2011-09-13 64 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)。