My input Image is
output image is
Expected output is something like this
it is seen that some of the ellipse like structures are merged with rectangle.Also I'm unable to separate each labels to get the ellipses Algorithm used is watershed
clear; close all;
I = imread('Sub.png');
I = rgb2gray(I);
figure; imshow(I)
I2 = imtophat(I, strel('square', 45));
figure; imshow(I2)
% Alpha=.047;
% h = fspecial('motion', 10, 5);
% w=gausswin(I2,Alpha) % you'll have to play with N and alpha
% I2 = imfilter(I2,h,'same','symmetric'); % something like these options
level = .047;
BW = im2bw(I2,level);
D = -bwdist(~BW,'chessboard');
D(~BW) = -Inf;
L = watershed(D);
imshow(label2rgb(L,'jet','w'))
ultimate opening code :
ImageSource=imread('cameraman.tif');
ImTmp=ImageSource
ImResidue = zeros(size(ImageSource));
ImIndicator= zeros(size(ImageSource));
ImValues= zeros(size(ImageSource));
For size= 1 : N
se = strel('square',N);
ImOp = imopen(ImageSource,se);
ImDiff=imabsdiff(ImOp,ImTmp)
if ImResidue < ImDiff then
ImResidue = ImDiff
ImIndicator = size
ImValues = ImOp
end
ImTmp=ImOp
end
You have to use a watershed with markers if you want something accurate, but it's going to be more tricky. By default the basic watershed over segment because it uses each local minima as a marker.
Therefore, you have to preprocess a little bit your image in order to increase the separation between the objects you want to segment, and then use markers in order to guide your watershed.
[EDIT according to you EDIT] If you want just the little structures between the vertebras, then I would recommend to perform a small erosion in order to increase the gap between them, followed by an ultimate opening. The structures you want will disappear for small radii, when the vertebras will need bigger ones.
Don't forget to use the markers on the gradient image.
[EDIT 2, preliminary results] I was curious about your problem, so I gave it a try. Instead of going to the small regions between the vertebras (the one you want to segment), I tried to first segment the vertebras (what you want being between them).
Here is what I did:
The patterns you want to segment are between the vertebras, so I guess this result narrows down a lot the region of interest.
Does it work for you?
I cannot share the code, but I guess that you should find everything in MatLab.
You can improve this result by detecting the rectangular shapes.