関数を使用せずに画像をグレースケールに変換したいです。
Show older comments
画像とサイズを読み込んでからfor文で各画素にグレースケール変換をしたいです
Accepted Answer
More Answers (2)
3番目がR,G,Bに対応しているので、for文で抜き出します
I = imread('ngc6543a.jpg');
for ii = 1:3
A{ii} = I(:,:,ii);
end
montage([A{1},A{2},A{3}])
1 Comment
ちなみにRGBのみを分離する関数もあります
imsplit関数です
I = imread('ngc6543a.jpg');
[R,G,B] = imsplit(I);
ここから指定の色以外を黒で設定して表示してみましょう
allBlack = zeros(size(I,1,2),class(I));
justR = cat(3,R,allBlack,allBlack);
justG = cat(3,allBlack,G,allBlack);
justB = cat(3,allBlack,allBlack,B);
figure
montage({justR,justG,justB},'Size',[1 3], ...
"BackgroundColor",'w',"BorderSize",10);
title('Color Representation of the Red, Green, and Blue Color Channels');
> 関数を使用せずに画像をグレースケールに変換したいです
> 画像とサイズを読み込んでからfor文で各画素にグレースケール変換をしたいです
我慢出来ない!行列操作や型変換は関数であっても関数の内に入らない!
I = imread('onion.png');
[row,col,wdh] = size(I);
G1 = reshape(double(I(:)), [], wdh) * [0.2989; 0.5870; 0.1140];
G2 = uint8(reshape(G1, [row,col]));
imshow(G2);
Categories
Find more on イメージ タイプの変換 in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


