Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

3d Morphological operations (erosion, dilation)

673 views
Skip to first unread message

Anand

unread,
Sep 21, 2006, 10:51:03 AM9/21/06
to
Hi,

How can we perform erosion adn dilation operations in 3d in matlab?
Are there any functions in matlab to perform erosion and dilation of a
3d image? If then, what are they?

Thanks,
Anand.

Peter Bone

unread,
Sep 21, 2006, 11:36:18 AM9/21/06
to
I don't think there are any functions for this but maybe you can do the morphological operation on each xy layer of the 3D matrix and then do it again on each xz layer. That may not work very well though because it would erode twice in places.

Steve Eddins

unread,
Sep 21, 2006, 12:19:53 PM9/21/06
to

Almost all of the morphological functions in the Image Processing
Toolbox can work in any number of dimensions. Use imdilate and imerode.

--
Steve Eddins
http://blogs.mathworks.com/steve

Dahai

unread,
Sep 23, 2009, 5:00:21 PM9/23/09
to
Beautiful. I googled and found this answer, and---It worked. ---
Very useful as I am a CT person.
Thanks.
DX

Dahai

unread,
Sep 23, 2009, 5:13:19 PM9/23/09
to
Well, no quite. After a careful inspection of the resulting image, it is obvious that the dilation only worked on (x,y) slices, and did not work through z direction, even though my strel is [1 1 1;1 1 1;1 1 1], a cube. How can we deal with that?

Thanks. DX

Matt

unread,
Sep 23, 2009, 5:31:06 PM9/23/09
to
"Dahai " <daha...@merck.com> wrote in message <h9e31e$e5l$1...@fred.mathworks.com>...

> Well, no quite. After a careful inspection of the resulting image, it is obvious that the dilation only worked on (x,y) slices, and did not work through z direction, even though my strel is [1 1 1;1 1 1;1 1 1], a cube. How can we deal with that?

Is it binary erosion? If so, you can get the equivalent by doing

result = convn(logical(A),[1 1 1;1 1 1;1 1 1]/9,'same')>=1

Since [1 1 1;1 1 1;1 1 1] is also separable, you can accelerate computation, possibly, by doing the convolution separably.

Bruno Luong

unread,
Sep 23, 2009, 7:04:06 PM9/23/09
to

Steve Eddins

unread,
Sep 24, 2009, 8:25:44 AM9/24/09
to

[1 1 1;1 1 1;1 1 1] is a square strel, not a cube. ones(3,3,3) is a cube.

>> a = zeros(3,3,3);
>> a(2,2,2) = 1
a(:,:,1) =
0 0 0
0 0 0
0 0 0
a(:,:,2) =
0 0 0
0 1 0
0 0 0
a(:,:,3) =
0 0 0
0 0 0
0 0 0
>> imdilate(a,ones(3,3,3))
ans(:,:,1) =


1 1 1
1 1 1
1 1 1

ans(:,:,2) =


1 1 1
1 1 1
1 1 1

ans(:,:,3) =


1 1 1
1 1 1
1 1 1

---
Steve Eddins
http://blogs.mathworks.com/steve/

Dave

unread,
Mar 11, 2015, 5:39:09 PM3/11/15
to
"Anand" <suresh...@gmail.com> wrote in message <1158850263.0...@m7g2000cwm.googlegroups.com>...
On top of Steve's solution, I just wanted to share a quick method for getting a BW-compatible ball element, since strel's built-in one seems to be completely incompatible with logical/BW.

[xgrid, ygrid, zgrid] = meshgrid(-radius:radius);
ball = (sqrt(xgrid.^2 + ygrid.^2 + zgrid.^2) <= radius);

This gives you a 3-d ball matrix of any size.
0 new messages