【问题标题】:image is too big to fit in the screen (MATLAB)图像太大而无法放入屏幕(MATLAB)
【发布时间】:2011-11-16 09:52:35
【问题描述】:

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

谢谢大家

【问题讨论】:

标签: image matlab plot zooming


【解决方案1】:

注意:要使图像居中(而不是显示其左上角),请使用

    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)。

【讨论】:

    【解决方案2】:

    一种可行的解决方案是显示图像,然后更改轴限制,以便每个图像像素都有一个屏幕像素:

    %# 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])
    

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

    【讨论】:

    • 非常酷:-)。您可以添加s=warning('off','Images:initSize:adjustingMag'); figure,imshow(img); warning(s); 以避免警告消息...
    • (正在删除不再适用的旧 cmets...)
    • @Jonas Heidelberg:好点子!不幸的是,我只安装了预发布版本,其中还有另一组不同的警告 ID,所以我还不能让我的答案 R2011b 兼容。
    • @Jonas:查看本页末尾的 PDF 文件:mathworks.com/support/solutions/en/data/1-ERAFNC/…
    • @Amro:太好了!事实上,在预发布版发布后,我确实要求提供这样的文件;我很高兴他们成功了。
    【解决方案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
    

    以下是resize回调函数:

    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
    

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

    【讨论】:

    • 谢谢 .. :) .. 但它不起作用 .. 我认为它不起作用,因为图像太大了 .. 它是 1914-by- 2294
    • @OmarOsama:到底出了什么问题?它对我来说很好。顺便说一句,上面示例中的平铺图像大小为 2060x3450..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-08
    • 1970-01-01
    • 2011-12-10
    • 1970-01-01
    • 1970-01-01
    • 2011-09-09
    相关资源
    最近更新 更多