Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Associating objects in two binary images

Subject: Associating objects in two binary images

From: Aprotim Mazumder

Date: 16 Nov, 2010 16:27:04

Message: 1 of 9

Hi I have a relatively simple problem, but I am a beginning user of Matlab image processing, so bear with me.

I have two binary images each with several objects. The number of objects in each image are similar but not exactly the same - but each object in one is associated with one or two objects in the other - the condition for association being that the smaller objects in one image are contained in or touching the larger objects in the other. Downstream of this, using these binary images as masks, I have to find the ratio or sum of...say, intensities, between associated objects.

My question simply is this - how do I find the associated objects, such that I can interrogate the ratios or sums from the downstream images on a object by object basis, and not just get a mean for the two images. Is there a ready way of doing this?

Thanks a lot and best regards,

-Aprotim.

--

Subject: Associating objects in two binary images

From: Sean de

Date: 16 Nov, 2010 17:58:04

Message: 2 of 9

"Aprotim Mazumder" <roguerace@gmail.com> wrote in message <ibubco$j1k$1@fred.mathworks.com>...
> Hi I have a relatively simple problem, but I am a beginning user of Matlab image processing, so bear with me.
>
> I have two binary images each with several objects. The number of objects in each image are similar but not exactly the same - but each object in one is associated with one or two objects in the other - the condition for association being that the smaller objects in one image are contained in or touching the larger objects in the other. Downstream of this, using these binary images as masks, I have to find the ratio or sum of...say, intensities, between associated objects.
>
> My question simply is this - how do I find the associated objects, such that I can interrogate the ratios or sums from the downstream images on a object by object basis, and not just get a mean for the two images. Is there a ready way of doing this?
>
> Thanks a lot and best regards,
>
> -Aprotim.
>
> --

Couldn't you just do a logical or on the two binary images?

Icombined = I1|I2;

Then do the math on a connected components analysis of the new objects?
CC = bwconncomp(Icomined);
or
L = bwlabel(Icombined);

STATS = regionprops(CC,...);

Subject: Associating objects in two binary images

From: Aprotim Mazumder

Date: 9 Dec, 2010 20:28:05

Message: 3 of 9

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <ibugnc$a2o$1@fred.mathworks.com>...
> "Aprotim Mazumder" <roguerace@gmail.com> wrote in message <ibubco$j1k$1@fred.mathworks.com>...
> > Hi I have a relatively simple problem, but I am a beginning user of Matlab image processing, so bear with me.
> >
> > I have two binary images each with several objects. The number of objects in each image are similar but not exactly the same - but each object in one is associated with one or two objects in the other - the condition for association being that the smaller objects in one image are contained in or touching the larger objects in the other. Downstream of this, using these binary images as masks, I have to find the ratio or sum of...say, intensities, between associated objects.
> >
> > My question simply is this - how do I find the associated objects, such that I can interrogate the ratios or sums from the downstream images on a object by object basis, and not just get a mean for the two images. Is there a ready way of doing this?
> >
> > Thanks a lot and best regards,
> >
> > -Aprotim.
> >
> > --
>
> Couldn't you just do a logical or on the two binary images?
>
> Icombined = I1|I2;
>
> Then do the math on a connected components analysis of the new objects?
> CC = bwconncomp(Icomined);
> or
> L = bwlabel(Icombined);
>
> STATS = regionprops(CC,...);

Thanks a lot for the response, I saw it late. But no, that's not it. That simply combines the two binary images. What I need to do is this: There are several objects in one binary image, and each object has one or two associated objects in the other(an associated object is any object which is in contact with the region of the first object). I need to find the intensity corresponding to any one object from the first image (easily done using the binary mask on the original image) and the intensities from its associated object. I can use the other binary image as a mask and get the intensities as before. Now with these two lists of intensities how do I know for any one value on one list which is the value of the associated object in the other. Basically given an object, is there an easy way of mapping onto its associated object in the other image. I'd greatly appreciate some insight.

Subject: Associating objects in two binary images

From: ImageAnalyst

Date: 9 Dec, 2010 21:52:45

Message: 4 of 9

Even with your new explanation I think Sean's approach sounds right.
At least it's the first step along the way. So to debunk it you'll
have to post your two images somewhere and explain why it won't work.

Subject: Associating objects in two binary images

From: Aprotim Mazumder

Date: 10 Dec, 2010 17:36:21

