图像太大,无法放入屏幕(MATLAB)

时间:2011-09-13 18:08:08

标签: image matlab plot zoom

我知道这只是一个警告,它不会影响代码..但我的问题是我需要以实际尺寸显示图像而不缩小..这可能在imshow函数是否有任何参数可以做到这一点?

谢谢大家

3 个答案:

答案 0 :(得分: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])

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

答案 1 :(得分: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

你可以进一步改进这一点,这样当你调整图形大小时,你并不总是回到左上角,而是保持当前位置。

答案 2 :(得分: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)。