1

要显示我在下面的代码中使用的输出图像

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

所有图像都清晰的地方。

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

 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)

画质怎么了?任何适当的答案都是可观的。

4

1 回答 1

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 图像以避免与颜色图相关的问题。

于 2013-05-05T16:28:50.287 回答