関数を使用せずに画像をグレースケールに変換したいです。
42 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
画像とサイズを読み込んでからfor文で各画素にグレースケール変換をしたいです
0 commentaires
Réponse acceptée
Atsushi Ueno
le 29 Juil 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 commentaires
Plus de réponses (2)
Hernia Baby
le 29 Juil 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 commentaire
Hernia Baby
le 30 Juil 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
le 29 Juil 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 commentaires
Voir également
Catégories
En savoir plus sur イメージ算術 dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!