在 MATLAB 中在一个 window 上显示多个图像

Display multiple images on one window in MATLAB

这些是我的原始图像,我需要在一张图中显示,

以下是我的源码,

function draw_multiple_images(image_list)    
    N = length(image_list);
    [m, n] = factor_out(N);

    % create the subplots
    figure;

    if(iscell(image_list))    
        for k=1:N
            h = subplot(m,n,k);
            image(image_list{k},'Parent',h);
            set(gca,'xtick',[],'ytick',[])
        end    
    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
end

输出

为什么我看到它们是蓝黄色的?

我需要将它们显示为黑白。

我在 figure 命令后使用 colormap(gray(256)); 解决了这个问题。

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

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

    if(l==2)
        N = length(image_list);
        [m, n] = factor_out(N);

        if(iscell(image_list))    
            for k=1:N
                h = subplot(m,n,k);
                image(image_list{k},'Parent',h);
                set(gca,'xtick',[],'ytick',[])
            end    
        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
    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
end