How do I prevent images displayed in a gui with imshow from being sized to fit the axes?

6 ビュー (過去 30 日間)
Katie
Katie 2015 年 11 月 19 日
コメント済み: Katie 2015 年 11 月 20 日
I built a gui that displays a folder of images one by one and lets the user select an object class to associate with each image. The images are all different dimensions, and large images show up fine, but small images are blown up to fit the axes, and you can't recognize what's in the image. How do I make the axes resize themselves to fit each image?
I'm using this code to display the image.
g = imread(current_im)
axes(handles.axes1);
cla;
imshow(g)

回答 (2 件)

Walter Roberson
Walter Roberson 2015 年 11 月 19 日
axis image; %sets data aspect ratio
oldunits = get(gca, 'Units');
set(gca, 'Units', 'pixels');
oldsize = get(gca, 'Position');
set(gca, 'Position', [oldsize(1), oldsize(2), size(g,1), size(g,2))
set(gca, 'Units', oldunits)

Chad Greene
Chad Greene 2015 年 11 月 19 日
Try this
A = repmat(imread('coins.png'),[6 6]);
imshow(A,'InitialMagnification',100)
set(gcf,'position',[10 10 size(A,2) size(A,1)])
setpixelposition(gca,[0 0 size(A,2) size(A,1)])
  2 件のコメント
Walter Roberson
Walter Roberson 2015 年 11 月 20 日
Hmmm... setpixelposition() says
Distances in pixels are independent of your system resolution on Windows® and Macintosh systems:
  • On Windows systems, a pixel is 1/96th of an inch.
  • On Macintosh systems, a pixel is 1/72nd of an inch.
On Linux® systems, the size of a pixel is determined by your system resolution.
Katie
Katie 2015 年 11 月 20 日
This worked on small images, but it screwed things up for large images. I ended up writing a function that adds zero padding to images if their dimensions are below a given value.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImages についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by