Message: 5 of 9

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <fca4ef35-b6d8-4d72-bf16-b89d004e2ecb@39g2000yqa.googlegroups.com>...
> Even with your new explanation I think Sean's approach sounds right.
> At least it's the first step along the way. So to debunk it you'll
> have to post your two images somewhere and explain why it won't work.

Okay, I guess I am not lucid enough. Here's an example:

http://www.mit.edu/~aprotim/example/Example.pdf

As you can see Binary2 contains objects which are contained withing the objects in Binary1. Combining them you get the image on the right.

I can use regionprops using either Binary1 or Binary2 as masks and get intensities of objects out from the original image. Now for any object (say the one in the red box) I need to find the difference or ratio of its subregion in Binary1 to its subregion(/-s) in Binary2. And I need to do this on an object by object basis for all the objects. As you can see the number of objects in Binary2 can be slightly more than in Binary1, but each object in Binary1 is associated with one or maybe two objects in Binary2.

For any object in Binary 2, will one need to compute distances from the centroids of all objects in Binary one, and choose the minimum one? Since I have thousands of such images I wonder if there a simpler way of associating objects - as any object in Binary2 is contained within objects in Binary1.

Thank you for your suggestions.

Subject: Associating objects in two binary images

From: ImageAnalyst

Date: 10 Dec, 2010 17:47:02

Message: 6 of 9

I think you'd have to mask your small interior objects by the filled,
larger ones. It will be inside only one of the larger ones. After
masking, the one with some non-zero pixels in it means that those
small objects are contained in that particular large object. In other
words, just how you'd intuitively think to do it.

Subject: Associating objects in two binary images

From: Aprotim Mazumder

Date: 13 Dec, 2010 21:13:05

Message: 7 of 9

Yes, I guess you're suggesting that before that first I either crop the smaller objects or use labelmatrix, and then proceed intuitively as you said. Thank you for the suggestion, and if no one has anything to add, I'll remove that image from the link soon.

Thanks again and best regards.


ImageAnalyst <imageanalyst@mailinator.com> wrote in message <0a71cbd2-cecc-4bde-a037-90589ad0d9ad@w17g2000yqh.googlegroups.com>...
> I think you'd have to mask your small interior objects by the filled,
> larger ones. It will be inside only one of the larger ones. After
> masking, the one with some non-zero pixels in it means that those
> small objects are contained in that particular large object. In other
> words, just how you'd intuitively think to do it.

Subject: Associating objects in two binary images

From: ImageAnalyst

Date: 13 Dec, 2010 22:37:27

Message: 8 of 9

No, I don't think I said that at all. What I said was that you have
two images: image1 which has the larger objects, and image2, which is
an image of the holes in the larger object (the holes being 1 or
white). Then you loop over small objects, masking (not cropping) the
images by each of the large objects (another loop). If the sum of
values in the masked image is more than 1, then the smaller one
"belongs" to the larger one. This will happen for only one large
object - the one that the small one is inside of. So it would be
something like this (untested, in pseudocode)

for kSmall = 1:numberOfSmallBlobs
  % Check against all the larger blobs
  for kBig = 1 : numberOfBigBlobs
    % Get PixelIdxList of the large blob
    if sum(smallImage(PixelIdxList)) > 0
      % Small blob is inside this large blob
      % Record its parent
      parentList(kSmall) = kBig;
      break; % Don't check other big blobs.
    end
  end
end

Subject: Associating objects in two binary images

From: Aprotim Mazumder

Date: 13 Dec, 2010 23:53:05

Message: 9 of 9

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <42ffad94-33d6-44e5-aed4-9d6b678f2623@m35g2000vbn.googlegroups.com>...
> No, I don't think I said that at all. What I said was that you have
> two images: image1 which has the larger objects, and image2, which is
> an image of the holes in the larger object (the holes being 1 or
> white). Then you loop over small objects, masking (not cropping) the
> images by each of the large objects (another loop). If the sum of
> values in the masked image is more than 1, then the smaller one
> "belongs" to the larger one. This will happen for only one large
> object - the one that the small one is inside of. So it would be
> something like this (untested, in pseudocode)
>
> for kSmall = 1:numberOfSmallBlobs
> % Check against all the larger blobs
> for kBig = 1 : numberOfBigBlobs
> % Get PixelIdxList of the large blob
> if sum(smallImage(PixelIdxList)) > 0
> % Small blob is inside this large blob
> % Record its parent
> parentList(kSmall) = kBig;
> break; % Don't check other big blobs.
> end
> end
> end

Got you! - great, and thanks a lot!

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us