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:
multi-ROI image masking

Subject: multi-ROI image masking

From: Cory

Date: 1 Nov, 2010 16:01:06

Message: 1 of 10

I am trying to create a function to allow a user to select multiple ROI's and then create a BW mask over the original RGB image. This would leave an image showing only the ROI's that were selected by the user from the original image.

I am having a hard time getting each iteration of my loop to assign a new variable name to each ROI selected, and then adding all these ROI's into one mask.

Any help is appreciated!!

Subject: multi-ROI image masking

From: Sean

Date: 1 Nov, 2010 16:12:03

Message: 2 of 10

"Cory " <cory.hayes@gkndriveline.com> wrote in message <iamo82$kl9$1@fred.mathworks.com>...
> I am trying to create a function to allow a user to select multiple ROI's and then create a BW mask over the original RGB image. This would leave an image showing only the ROI's that were selected by the user from the original image.
>
> I am having a hard time getting each iteration of my loop to assign a new variable name to each ROI selected, and then adding all these ROI's into one mask.
>
> Any help is appreciated!!

Why don't you just have one mask and add the ROIs every time?

Map = false(size(image));

---
ROI = however you get you ROI
Map(ROI) = true;
---
repeated n times or as long as necessary etc.

Subject: multi-ROI image masking

From: Cory

Date: 1 Nov, 2010 16:46:04

Message: 3 of 10

> Why don't you just have one mask and add the ROIs every time?
>
> Map = false(size(image));
>
> ---
> ROI = however you get you ROI
> Map(ROI) = true;
> ---
> repeated n times or as long as necessary etc.

Ok, I understand how this would work. However how do I go about modifying the Map? I tried it in a loop but come back with a black image.

Subject: multi-ROI image masking

From: ImageAnalyst

Date: 1 Nov, 2010 16:46:53

Message: 4 of 10

You might use roipolyold() or imfreehand() (and cousins) and
poly2mask() to create the mask images, then build up your image one
ROI at a time like Sean says.

Subject: multi-ROI image masking

From: Cory

Date: 1 Nov, 2010 17:18:05

Message: 5 of 10

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <218f3d01-70dd-48a0-9d16-5df5896588a7@30g2000yql.googlegroups.com>...
> You might use roipolyold() or imfreehand() (and cousins) and
> poly2mask() to create the mask images, then build up your image one
> ROI at a time like Sean says.

I am still having a problem building up the image. I tried just repeating the code Sean gave me, but every time I run through again the previous mask is gone, and only the current selected ROI shows up in the mask.

Subject: multi-ROI image masking

From: Sean

Date: 1 Nov, 2010 17:22:04

Message: 6 of 10

"Cory " <cory.hayes@gkndriveline.com> wrote in message <iamsod$jqv$1@fred.mathworks.com>...
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message <218f3d01-70dd-48a0-9d16-5df5896588a7@30g2000yql.googlegroups.com>...
> > You might use roipolyold() or imfreehand() (and cousins) and
> > poly2mask() to create the mask images, then build up your image one
> > ROI at a time like Sean says.
>
> I am still having a problem building up the image. I tried just repeating the code Sean gave me, but every time I run through again the previous mask is gone, and only the current selected ROI shows up in the mask.

Don't rerun the original call to M = false... since this will overwrite your previous work.


Post your code here for more useful comments.

Subject: multi-ROI image masking

From: Cory

Date: 1 Nov, 2010 17:29:07

Message: 7 of 10

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <iamsvs$64v$1@fred.mathworks.com>...
> "Cory " <cory.hayes@gkndriveline.com> wrote in message <iamsod$jqv$1@fred.mathworks.com>...
> > ImageAnalyst <imageanalyst@mailinator.com> wrote in message <218f3d01-70dd-48a0-9d16-5df5896588a7@30g2000yql.googlegroups.com>...
> > > You might use roipolyold() or imfreehand() (and cousins) and
> > > poly2mask() to create the mask images, then build up your image one
> > > ROI at a time like Sean says.
> >
> > I am still having a problem building up the image. I tried just repeating the code Sean gave me, but every time I run through again the previous mask is gone, and only the current selected ROI shows up in the mask.
>
> Don't rerun the original call to M = false... since this will overwrite your previous work.
>
>
> Post your code here for more useful comments.

Actually, I think I just fixed the problem. However, now I have the issue of trying to overlay the image on the original RGB image and showing only the areas selected by the ROI. However that is unrelated...

Subject: multi-ROI image masking

From: Cory

Date: 1 Nov, 2010 17:30:09

Message: 8 of 10

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <iamsvs$64v$1@fred.mathworks.com>...
> "Cory " <cory.hayes@gkndriveline.com> wrote in message <iamsod$jqv$1@fred.mathworks.com>...
> > ImageAnalyst <imageanalyst@mailinator.com> wrote in message <218f3d01-70dd-48a0-9d16-5df5896588a7@30g2000yql.googlegroups.com>...
> > > You might use roipolyold() or imfreehand() (and cousins) and
> > > poly2mask() to create the mask images, then build up your image one
> > > ROI at a time like Sean says.
> >
> > I am still having a problem building up the image. I tried just repeating the code Sean gave me, but every time I run through again the previous mask is gone, and only the current selected ROI shows up in the mask.
>
> Don't rerun the original call to M = false... since this will overwrite your previous work.
>
>
> Post your code here for more useful comments.

Actually, I think I just fixed the problem. However, now I have the issue of trying to overlay the image on the original RGB image and showing only the areas selected by the ROI. However that is unrelated...

Subject: multi-ROI image masking

From: Sean

Date: 1 Nov, 2010 17:34:04

Message: 9 of 10

"Cory " <cory.hayes@gkndriveline.com> wrote in message <iamtd3$4do$1@fred.mathworks.com>...
> "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <iamsvs$64v$1@fred.mathworks.com>...
> > "Cory " <cory.hayes@gkndriveline.com> wrote in message <iamsod$jqv$1@fred.mathworks.com>...
> > > ImageAnalyst <imageanalyst@mailinator.com> wrote in message <218f3d01-70dd-48a0-9d16-5df5896588a7@30g2000yql.googlegroups.com>...
> > > > You might use roipolyold() or imfreehand() (and cousins) and
> > > > poly2mask() to create the mask images, then build up your image one
> > > > ROI at a time like Sean says.
> > >
> > > I am still having a problem building up the image. I tried just repeating the code Sean gave me, but every time I run through again the previous mask is gone, and only the current selected ROI shows up in the mask.
> >
> > Don't rerun the original call to M = false... since this will overwrite your previous work.
> >
> >
> > Post your code here for more useful comments.
>
> Actually, I think I just fixed the problem. However, now I have the issue of trying to overlay the image on the original RGB image and showing only the areas selected by the ROI. However that is unrelated...


MaskApplied = bsxfun(@times,OriginalRGB,cast(Map,class(OriginalRGB)))

Subject: multi-ROI image masking

From: Cory

Date: 1 Nov, 2010 17:57:03

Message: 10 of 10

 
> MaskApplied = bsxfun(@times,OriginalRGB,cast(Map,class(OriginalRGB)))

Thank you! this works perfectly... however do you have any idea why the mask is red?

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