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

1 次查看(过去 30 天)
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');

采纳的回答

Image Analyst
Image Analyst 2020-7-20
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by