The bwmorph documentation states that it uses ones(3) as the
structuring element.
Both functions, when asking for a returned image BWret, return the
same dilated image. (bwmorph without a return image seems to display
the dilated image)
Since I am asking for an updated image to be returned, what is the
difference between these two functions (using the same structuring
element, as stated above)?
Is one faster than another?
Note that BW is a logical matrix throughout my program, and therefore
BWret is also a logical matrix.
(I did notice that if BW was not logical to start with, imdilate
returns BW's type, while bwmorph returns the type logical)
Any help with this would be much appreciated.
I don't know how much it will effect my program, but I am at least
interested in the difference between the two specific calls.
-Nathan
In general, the functions in the Image Processing Toolbox that start
with "bw" refer to operations on BINARY images, while those with "im"
prefixes refer to functions that operate on GRAYSCALE images. Thus if
you pass in a grayscale image, imdilate will give you the grayscale
morphology operation (for example local max for imdilate, local min
for imerode, etc.) You can pass in grayscale or binary images to the
im functions but the bw functions only take binary (logical or 0&1)
images.
Hm. Alright then. I'll try to do some timing-tests on my own then.
I have a second question, still regarding bwmorph and imdilate, but
off topic from the first post.
How can I go about dilating only one connected "blob" of an image,
leaving the rest of the "blobs" the same size?
I would like to do this by selecting a blob with my mouse (using
ginput) and finding that region's label within my code and then
dilating only that region.
My blobs are of various shapes and sizes.
The program I use takes sections of a larger image and zooms in to
center on a blob. Doing so often includes more than one blob within
this sub-image. I would like to dilate a chosen blob within this sub-
image, rather than dilate all the blobs (as is currently happening).
Example of a subimage:
BW = [...
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;
0,0,1,1,1,0,0,1,1,1,0,0,0,0,0,0,0;
0,1,1,1,1,0,0,1,1,1,1,0,1,1,1,1,0;
0,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,0;
0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0;
0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0;
0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0;
0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
Note that if I dilate this image using the aforementioned functions,
both blobs will dilate and will ultimately become one blob.
Note that if I only want to dilate the smaller blob, the two blobs
will remain separate.
(Note that I am using 8-connectivity in my program for labeling and
whatnot)
Doing BWlab = bwlabel(BW,8); we get
BWlab ==
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;
0,0,1,1,1,0,0,2,2,2,0,0,0,0,0,0,0;
0,1,1,1,1,0,0,2,2,2,2,0,2,2,2,2,0;
0,1,1,1,0,0,0,2,2,2,2,2,2,2,2,2,0;
0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,0,0;
0,0,0,0,0,0,2,2,2,2,2,2,2,0,0,0,0;
0,0,0,2,2,2,2,2,2,0,0,0,0,0,0,0,0;
0,0,0,2,2,2,2,0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
What I would like do to is be able to click on BWlab(3,4) to select
the smaller blob to dilate, and end up with BW as:
[...
0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0;
1,1,1,1,1,1,0,1,1,1,0,0,0,0,0,0,0;
1,1,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0;
1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0;
1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,0,0;
0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0;
0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0;
0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
(I would want to be able to do this with either blob)
Any information on how to do this?
-Nathan
You will get a binary image (0 and 1 now, not 0 and 5) that has ONLY
blob #5 in it. Understand?
Doh!
I was trying to think too hard about this.
I guess all I have to do is extract that one blob (as you mention),
dilate that blob's image, and then bit-or the original image with the
dilated blob's image (right?).
Thanks for the help and clarification.
-Nathan
Ah, yeah. I've noticed that. Sometimes my blobs, through thresholding
and whatnot, should be connected while they aren't, so dilate is what
I was looking for. Thanks, though.
-Nathan
Ah, no. I have multiple options in my program to edit a given sub-
image to find the area of each blob. I somewhat automate finding each
blob using a pretty decent thresholding technique (the Triangle method
that you either mentioned to me or you've heard me speak of before in
a different thread). This thresholding, due to an uneven background
level, causes some blobs to be slightly smaller than they should be,
and therefore one dilate is usually sufficient to fill in the full
area of the blob.
I also have options for eroding, a usage of the graythresh at a given
threshold, and some manual manipulations available for me (such as
splines, filling in regions, drawing single pixels, and deleting
rectangular regions).
I will also look into eroding a selected region now that I think of
it, but as far as I can tell the same scenario applies as imdilate/
imerode and bwmorph with 'dilate' or 'erode'
Thanks for your interest in helping me out.
(Note that I DO have some functional form of imclose implemented such
that the user is allowed to dilate and erode manually as they please)
-Nathan
Ah, imerode seems to not be the same thing as using bwmorph with the
'erode' option. Test example on r2010a/r2009b/r2009a/r2007b:
>> tmp = bwmorph(true(5),'erode',1)
tmp =
0 0 0 0 0
0 1 1 1 0
0 1 1 1 0
0 1 1 1 0
0 0 0 0 0
>> tmp2 = imerode(true(5),ones(3))
tmp2 =
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
This makes me question whether imerode is working correctly... Eroding
a 5x5 matrix full of ONES/TRUE should at least get rid of the outer
layer, as the bwmorph with 'erode' does.
Could someone tell me why imerode does not (and has not) do this?
So far: 1 point for using bwmorph, 0 points for using imdilate/
imerode.
-Nathan