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:
mask | image

Subject: mask | image

From: Mario

Date: 22 Feb, 2008 17:16:04

Message: 1 of 12

Hi,
I have a uint8 image and a (logical) mask representing the
silhouette of a person extracted from the image.

Now I'd want to apply this mask to the image in order to
view just the person, but with its color.

Is it clear? It's a so stupid question that I'm unable to
explain it too... :|
Regards,

Mario

Subject: mask | image

From: Ashish Uthama

Date: 22 Feb, 2008 17:48:59

Message: 2 of 12

Tye the .* operation

man =3D picture.*mask

though both picture and mask have to be the same size. But of course, yo=
u =

already know that.

On Fri, 22 Feb 2008 12:16:04 -0500, Mario <nospam@yahoo.com> wrote:

> Hi,
> I have a uint8 image and a (logical) mask representing the
> silhouette of a person extracted from the image.
>
> Now I'd want to apply this mask to the image in order to
> view just the person, but with its color.
>
> Is it clear? It's a so stupid question that I'm unable to
> explain it too... :|
> Regards,
>
> Mario

Subject: mask | image

From: Arthur G

Date: 22 Feb, 2008 17:55:59

Message: 3 of 12

On 2008-02-22 12:48:59 -0500, "Ashish Uthama" <authama@mathworks.com> said:

> Tye the .* operation
>
> man = picture.*mask
>
> though both picture and mask have to be the same size. But of course, yo u
> already know that.
>
> On Fri, 22 Feb 2008 12:16:04 -0500, Mario <nospam@yahoo.com> wrote:
>
>> Hi,
>> I have a uint8 image and a (logical) mask representing the
>> silhouette of a person extracted from the image.
>>
>> Now I'd want to apply this mask to the image in order to
>> view just the person, but with its color.
>>
>> Is it clear? It's a so stupid question that I'm unable to
>> explain it too... :|
>> Regards,
>>
>> Mario

Alternately, you can use logical indexing, e.g.
man(~mask) = 0

Subject: mask | image

From: Mario

Date: 25 Feb, 2008 17:48:02

Message: 4 of 12

"Ashish Uthama" <authama@mathworks.com> wrote in message
<op.t6xs3xlfkk0qo1@uthamaa.dhcp.mathworks.com>...
> Tye the .* operation
>
> man =3D picture.*mask
>

that's what I thought.. but the picture is <480x640x3 uint8>
and mask is <480x640 uint8>
so I tried to do the .* operation between the 3 color
channel (probably there's a faster way, thanks if u can
suggest me..) but, at the end, the image I see is still b&w..

this is the code

imageR=mask.*picture(:,:,1);
imageG=mask.*picture(:,:,2);
imageB=mask.*picture(:,:,3);
imageRGB=zeros(480,640,3);
imageRGB(.,:,1)=imageR;
imageRGB(:,:,2)=imageG;
imageRGB(:,:,3)=imageB;
imshow(imageRGB);

Subject: mask | image

From: Ashish Uthama

Date: 25 Feb, 2008 18:13:49

Message: 5 of 12

picture(:,:,1)=3Dpicture(:,:,1).*mask;
picture(:,:,2)=3Dpicture(:,:,2).*mask;
picture(:,:,3)=3Dpicture(:,:,3).*mask;

To the best of my knowledge, the above should work.

Not sure why you dont see color with your code

On Mon, 25 Feb 2008 12:48:02 -0500, Mario <nospam@yahoo.com> wrote:

> "Ashish Uthama" <authama@mathworks.com> wrote in message
> <op.t6xs3xlfkk0qo1@uthamaa.dhcp.mathworks.com>...
>> Tye the .* operation
>>
>> man =3D3D picture.*mask
>>
>
> that's what I thought.. but the picture is <480x640x3 uint8>
> and mask is <480x640 uint8>
> so I tried to do the .* operation between the 3 color
> channel (probably there's a faster way, thanks if u can
> suggest me..) but, at the end, the image I see is still b&w..
>
> this is the code
>
> imageR=3Dmask.*picture(:,:,1);
> imageG=3Dmask.*picture(:,:,2);
> imageB=3Dmask.*picture(:,:,3);
> imageRGB=3Dzeros(480,640,3);
> imageRGB(.,:,1)=3DimageR;
> imageRGB(:,:,2)=3DimageG;
> imageRGB(:,:,3)=3DimageB;
> imshow(imageRGB);
>
>
>

