GUI MATLAB中图形窗口和轴之间的差异

时间:2013-05-05 15:04:24

标签: matlab matlab-figure figure matlab-guide

显示我在代码

下面使用的输出图像
function displayResults(filename, header)
    figure('Position',[200 100 700 400], 'MenuBar', 'none', 'Name', header, 'Resize', 'off', 'NumberTitle', 'off');
    % Open 'filename' file... for reading...
    fid = fopen(filename);
    i = 1;                  % Subplot index on the figure...
    while 1
        imagename = fgetl(fid);
        if ~ischar(imagename), break, end       % Meaning: End of File...    
        [x, map] = imread(imagename);
        subplot(2,5,i);
        subimage(x, map);
        xlabel(imagename);
        i = i + 1;
    end
    fclose(fid);

这导致输出正确(http://s1273.photobucket.com/user/Chethan_tv/media/figure_zps326033c2.jpg.html

所有图像都清晰。

但是,我改变了上面的代码,在我的GUI中显示,输出端有5个轴,代码如下所示

 function displayResults(filename,hObject, eventdata, handles)
    % Open 'filename' file... for reading...
    fid = fopen(filename);
    for N=6:1:10
        imagename = fgetl(fid);
        if ~ischar(imagename), break, end       % Meaning: End of File...
        x=imread(imagename);
        ax = handles.(sprintf('axes%d', N));
        imshow(x, 'Parent', ax);
        xlabel(ax, imagename);  
    end
    fclose(fid);

但这导致了低质量的输出 (http://s1273.photobucket.com/user/Chethan_tv/media/fig_zpsa48de802.jpg.html?so RT = 3及O = 0)

图像质量发生了什么变化?任何合适的答案都是值得的。

1 个答案:

答案 0 :(得分:0)

从我看到你正在使用索引图像。

您的代码中实际存在不同的行为,因为在第一种情况下,您使用subimage函数显示图像并为其提供色彩映射(代码中为subimage(x, map);)。在第二种情况下,您使用imshow函数并且不向其提供色彩映射(代码中为imshow(x);),因此您显示颜色索引而不是实际颜色。

两个函数subimageimshow以不同方式处理索引图像中的色彩映射,请参阅手册。 试试这个例子也可以在一个地方看到所有的东西

fn          = 'peppers.png';

rgb         = imread(fn); % This is RGB image
NR          = 2;
NC          = 3;
NI          = NR * NC;
CMapStep    = 12;


figure('Position',[200 100 800 600], 'MenuBar', 'none' );
hAxes = zeros(NI,1);

% displaying original images using subimge
MsgStr = 'subimage(x, map)';
for k=1:NI
    % convert it to indexed image so each image has different number of colors in its colormap
    [x, map] = rgb2ind(rgb,k*CMapStep);
    hAxes(k)    = subplot(NR,NC,k);    % store axes handles for later
    subimage(x, map);
    title(hAxes(k), sprintf('%s: image #%d',MsgStr,k) );
    drawnow;
    pause(1);
end

% displaying original images WITHOUT colormap using imshow
MsgStr = 'imshow(x)';
for k=1:NI
    % convert it to indexed image so each image has different number of colors in its colormap
    [x, map] = rgb2ind(rgb,k*CMapStep);
    imshow(x, 'Parent',hAxes(k) );
    title(hAxes(k), sprintf('%s: image #%d',MsgStr,k) );
    drawnow;
    pause(1);
end

% displaying original images WITH colormap using imshow
MsgStr = 'imshow(x,cmap)';
for k=1:NI
    % convert it to indexed image so each image has different number of colors in its colormap
    [x, map]    = rgb2ind(rgb,k*CMapStep);
    imshow(x,map, 'Parent',hAxes(k) );
    title(hAxes(k), sprintf('%s: image #%d',MsgStr,k) );
    drawnow;
    pause(1);
end

作为您问题的解决方案,您应该坚持使用相同的方式在任何地方显示图像或将其转换为RGB图像以避免与色彩图相关的问题。