From: Nathan on
What is the difference between using bwmorph(BW,'dilate',1) and using
imdilate(BW,ones(3))? (Is there any advantage of using one over the
other?)

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
From: ImageAnalyst on
I doubt there's any difference. You say the output images are the
same. You could try timing with tic and toc to see if there is any
speed difference (but I doubt it). A kernel window with radius of 1
is essentially
1 1 1
1 1 1
1 1 1
which is also what ones(3) is, so I don't doubt that they're the same
for binary images(I haven't brought up the documentation and
scrutinized it though).

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.
From: Nathan on
On Apr 26, 3:37 pm, ImageAnalyst <imageanal...(a)mailinator.com> wrote:
> I doubt there's any difference.  You say the output images are the
> same.  You could try timing with tic and toc to see if there is any
> speed difference (but I doubt it).  A kernel window with radius of 1
> is essentially
> 1 1 1
> 1 1 1
> 1 1 1
> which is also what ones(3) is, so I don't doubt that they're the same
> for binary images(I haven't brought up the documentation and
> scrutinized it though).
>
> 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
From: ImageAnalyst on
Nathan:
Extract out one blob into it's own image. Let's say you want the blob
that is labeled "5" and want to exclude all the others. You can do:
blob5Image = (labeledImage == 5);

You will get a binary image (0 and 1 now, not 0 and 5) that has ONLY
blob #5 in it. Understand?

From: Nathan on
On Apr 26, 5:32 pm, ImageAnalyst <imageanal...(a)mailinator.com> wrote:
> Nathan:
> Extract out one blob into it's own image.  Let's say you want the blob
> that is labeled "5" and want to exclude all the others.  You can do:
> blob5Image = (labeledImage == 5);
>
> 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