The Dilation process is performed by laying the structuring element B on the image A and sliding it across the image in a manner similar to convolution.
I understand the main concept behind the mathematical morphology dilation of the grayscale images, but i still have one question :
Can the values of the structure element be not chosen by the user ? In other words, can we perform a dilation process on the image by just choosing the size and shape of the structure element without specifying its elements?
For more precision, i will explain well my question by an example : Assume a greyscale image I
of size 160 x 160
to be processed (dilated in this case) by a neighborhood of size 8 x 8. I didn't specify the elements of this neighborhood, so their elements are from the image itself. For example i wrote the matlab code below:
Max_image = max_filter(I, [0 0 7 7]);
Where the function max_filter is:
[n m] = size(I); % n=160 and m=160
B = I;
for i = 1:m-7,
B(:,i) = max(I(:,i:i+7),[],2);
end
for i=m-7+1:m
B(:,i) = max(I(:,i:min(end,i+7),[],2);
end
for i = 1:n-7,
I(i,:) = max(B(max(1,i):min(end,i+7),:),[],1);
end
for i = n-7+1:n,
I(i,:) = max(B(i:min(end,i+7),:),[],1);
end
Does that is still considered as a morphological dilation operation ? Recall that i used a structure element of size 8 x 8.
Your program is equivalent to a full image dilation with the structure element of
ones(8)
(btw, you didn't use the input argument [0 0 7 7], and you don't need that indeed):Max_image = max_filter(I, [0 0 7 7])
will give you:When you are using:
It will give you exactly the same answer.
That's why I told you yesterday that it is often to use a binary image mask as the structure element. You don't need to choose the value inside the mask, but you need to choose the size (8*8) and shape. What is a shape? In a binary image, the elements that are filled with 1 determines the shape. Here in your code you selected the largest value within the 8*8 region, that is equivalent to the image dilation with a whole bright 8*8 square shaped mask.