# バナナのエッジ処理（輪郭摘出）がうまくできない。

3 views (last 30 days)
METACORN on 16 Feb 2023
Commented: METACORN on 20 Feb 2023

##### 2 CommentsShow 1 older commentHide 1 older comment
METACORN on 19 Feb 2023

Tohru Kikawada on 20 Feb 2023

% RGBからHSV色空間に変換
I = rgb2hsv(RGB);
はじめにバナナの影の部分だけを抽出するマスクを生成
% 色相
channel1Min = 0.040;
channel1Max = 0.098;
% 彩度
channel2Min = 0.086;
channel2Max = 0.443;
% 明度
channel3Min = 0.671;
channel3Max = 0.871;
% 上記範囲のを満たすマスクを作成
sliderBW = ( (I(:,:,1) >= channel1Min) | (I(:,:,1) <= channel1Max) ) & ...
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ...
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW1 = sliderBW;

% 色相
channel1Min = 0.925;
channel1Max = 0.173;
% 彩度
channel2Min = 0.218;
channel2Max = 1.000;
% 明度
channel3Min = 0.000;
channel3Max = 1.000;
% 上記範囲のを満たすマスクを作成
sliderBW = ( (I(:,:,1) >= channel1Min) | (I(:,:,1) <= channel1Max) ) & ...
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ...
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW2 = sliderBW;

% 2つのマスクのANDをとる
BW = ~BW1 & BW2;
モルフォロジー処理による後処理
% 1番大きい面積の部分だけを残す
BW = bwareafilt(BW,1);
% クローズ処理で輪郭の凸凹をならす
BW = imclose(BW,strel("disk",10));
% 黒いところを穴埋め
BW = imfill(BW,"holes");

figure
imshow(im2single(RGB) .* single(BW))
METACORN on 20 Feb 2023

きちんとほかの画像でも輪郭の抽出が行えました。

### Categories

Find more on MATLAB 入門 in Help Center and File Exchange

R2017b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!