title: Matlab : Remove skin part on segmentation
body: <p>How to remove skin parts on segmentation ?</p>
  
  <p>First, I made this first picture smaller, since the picture is somehow intimidating, I'll give the image at the end section.</p>
  
  <p><a href="https://i.stack.imgur.com/gklUNm.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gklUNm.jpg" alt="enter image description here"></a></p>
  
  <p>I'm using RGB &amp; ycbcr segmentation, but it seems the segmentation didn't work well.</p>
  
  <pre><code>clear all;
    close all;
    clc;
  
     img=imread('acne.jpg');
  
  
   %ycbcr segmentation
     img_ycbcr=img;  %image from the previous segmentation
     ycbcr=rgb2ycbcr(img_ycbcr);
     cb=ycbcr(:,:,2);
     cr=ycbcr(:,:,3);
  
  
      %Detect Skin
      %[r,c,v] = find(cb&gt;=77 &amp; cb&lt;=127 &amp; cr&gt;=133 &amp; cr&lt;=173);
       [r c v] = find(cb&lt;=77 | cb &gt;=127 | cr&lt;=133 | cr&gt;=173);
      numid = size(r,1);
  
      %Mark Skin Pixels
      for i=1:numid
          img_ycbcr(r(i),c(i),:) = 0;
         % bin(r(i),c(i)) = 1;
      end
  
      figure
      title('ycbcr segmentation');
     imshow(img_ycbcr);
  
   %==============================================================
    %rgb segmentation
  
  img_rgb=img_ycbcr;
  r=img_rgb(:,:,1);
  g=img_rgb(:,:,2);
  b=img_rgb(:,:,3);
  
  
  [row col v]= find(b&gt;0.79*g-67 &amp; b&lt;0.78*g+42 &amp; b&gt;0.836*g-14 &amp; b&lt;0.836*g+44 ); %non skin pixels
  numid=size(row,1);
  
  for i=1:numid
      img_rgb(row(i),col(i),:)=0;
  end
  
  
  figure
  imshow(img_rgb);
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/l8gHb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l8gHb.png" alt="enter image description here"></a></p>
  
  <p>Here my sample :</p>
  
  <p><a href="https://i.stack.imgur.com/N8y6Q.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/N8y6Q.jpg" alt="enter image description here"></a></p>