Subject: mask | image

From: ImageAnalyst

Date: 26 Feb, 2008 02:26:55

Message: 6 of 12

On Feb 25, 12:48=A0pm, "Mario " <nos...@yahoo.com> wrote:
> "Ashish Uthama" <auth...@mathworks.com> wrote in message
>
> <op.t6xs3xlfkk0...@uthamaa.dhcp.mathworks.com>...
>
> > Tye the .* operation
>
> > man =3D3D picture.*mask
>
> that's what I thought.. but the picture is <480x640x3 uint8>
> and mask is <480x640 uint8>
> so I tried to do the .* operation between the 3 color
> channel (probably there's a faster way, thanks if u can
> suggest me..) but, at the end, the image I see is still b&w..
>
> this is the code
>
> imageR=3Dmask.*picture(:,:,1);
> imageG=3Dmask.*picture(:,:,2);
> imageB=3Dmask.*picture(:,:,3);
> imageRGB=3Dzeros(480,640,3);
> imageRGB(.,:,1)=3DimageR;
> imageRGB(:,:,2)=3DimageG;
> imageRGB(:,:,3)=3DimageB;
> imshow(imageRGB);

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Mario:
It should work. Try this demo with a standard MATLAB demo image and
let us know if you don't get a masked image that's full color:
Regards,
ImageAnalyst
P.S. You had a syntax error in the line imageRGB(.,:,1)=3DimageR; where
you had a dot instead of a colon.

% Macro to demo masking of color image.
picture=3Dimread('autumn.tif');% Open standard MATLAB demo image.
subplot(2,2,1);
imshow(picture);
title('Original');
mask =3D uint8(picture(:,:,1) < 200); % Get mask of non-sky region
subplot(2,2,2);
imshow(mask, []);
title('Mask');
imageR=3Dmask .* picture(:,:,1);
imageG=3Dmask .* picture(:,:,2);
imageB=3Dmask .* picture(:,:,3);
imageRGB(:,:,1)=3DimageR;
imageRGB(:,:,2)=3DimageG;
imageRGB(:,:,3)=3DimageB;
subplot(2,2,4);
imshow(imageRGB);
title('Sky Masked Out');

Subject: mask | image

From: Vihang Patil

Date: 26 Feb, 2008 05:09:02

Message: 7 of 12

ImageAnalyst <imageanalyst@mailinator.com> wrote in message
<f50429ea-c28c-4076-a7c1-ba96c243b83b@n58g2000hsf.googlegroups.com>...
> On Feb 25, 12:48=A0pm, "Mario " <nos...@yahoo.com> wrote:
> > "Ashish Uthama" <auth...@mathworks.com> wrote in message
> >
> > <op.t6xs3xlfkk0...@uthamaa.dhcp.mathworks.com>...
> >
> > > Tye the .* operation
> >
> > > man =3D3D picture.*mask
> >
> > that's what I thought.. but the picture is <480x640x3 uint8>
> > and mask is <480x640 uint8>
> > so I tried to do the .* operation between the 3 color
> > channel (probably there's a faster way, thanks if u can
> > suggest me..) but, at the end, the image I see is still
b&w..
> >
> > this is the code
> >
> > imageR=3Dmask.*picture(:,:,1);
> > imageG=3Dmask.*picture(:,:,2);
> > imageB=3Dmask.*picture(:,:,3);
> > imageRGB=3Dzeros(480,640,3);
> > imageRGB(.,:,1)=3DimageR;
> > imageRGB(:,:,2)=3DimageG;
> > imageRGB(:,:,3)=3DimageB;
> > imshow(imageRGB);
>
>
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
>
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> Mario:
> It should work. Try this demo with a standard MATLAB demo
image and
> let us know if you don't get a masked image that's full color:
> Regards,
> ImageAnalyst
> P.S. You had a syntax error in the line
imageRGB(.,:,1)=3DimageR; where
> you had a dot instead of a colon.
>
> % Macro to demo masking of color image.
> picture=3Dimread('autumn.tif');% Open standard MATLAB demo
image.
> subplot(2,2,1);
> imshow(picture);
> title('Original');
> mask =3D uint8(picture(:,:,1) < 200); % Get mask of
non-sky region
> subplot(2,2,2);
> imshow(mask, []);
> title('Mask');
> imageR=3Dmask .* picture(:,:,1);
> imageG=3Dmask .* picture(:,:,2);
> imageB=3Dmask .* picture(:,:,3);
> imageRGB(:,:,1)=3DimageR;
> imageRGB(:,:,2)=3DimageG;
> imageRGB(:,:,3)=3DimageB;
> subplot(2,2,4);
> imshow(imageRGB);
> title('Sky Masked Out');


