Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab - Watershed to extract lines - lost information

enter image description here

I have a vein image as follow. I use watershed algorithm to extract the skeleton of the vein.

My code: (K is the original image).

level = graythresh(K);
BW = im2bw(K,level);
D = bwdist(~BW);
DL = watershed(D);
bgm = DL == 0;
imshow(bgm);

The result is:

enter image description here

As you can see lot of information is lost. Can anybody help me out? Thanks.

like image 371
W00f Avatar asked Apr 15 '12 18:04

W00f


2 Answers

It looks like the lighting is somewhat uneven. This can be corrected using certain morphological operations. The basic idea is to compute an image that represents just the uneven lighting and subtract it, or to divide by it (which also enhances contrast). Because we want to find just the lighting, it is important to use a large enough structuring element, so that the operation examines more global properties rather than local ones.

%# Load image and convert to [0,1].
A = im2double(imread('http://i.stack.imgur.com/TQp1i.png'));
%# Any large (relative to objects) structuring element will do.
%# Try sizes up to about half of the image size.
se = strel('square',32);
%# Removes uneven lighting and enhances contrast.
B = imdivide(A,imclose(A,se));
%# Otsu's method works well now.
C = B > graythresh(B);
D = bwdist(~C);
DL = watershed(D);
imshow(DL==0);

Here are C (left), plus DL==0 (center) and its overlay on the original image:

Divided by closingOtsu's methodSegmentation overlay

like image 184
reve_etrange Avatar answered Sep 27 '22 20:09

reve_etrange


You are losing information because when you apply im2bw, you are basically converting your uint8 image, where the pixel brightness takes a value from intmin('uint8')==0 to intmax('uint8')==255, into a binary image (where only logical values are used). This is what entails a loss of information that you observed. If you display the image BW you will see that all the elements of K that had a value greater than the threshold level turn into ones, while those ones below the threshold turn into zeros.

like image 27
Drodbar Avatar answered Sep 27 '22 19:09

Drodbar