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);ます。2 番目のケースでは、imshow関数を使用し、(コード内で) カラーマップを提供しないためimshow(x);、実際の色の代わりにカラー インデックスを表示します。

この 2 つの関数は、インデックス付きイメージのカラーマップを異なる方法で処理します。これについては、マニュアルを参照してくださいsubimageimshowこの例を試して、すべてを 1 か所で確認してください

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 に答える