This is to ImageAnalyst
Why do you use the word "3D" everwhere?. It makes the code
and the readable matter so difficult to understand..
Could you please avoid it.
Vihang

Subject: mask | image

From: ImageAnalyst

Date: 26 Feb, 2008 20:13:47

Message: 8 of 12

On Feb 26, 12:09=A0am, "Vihang Patil" <vihang_pa...@yahoo.com> wrote:
> ImageAnalyst <imageanal...@mailinator.com> wrote in message
>
> <f50429ea-c28c-4076-a7c1-ba96c243b...@n58g2000hsf.googlegroups.com>...
>
>
>
> > On Feb 25, 12:48=3DA0pm, "Mario " <nos...@yahoo.com> wrote:
> > > "Ashish Uthama" <auth...@mathworks.com> wrote in message
>
> > > <op.t6xs3xlfkk0...@uthamaa.dhcp.mathworks.com>...
>
> > > > Tye the .* operation
>
> > > > man =3D3D3D picture.*mask
>
> > > that's what I thought.. but the picture is <480x640x3 uint8>
> > > and mask is <480x640 uint8>
> > > so I tried to do the .* operation between the 3 color
> > > channel (probably there's a faster way, thanks if u can
> > > suggest me..) but, at the end, the image I see is still
> b&w..
>
> > > this is the code
>
> > > imageR=3D3Dmask.*picture(:,:,1);
> > > imageG=3D3Dmask.*picture(:,:,2);
> > > imageB=3D3Dmask.*picture(:,:,3);
> > > imageRGB=3D3Dzeros(480,640,3);
> > > imageRGB(.,:,1)=3D3DimageR;
> > > imageRGB(:,:,2)=3D3DimageG;
> > > imageRGB(:,:,3)=3D3DimageB;
> > > imshow(imageRGB);
>
> =3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3=
D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=AD=3D
>
> =3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3=
D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D> Mario:
> > It should work. =A0Try this demo with a standard MATLAB demo
> image and
> > let us know if you don't get a masked image that's full color:
> > Regards,
> > ImageAnalyst
> > P.S. You had a syntax error in the line
>
> imageRGB(.,:,1)=3D3DimageR; where
>
>
>
>
>
> > you had a dot instead of a colon.
>
> > % Macro to demo masking of color image.
> > picture=3D3Dimread('autumn.tif');% Open standard MATLAB demo
> image.
> > subplot(2,2,1);
> > imshow(picture);
> > title('Original');
> > mask =3D3D uint8(picture(:,:,1) < 200); % Get mask of
> non-sky region
> > subplot(2,2,2);
> > imshow(mask, []);
> > title('Mask');
> > imageR=3D3Dmask .* picture(:,:,1);
> > imageG=3D3Dmask .* picture(:,:,2);
> > imageB=3D3Dmask .* picture(:,:,3);
> > imageRGB(:,:,1)=3D3DimageR;
> > imageRGB(:,:,2)=3D3DimageG;
> > imageRGB(:,:,3)=3D3DimageB;
> > subplot(2,2,4);
> > imshow(imageRGB);
> > title('Sky Masked Out');
>
> This is to ImageAnalyst
> Why do you use the word "3D" everwhere?. It makes the code
> and the readable matter so difficult to understand..
> Could you please avoid it.
> Vihang- Hide quoted text -
>
> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

