Can anyone tell me what does this code do and how does it work?

1 view (last 30 days)
function segment = skin_seg2(I1)
% Convert image to double precision
I=double(I1);
[hue,~,~]=rgb2hsv(I);
% Ycbcr = rgb2ycbcr(I);
% % cb=Ycbcr(:,:,2)+128;
% % cr=Ycbcr(:,:,3)+128;
cb = 0.148* I(:,:,1) - 0.291* I(:,:,2) + 0.439 * I(:,:,3) + 128;
cr = 0.439 * I(:,:,1) - 0.368 * I(:,:,2) -0.071 * I(:,:,3) + 128;
[~ , ~]=size(I(:,:,1));
segment = 140<=cr & cr<=165 & 140<=cb & cb<=195 & 0.01<=hue & hue<=0.1;
segment=imfill(segment,'holes');
segment=bwmorph(segment,'dilate');
segment=bwmorph(segment,'majority');

Accepted Answer

Image Analyst
Image Analyst on 20 Jul 2020
It converts the image to ycbcr and hsv color spaces and then thresholds to find certain colors. The thresholds on the cb and cr will basically select purple pixels, but then the threshold on hue will select very red pixels. ANDing them might not select any pixels at all. At least it doesn't for the 'peppers.png' demo image. It really depends on what image those thresholds were designed for, and you forgot to attach one of those images.
The fill will basically remove any interior holes for the region, which may be noise. The dilate grows the region(s) larger - perhaps it wanted to expand beyond some edge or boundary. The Majority is basically a median filter and it removes interior or exterior noise and smooths out boundaries.
How (well) does it work? Who knows? Depends on the image, which you forgot to attach. Maybe it works great for some image(s) but maybe it works lousy for other images. Just depends on what you want to find in the image.

More Answers (0)

Categories

Find more on Modify Image Colors 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!

Translated by