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

1 visualización (últimos 30 días)
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');

Respuesta aceptada

Image Analyst
Image Analyst el 20 de Jul. de 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.

Más respuestas (0)

Categorías

Más información sobre Image Processing Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by