----------------------------------------------------------------------------=
------------------------------------
Vihang:
I agree it's annoying. I don't put in a 3D after every equals sign.
In fact when I look up the posts in Google, only your responses to me
have the 3D in them, not mine. I think your news reader has trouble
with equals signs. Also, when you look at other responses to my
messages, such as Ivan's at
http://tinyurl.com/3c8gdj
you'll see his newsreader doesn't add any 3D, so maybe it's just you
or your news reader. I put the dividing lines in to separate my
responses from the others. As you know, it can get confusing when
there are so many angle brackets as various levels and people
sometimes respond in the middle of the message rather than all at the
end or beginning. Often it's hard to tell who said what. But for you
I can change from =3D to - so that maybe you won't see the 3D on my
equals signs. I use Google (to read and post) because of the nice
searchable archive integrated in with the newsreader. What news
reader do you use?
Regards,
ImageAnalyst

Subject: mask | image

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 26 Feb, 2008 20:23:23

Message: 9 of 12

In article <b3ae8c26-58d4-4d13-a310-21ee04de4570@34g2000hsz.googlegroups.com>,
ImageAnalyst <imageanalyst@mailinator.com> wrote:

>I agree it's annoying. I don't put in a 3D after every equals sign.
>In fact when I look up the posts in Google, only your responses to me
>have the 3D in them, not mine. I think your news reader has trouble
>with equals signs.

No, the problem is at your end. Google groups is using
an encoding of printable-quoted, which converts non-ascii
characters to equal sign followed by two hexidecimal digits;
unfortunately in order to get that to work, the equal sign itself
has to be encoded as equal-sign 3 D (the hex for the equal sign
character.)

Google groups should not be using printable-quoted encoding for
Usenet postings -- MIME is not for use with Usenet (according
to the MIME RFCs.) There is no fault with newsreaders that expect
the standards to be respected.
--
   "History is a pile of debris" -- Laurie Anderson

Subject: mask | image

From: Vihang Patil

Date: 27 Feb, 2008 13:03:01

Message: 10 of 12

