## How do I perform 3-dimensional dilation on my image array using the Image Processing Toolbox?

### MathWorks Support Team (view profile)

on 27 Jun 2009
Latest activity Edited by Sara Salimi

### Sara Salimi (view profile)

on 10 Dec 2018
Accepted Answer by MathWorks Support Team

### MathWorks Support Team (view profile)

I have tried using the "ball" option with the STREL function to create a 3-dimensional structure element for dilating my image:
s = strel('ball',3,3);
However, when I attempt to dilate the image with this structure element, I do not see the results I expect.

### MathWorks Support Team (view profile)

on 27 Jun 2009

The following code:
strel('ball',3,3)
returns a 2-dimensional nonflat structuring element. Nonflat structuring elements are usually used for gray-scale dilation. Gray-scale dilation for the position (x,y) is defined as:
max{ f(x-x',y-y') + b(x',y') | (x',y') in b}
where "b" is the structuring element, and "(x',y')" are the relative locations in "b"s neighborhood. The values "b(x',y')" correspond to the strel object's "height". In this context, the term "ball" refers to the interpretation of a 2-dimensional grayscale image as a surface, and passing a ball "under" the surface.
For 3-dimensional binary dilation, you will need to create a sphere-shaped structuring element:
[x,y,z] = ndgrid(-3:3);
se = strel(sqrt(x.^2 + y.^2 + z.^2) <=3);

Sara Salimi

### Sara Salimi (view profile)

on 10 Dec 2018
I have 3D binary image. How to define a cube which dilate the binary image by factor of 5?