Morphological dilation on Greyscale image using a neighborhood of size n x n in MATLAB

2.2k views Asked by At

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.

1

There are 1 answers

4
lennon310 On BEST ANSWER

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):

I = [92    99     1     8    15    67    74    51    58    40
     98    80     7    14    16    73    55    57    64    41
      4    81    88    20    22    54    56    63    70    47
     85    87    19    21     3    60    62    69    71    28
     86    93    25     2     9    61    68    75    52    34
     17    24    76    83    90    42    49    26    33    65
     23     5    82    89    91    48    30    32    39    66
     79     6    13    95    97    29    31    38    45    72
     10    12    94    96    78    35    37    44    46    53
     11    18   100    77    84    36    43    50    27    59];

Max_image = max_filter(I, [0 0 7 7]) will give you:

    99    99    97    97    97    75    75    75    72    72
    98    97    97    97    97    75    75    75    72    72
   100   100   100    97    97    75    75    75    72    72
   100   100   100    97    97    75    75    75    72    72
   100   100   100    97    97    75    75    75    72    72
   100   100   100    97    97    72    72    72    72    72
   100   100   100    97    97    72    72    72    72    72
   100   100   100    97    97    72    72    72    72    72
   100   100   100    96    84    59    59    59    59    59
   100   100   100    84    84    59    59    59    59    59

When you are using:

J1=imdilate(I,ones(8),'full');
J1(8:end,8:end)

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.