ImageAnalyst <imageanalyst@mailinator.com> wrote in
message <b3ae8c26-58d4-4d13-a310-
21ee04de4570@34g2000hsz.googlegroups.com>...
> On Feb 26, 12:09=A0am, "Vihang Patil"
<vihang_pa...@yahoo.com> wrote:
> > ImageAnalyst <imageanal...@mailinator.com> wrote in
message
> >
> > <f50429ea-c28c-4076-a7c1-
ba96c243b...@n58g2000hsf.googlegroups.com>...
> >
> >
> >
> > > On Feb 25, 12:48=3DA0pm, "Mario " <nos...@yahoo.com>
wrote:
> > > > "Ashish Uthama" <auth...@mathworks.com> wrote in
message
> >
> > > > <op.t6xs3xlfkk0...@uthamaa.dhcp.mathworks.com>...
> >
> > > > > Tye the .* operation
> >
> > > > > man =3D3D3D picture.*mask
> >
> > > > that's what I thought.. but the picture is
<480x640x3 uint8>
> > > > and mask is <480x640 uint8>
> > > > so I tried to do the .* operation between the 3
color
> > > > channel (probably there's a faster way, thanks if
u can
> > > > suggest me..) but, at the end, the image I see is
still
> > b&w..
> >
> > > > this is the code
> >
> > > > imageR=3D3Dmask.*picture(:,:,1);
> > > > imageG=3D3Dmask.*picture(:,:,2);
> > > > imageB=3D3Dmask.*picture(:,:,3);
> > > > imageRGB=3D3Dzeros(480,640,3);
> > > > imageRGB(.,:,1)=3D3DimageR;
> > > > imageRGB(:,:,2)=3D3DimageG;
> > > > imageRGB(:,:,3)=3D3DimageB;
> > > > imshow(imageRGB);
> >
> >
=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3
D=3D3D=3D3D=3D3=
> D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=AD=3D
> >
> >
=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3
D=3D3D=3D3D=3D3=
> D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D> Mario:
> > > It should work. =A0Try this demo with a standard
MATLAB demo
> > image and
> > > let us know if you don't get a masked image that's
full color:
> > > Regards,
> > > ImageAnalyst
> > > P.S. You had a syntax error in the line
> >
> > imageRGB(.,:,1)=3D3DimageR; where
> >
> >
> >
> >
> >
> > > you had a dot instead of a colon.
> >
> > > % Macro to demo masking of color image.
> > > picture=3D3Dimread('autumn.tif');% Open standard
MATLAB demo
> > image.
> > > subplot(2,2,1);
> > > imshow(picture);
> > > title('Original');
> > > mask =3D3D uint8(picture(:,:,1) < 200); % Get mask of
> > non-sky region
> > > subplot(2,2,2);
> > > imshow(mask, []);
> > > title('Mask');
> > > imageR=3D3Dmask .* picture(:,:,1);
> > > imageG=3D3Dmask .* picture(:,:,2);
> > > imageB=3D3Dmask .* picture(:,:,3);
> > > imageRGB(:,:,1)=3D3DimageR;
> > > imageRGB(:,:,2)=3D3DimageG;
> > > imageRGB(:,:,3)=3D3DimageB;
> > > subplot(2,2,4);
> > > imshow(imageRGB);
> > > title('Sky Masked Out');
> >
> > This is to ImageAnalyst
> > Why do you use the word "3D" everwhere?. It makes the
code
> > and the readable matter so difficult to understand..
> > Could you please avoid it.
> > Vihang- Hide quoted text -
> >
> > - Show quoted text -- Hide quoted text -
> >
> > - Show quoted text -
>
> ---------------------------------------------------------
-------------------=
> ------------------------------------
> Vihang:
> I agree it's annoying. I don't put in a 3D after every
equals sign.
> In fact when I look up the posts in Google, only your
responses to me
> have the 3D in them, not mine. I think your news reader
has trouble
> with equals signs. Also, when you look at other
responses to my
> messages, such as Ivan's at
> http://tinyurl.com/3c8gdj
> you'll see his newsreader doesn't add any 3D, so maybe
it's just you
> or your news reader. I put the dividing lines in to
separate my
> responses from the others. As you know, it can get
confusing when
> there are so many angle brackets as various levels and
people
> sometimes respond in the middle of the message rather
than all at the
> end or beginning. Often it's hard to tell who said
what. But for you
> I can change from =3D to - so that maybe you won't see
the 3D on my
> equals signs. I use Google (to read and post) because
of the nice
> searchable archive integrated in with the newsreader.
What news
> reader do you use?
> Regards,
> ImageAnalyst

Hello ImageAnalyst
Well, I use the newsreader found here,
http://www.mathworks.com/matlabcentral/newsreader/

and I think most of the people out there might also might
be accessing the newsreader from the same location. If you
just click on the link I have posted below, you will see
all your post contains this word "3D" and even though you
give nice suggestions, but because of this "3D" its really
hard to follow.
http://www.mathworks.com/matlabcentral/newsreader/search_re
sults?search_string=ImageAnalyst

 Regards
Vihang

Subject: mask | image

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 27 Feb, 2008 15:01:11

Message: 11 of 12

In article <fq3n25$216$1@fred.mathworks.com>,
Vihang Patil <vihang_patil@yahoo.com> wrote:

>Well, I use the newsreader found here,
>http://www.mathworks.com/matlabcentral/newsreader/

>and I think most of the people out there might also might
>be accessing the newsreader from the same location.


The statistics I compiled and posted on September 17 2007
showed 69% using the mathworks newsreader, 13.3% using google groups,
and the rest using Usenet.

The statistics would have significantly changed since then, as
I (one of the Useneters) started posting noticably more;
about 10% of the postings these days are from me.
(But I have a *long* way to go to catch up to 'us' or Steve Lord!!)
--
  "Tired minds don't plan well. Sleep first, plan later."
                                              -- Walter Reisch

Subject: mask | image

From: Vihang Patil

Date: 27 Feb, 2008 15:34:02

Message: 12 of 12

To ImageAnalyst
This is what your response looks like in the Matlab
Newsgroup

"I can change from =3D to - so that maybe you won't see
the 3D on my
equals signs."

This is what your response looks like in Google Groups
"I can change from = to - so that maybe you won't see the
3D on my
equals signs. "

Strange. So, is it wrong with Google Groups or Matlab
Newsgroup? Need to know from the webmaster.
Regards
Vihang

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