title: Unwanted branches in thinning process
body: <p>I was trying to code for thinning an image and to an extent I got an output. But still the final output does have some small unwanted lines emerging from different areas.  My next step was to find intersection points. Because of these small lines, I get points which are actually not intersection points. How can I improve my code in order to avoid those lines.</p>
  
  <pre><code>I = imread('img.jpg');
  I = rgb2gray(I);
  I = uint8(255*mat2gray(I));
  I=imresize(I,[128 128]);
  
  I1=edge(I,'canny',0.6);
  I2=edge(I,'canny',0.1);
  I = imsubtract(I2,I1);
  
  
  si = imdilate(I,strel('line',3,0));
  se = imerode(I,strel('line',3,0));
  I = imsubtract(si,se);
  
  si = imdilate(I,strel('disk',1));
  se = imerode(I,strel('disk',3));
  I = imsubtract(si,se);
  
  I = imfill(I,'holes');
  
  
  [L num]=bwlabel(I); %%number of connected objects found in binary%%%
  A=[];
  for i=1:num
      a=find(L==i);
      A(i)=size(a,1);
  end
  [b indxA]=max(A);
  
  L2(128,128)=0;
  
  for i=1:num
     if A(i)&gt;=0.9*b
        L2(find(L==i))=1;
     end
  end
  
  I = imerode(L2,strel('disk',1));
  I = bwmorph(I,'skel',Inf);
  
  [i,j] = ind2sub(size(I),find(bwmorph(bwmorph(I,'thin',Inf),'branchpoint') == 1));
  figure,imshow(I); hold on; plot(j,i,'rx');
  </code></pre>
  
  <p>Input:</p>
  
  <p><img src="https://i.stack.imgur.com/7jRUe.jpg" alt="enter image description here"></p>
  
  <p>Output:</p>
  
  <p><img src="https://i.stack.imgur.com/8lLMg.jpg" alt="enter image description here"></p>
  
  <p>Required img:</p>
  
  <p><img src="https://i.stack.imgur.com/7GFoQ.jpg" alt="enter image description here"></p>