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');
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!