title: How do I proceed to retain just the veins as black using MATLAB?
body: <p>I have this Ir image that has captured the veins under the skin. I want to process this image so as to retain just the veins as black colour and get everything else as white. Then I want to generate the coordinate pixels as these black pixels which will be the veins. </p>
  
  <p>This is what I have done till now : </p>
  
  <pre><code>a=imread('11.jpg');
  figure(1),imshow(a);
  title('original image');
  cform = makecform('srgb2lab');
  for ii = 1:3
      a(:,:,ii) = medfilt2(a(:,:,ii),[5 5]);
  end
  lab = applycform(a,cform); 
  figure(2),imshow(lab);
  title('ímage in color space after filtering');
  b=lab(:,:,1);
  c=im2bw(b,0.2);
  figure(3),imshow(c);
  title('b&amp;white boundry of fist');
  neg=1-c;
  figure(4),imshow(neg);
  color=a;
  r=color(:,:,1);
  r(~c)= 0;
  g = color(:,:,2);
  g(~c)= 0;
  b = color(:,:,3);
  b(~c)= 0;
  % Concatenate in the "3rd dimension" to re-constitute an RGB image.
  color = cat(3,r,g,b);
  figure(5),
  imshow(color);
  title('reconstructed fist with black bg');
  gray=rgb2gray(color);
  figure(6);
  imshow(gray);
  title('grayscale of fist');
  
  i1=imresize(gray,[256 256],'bilinear');
  figure(7);
  imshow(i1);
  title('Resized Image of grayscale');
  
  figure(8),imhist(i1);
  title('histogram of resized grayscale');
  i2=histeq(i1,256);
  figure(9),imshow(i2);
  title('histogram equalisatio');
  figure(10),imhist(i2);
  title('équalised histogram');
  e=medfilt2(i2,[5 5]);
  figure(7),imshow(e);
  f=medfilt2(e,[5 5]);
  figure(8),imshow(f);
  g=medfilt2(f,[5 5]);
  figure(9),imshow(g);
  s=g;
  figure(10),imshow(s);
  l=imresize(s,[200 200]);
  figure(11);
  imshow(l);
  
  [h,u]=size(l);
  smth=double(l);
  wl=1.5;
  we=3;
  wt=15;
  eline=smth;;
  [grady,gradx]=gradient(smth);
  eedge=-1*sqrt((gradx.*gradx+grady.*grady));
  figure(12);
  imshow(uint8(-eedge));
  m1=[-1 1];
  m2=[-1;1];
  m3=[1 -2 1];
  m4=[1;-2;1];
  m5=[1 -1;-1 1];
  cx=conv2(smth,m1,'same');
  cy=conv2(smth,m2,'same');
  cxx=conv2(smth,m3,'same');
  cyy=conv2(smth,m4,'same');
  cxy=conv2(smth,m5,'same');
  for i=1:h
      for j=1:u
          eterm(i,j)=(cyy(i,j)*cx(i,j)*cx(i,j)-2*cxy(i,j)*cx(i,j)*cy(i,j)+cxx(i,j)*cy(i,j)*cy(i,j))/((1+cx(i,j)*cx(i,j)+cy(i,j)*cy(i,j))^1.5);
      end
  end
  figure(13);
  imshow(uint8(-eterm));
  eext=(wl*eline+we*eedge+wt*eterm);
  figure(14);
  imshow(uint8(eext));
  eext=(wl*eline+we*eedge);
  figure(15);
  imshow(uint8(eext));
  whos eext;
  </code></pre>
  
  <p>and this is the image:</p>
  
  <p><img src="https://i.stack.imgur.com/UtcwZ.jpg" alt="enter image description here"></p>
  
  <p>So how do I proceed after this so that I retain the veins as black and eveything else as white?</p>
  
  <p><img src="https://i.stack.imgur.com/wcua7.jpg" alt="after median filtering"></p>
  
  <p>So this is the image after median filtering, as you can see the veins are quite dark. So how do I proceed from here so that the veins are retained as black and everything else as white?</p>