Matlab - Watershed to extract lines - lost information

image-processing, matlab, watershed

Solution

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('https://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:

Problem

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: As you can see lot of information is lost. Can anybody help me out? Thanks.

Original source