関数を使用せずに画像をグレースケールに変換したいです。
41 views (last 30 days)
Show older comments
画像とサイズを読み込んでからfor文で各画素にグレースケール変換をしたいです
0 Comments
Accepted Answer
Atsushi Ueno
on 29 Jul 2022
> rgb2gray は、R 成分、G 成分、B 成分の重み付き和を計算することによって、RGB 値をグレースケール値に変換します。
>
I = imread('onion.png');
[row,col,wdh] = size(I);
for r = 1:row
for c = 1:col
G(r,c) = I(r,c,1) * 0.2989 + I(r,c,2) * 0.5870 + I(r,c,3) * 0.1140;
end
end
imshow(G);
0 Comments
More Answers (2)
Hernia Baby
on 29 Jul 2022
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
Hernia Baby
on 30 Jul 2022
ちなみに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');
Atsushi Ueno
on 29 Jul 2022
> 関数を使用せずに画像をグレースケールに変換したいです
> 画像とサイズを読み込んでから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);
0 Comments
See Also
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!