【问题标题】:Displaying images is Matlab显示图像是Matlab
【发布时间】:2017-12-23 07:56:27
【问题描述】:

我想写一个Matlab函数,可以显示一个图像,图像的多个图像(即单元格数组、向量、矩阵),这样我就不用担心写'plots'、'subplots'和每次我用新的输入运行我的程序时,其他复杂的 Matlab 机制。这也是我在项目中的要求之一。

以下源码有几个问题:

  1. 它不能只显示一张图片
  2. 有时它不会保留图像的原始纵横比
  3. 将窗口调整为更小的尺寸会显着减小显示图像的尺寸

如何解决这些问题?


源代码

function draw_images(image_list)    
    d = size(image_list);
    l = length(d);

    figure;
    hold all
    colormap(gray(256));  

    % vector or cell-array
    if(l==2)
        N = length(image_list);
        [m, n] = factor_out(N);

        % images may be of differenet dimensions
        if(iscell(image_list))    
            for k=1:N
                h = subplot(m,n,k);
                image(image_list{k},'Parent',h);
                set(gca,'xtick',[],'ytick',[])
            end
        % must be of same dimension
        elseif(isvector(image_list))
            for k=1:N
                h = subplot(m,n,k);
                image(image_list(k),'Parent',h);
                set(gca,'xtick',[],'ytick',[])
            end
        end
    % 3D matrix of images (!!!)
    elseif(l==3)
        N = d(3) ;
        [m, n] = factor_out(N);
        for k=1:N
            I = image_list(:,:,k);
            subplot(m,n,k);
            imshow(I);
            set(gca,'xtick',[],'ytick',[])
        end  
    end     
    hold off

function [m, n] = factor_out(input_number)
    sqrtt = ceil(sqrt(input_number));    
    m = sqrtt;
    n = sqrtt;

【问题讨论】:

    标签: image matlab


    【解决方案1】:

    我认为python中没有类似pyplot.tight-layout()的内置解决方案。但是,存在由几位作者编写的几种解决方案。我更喜欢名为subtightplot 的函数

    Stackoverflow 上也有关于这个问题的讨论,称为 How to reduce the borders around subplots in matlab?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-25
      • 2016-08-26
      • 2014-10-27
      • 1970-01-01
      • 2016-07-09
      相关资源
      最近更新 更多