How many ways to define shape and size of structuring element depend on images in Watershed segmentation?

6 views (last 30 days)
% Here a sample matlab code for MC-Watershed Segmentation
% Please ! help me, I would like to obtain structuring element arbitrarily, depending on images
rgb = imread(name);
I = rgb2gray(rgb);
hy = fspecial('sobel');
hx = hy';
Iy = imfilter(double(I), hy, 'replicate');
Ix = imfilter(double(I), hx, 'replicate');
gradmag = sqrt(Ix.^2 + Iy.^2);
%this is fixed structuring element in tool ,So I would like to change that
se = strel('disk',20);
Io = imopen(I, se);
Ie = imerode(I, se);
Iobr = imreconstruct(Ie, I);
Ioc = imclose(Io, se); %closing
Iobrd = imdilate(Iobr, se);
Iobrcbr = imreconstruct(imcomplement(Iobrd), imcomplement(Iobr));
Iobrcbr = imcomplement(Iobrcbr);
fgm = imregionalmax(Iobrcbr);
I2 = I;
I2(fgm) = 255;
se2 = strel(ones(5,5));
fgm2 = imclose(fgm, se2);
fgm3 = imerode(fgm2, se2);
fgm4 = bwareaopen(fgm3,10); %shink them a bit e.g 20
I3 = I;
I3(fgm4) = 255;
.
.
...
.....
%Please ,suggest me

Accepted Answer

Walter Roberson
Walter Roberson on 3 Jan 2014
strel() can take 'arbitrary' matrices for the neighborhood. You are working on 2D matrices, so you want your strel matrix to be 2D. All arbitrary rectangular matrix sizes between 1 x 1 to size(I,1) to size(I,2) can be used. For each matrix size, each position can be either 0 or 1, so each matrix can be filled in 2^numel(matrix) ways.
2^(1 * 1) + 2^(1 * 2) + 2^(2 * 1) + 2^(1 * 3) + 2^(3 * 1) + 2^(1 * 4) + 2^(4 * 1) + 2^(2 * 2) + ....
So basically unless your original image is no more than roughly 6 x 6, automatically generating and applying all the possible structuring elements is going to take the computer rather some time. In view of the alternatives, are you sure this is wise?

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!