
関数を使用せずに画像をグレースケールに変換したいです。
53 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
ma
am 29 Jul. 2022
Kommentiert: Hernia Baby
am 30 Jul. 2022
画像とサイズを読み込んでからfor文で各画素にグレースケール変換をしたいです
0 Kommentare
Akzeptierte Antwort
Atsushi Ueno
am 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 Kommentare
Weitere Antworten (2)
Hernia Baby
am 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 Kommentar
Hernia Baby
am 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
am 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 Kommentare
Siehe auch
Kategorien
Mehr zu イメージ タイプの変換 finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!