2011-09-13 62 views
5

我知道这只是一个警告,它不会影响代码..但我的问题是我需要显示图像的实际大小没有任何缩放出..在imshow函数中是否可能有这样做的任何参数?图像太大,不适合在屏幕上(MATLAB)

谢谢大家应该工作

+1

你有没有考虑过使用[IMTOOL](http://www.mathworks.com/help/toolbox/images/ref/imtool.html)? – Amro

+0

我试过..它的工作原理..但我希望'imshow'做到这一点,因为使用'print'保存问题..'imtool'不会让我保存图 –

+0

类似的问题:[MATLAB:显示图像在其原始大小](http://stackoverflow.com/questions/1427602/matlab-showing-an-image-in-its-original-size) – Amro

回答

3

一种解决方案是显示图像,然后更改轴限度,因此没有为每个图像像素一个屏幕像素:

%# read an image and make it large 
img = imread('autumn.tif'); 
img = repmat(img,[10,10]); 

%# turn off the warning temporarily, we're going to fix the problem below 
%# Note that in R2011b, the warning ID is different! 
warningState = warning('off','Images:initSize:adjustingMag'); 
figure 
imshow(img) 
warning(warningState); 


%# get axes limits in pixels 
set(gca,'units','pixels') 
pos = get(gca,'position') 

%# display the top left part of the image at magnification 100% 
xlim([0.5 pos(3)-0.5]),ylim([0.5 pos(4)-0.5]) 

现在您可以选择手(平移工具)并根据需要移动图像。

+0

@Jonas海德堡:修复它。 – Jonas

+1

很酷:-)。你可以添加's = warning('off','Images:initSize:adjustingMag'); figure,imshow(img); 警告;'以避免警告信息... –

+0

(删除旧评论不再适用...) –

3

@Jonas给出的解决方案,我已经提出了,非常好。让我提出一些小的改进,使得它处理时,这个数字被调整的情况:

%# read an image and make it large 
img = imread('autumn.tif'); 
img = repmat(img, [10 10]); 

%# new figure 
hFig = figure; 

%# try show image at full size (suppress possible warning) 
s = warning('off', 'Images:initSize:adjustingMag'); 
imshow(img, 'InitialMagnification',100, 'Border','tight') 
warning(s); 

%# handle figure resize events 
hAx = gca; 
set(hFig, 'ResizeFcn',{@onResize,hAx}) 

%# call it at least once 
feval(@onResize,hFig,[],hAx); 

%# enable panning tool 
pan on 

以下是调整大小的回调函数:

function onResize(o,e,hAx) 
    %# get axes limits in pixels 
    oldUnits = get(hAx, 'Units'); %# backup normalized units 
    set(hAx, 'Units','pixels') 
    pos = get(hAx, 'Position'); 
    set(hAx, 'Units',oldUnits)  %# restore units (so it auto-resize) 

    %# display the top left part of the image at magnification 100% 
    xlim(hAx, [0 pos(3)]+0.5) 
    ylim(hAx, [0 pos(4)]+0.5) 
end 

screenshot

你也许可以改善这种更进一步,因此当您调整图形大小时,并不总是回到左上角,而是保持当前位置。

+0

不错的补充! – Jonas

+0

谢谢.. :) ..但它不起作用..我认为它没有工作,因为图像的巨大尺寸..它是'1914年由2294'' –

+0

@OmarOsama:究竟是什么出错了?它对我来说工作得很好。顺便说一下,上例中的平铺图像大小是2060x3450 .. – Amro

0

注意:要居中图像(而不是显示它的左上方),用

xlim([(w_image - w_window)/2, (w_image + w_window)/2]); 
    ylim([(h_image - h_window)/2, (h_image + h_window)/2]); 

其中w_image和h_image是图像的尺寸,和w_window和h_window是上述答案的POS(3)和pos(4)。