プロが教えるわが家の防犯対策術!

現在Matlabを勉強中の者です.
160*120ピクセルの画像の色空間を
RGBからYUV(YCbCr)へ変換するプログラムを考えているのですが,
以下のソースコードで大まかな点はあっているでしょうか?
実際にYUVへ変換後,画像を表示したところ,
元画像とは色調が変わってしまい頭を抱えています.
画像を表示する際のカラーマップに問題があるのでしょうか.
ご教授お願い致します.

% 画像ファイルの読込
pictureRgb = imread('./data/gazou0.bmp');
pictureYcbcr = imread('./data/gazou0.bmp');

% YCbCr空間(フルレンジ)への変換
pictureYcbcr(:,:,1) = uint8(0.257 * double(pictureRgb(:,:,1)) + 0.504 * double(pictureRgb(:,:,2))...
+ 0.098 * double(pictureRgb(:,:,3))+16.0);


pictureYcbcr(:,:,2) = uint8(-0.148 * double(pictureRgb(:,:,1)) - 0.291 * double(pictureRgb(:,:,2))...
+ 0.439 * double(pictureRgb(:,:,3))+128.0);


pictureYcbcr(:,:,3) = uint8(0.439 * double(pictureRgb(:,:,1)) - 0.368 * double(pictureRgb(:,:,2))...
+ 0.071 * double(pictureRgb(:,:,3))+128.0);


%R成分の表示
subplot(3,3,1);
image(pictureRgb(:,:,1));
axis image; axis off;
title('R 成分');

%G成分の表示
subplot(3,3,2);
image(pictureRgb(:,:,2));
axis image; axis off;
title('G 成分');

%B成分の表示
subplot(3,3,3);
image(pictureRgb(:,:,3));
axis image; axis off;
title('B 成分');

%---------------------------

%Y成分の表示
subplot(3,3,4);
image(pictureYcbcr(:,:,1));
axis image; axis off;
title('Y 成分');

%Cb成分の表示
subplot(3,3,5);
image(pictureYcbcr(:,:,2));
axis image; axis off;
title('Cb成分');

%Cr成分の表示
subplot(3,3,6);
image(pictureYcbcr(:,:,3));
axis image; axis off;
title('Cr成分');

%---------------------------

%原画像の表示
subplot(3,3,7);
image(pictureRgb);
axis image; axis off;
title('元画像');

%YUV画像の表示
subplot(3,3,8);
image(pictureYcbcr);
axis image; axis off;
title('YUV画像');

※添付画像が削除されました。

A 回答 (1件)

Matlabはよく知らないのでそれについては分かりませんが


添付画像見る限り原画のRGB分離自体もまともに出来てないのでは?と思いますけど
(普通グレー(白黒濃淡)画像にならないとおかしいと思うんですがなぜ青とか茶色???)
    • good
    • 0
この回答へのお礼

回答ありがとうございます.
Matlabの仕様で,濃淡を「低い値程青く,高い値程赤に近い」
というモードで表示されていたので
colormap(gray);
というコマンドを追加すると白黒濃淡の画像で表示できました.
画像を張り直そうとしたのですが,画像の投稿は一度切りのようですね.
困りました…苦笑

お礼日時:2010/01/12 22:23

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!