显示图像是Matlab

时间:2017-07-18 12:32:52

标签: image matlab

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

以下源代码有几个问题:

  1. 它只能显示一张图片
  2. 偶尔也不会保留图像的原始宽高比
  3. 将窗口大小调整为较小的尺寸会大大减小显示图像的大小
  4. 如何解决这些问题?

    源代码

    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;
    

1 个答案:

答案 0 :(得分:1)

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

的函数

在Stackoverflow上还有一个名为How to reduce the borders around subplots in matlab?

的讨论