HSV変換した画像から特定の色のピクセル数を数えたい
32 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
画像中から特定の色を抽出して,そのピクセル数を数えるプログラムをつくりたいのですがうまくいきません.やりたいこととしては,添付画像をHSV変換し,赤い部分のピクセル数を数えるプログラムを作りたいです.RGB画像よりもHSV画像の方が特定の色を抽出しやすいと考え,HSV変換して行いたいと考えています.分かりにくい文章ですみませんが,どなたか教えていただきたいです。
0 commentaires
Réponses (1)
Atsushi Ueno
le 23 Juil 2022
H (色相) が 0.00~0.02 と 0.98~1.00 のピクセルを「赤」と判定しました。
HSV = rgb2hsv(imread('image.png'));
RED = (HSV(:,:,1) <= 0.02) ...
| (HSV(:,:,1) >= 0.98);
sum(RED,'all') % 赤い部分のピクセル数
numel(HSV(:,:,1)) % 画像のピクセル数
imshow(~RED) % 黒い部分が赤色、白い部分が赤色以外。若干判定ムラが生じている
Voir également
Catégories
En savoir plus sur Red 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!