【问题标题】:difference between figure window and axes in GUI MATLABGUI MATLAB中图形窗口和轴之间的区别
【发布时间】:2013-05-05 15:04:23
【问题描述】:

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

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)

图像质量发生了什么变化?任何适当的答案都是可观的。

【问题讨论】:

    标签: matlab matlab-figure figure matlab-guide


    【解决方案1】:

    据我所知,您正在使用索引图像。

    这种不同的行为实际上存在于您的代码中,因为在第一种情况下,您使用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 图像以避免与颜色图相关的问题。

    【讨论】:

    • 对不起,一个小错误。我用过image(x, 'Parent', ax); 而不是imshow(x, 'Parent', ax);。 . .即使我得到的图像质量很差。
    • 你能提供imfinfo('YorImageFileName.Ext')的输出吗?
    • function imfinfo 不显示图像它只是返回一个结构,对不起,你能举例说明如何使用它吗?我可以在我的代码中哪里使用它?
    • 我对问题图像的FormatBitDepthColorType 字段感到好奇
    • 所有图片均为位图类型。对于我的 CBIR 代码,我需要位深度为 8 的位图图像。因此,我使用 Photoshop 软件创建了这些图像,而我的数据库中充满了这种类型的图像。在 photoshop 中:图像>模式>索引颜色和 8 位/通道,最后我将其保存为 .bmp 格式
    猜你喜欢
    • 2014-09-03
    • 1970-01-01
    • 2012-07-18
    • 2016-11-06
    • 2013-10-25
    • 1970-01-01
    • 2021-09-25
    • 2013-09-27
    • 1970-01-01
    相关资源
    最近更新 更多