Got Questions? Get Answers.
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:
Very basic Question

Subject: Very basic Question

From: Student

Date: 25 Mar, 2012 19:24:12

Message: 1 of 4

Hi, I am having trouble keeping only certain coloured pixels and removing the others.

I have already done region props and know that the pixels in the image (which are required) are above .130 and below .200 in the green channel.

The question I have is how would I tell matlab to keep only the pixels that are between these two limits. And from there display only the pixels that match the criteria set?

Any help would be great

Subject: Very basic Question

From: Matt J

Date: 25 Mar, 2012 22:02:11

Message: 2 of 4

"Student " <slowlygoes@hotmail.com> wrote in message <jknrcs$mgl$1@newscl01ah.mathworks.com>...
> Hi, I am having trouble keeping only certain coloured pixels and removing the others.
>
> I have already done region props and know that the pixels in the image (which are required) are above .130 and below .200 in the green channel.
>
> The question I have is how would I tell matlab to keep only the pixels that are between these two limits. And from there display only the pixels that match the criteria set?
=============

[m,n,p]=size(YourImage);

YourImage=reshape(YourImage,[],3);

bad=YourImage(:,2)<.130 | YourImage(:,2)>.200; %middle column is green

YourImage(bad,:)=nan;

YourImage=reshape(YourImage,m,n,p);

Subject: Very basic Question

From: Student

Date: 25 Mar, 2012 23:11:12

Message: 3 of 4

"Matt J" wrote in message <jko4l3$j43$1@newscl01ah.mathworks.com>...
> "Student " <slowlygoes@hotmail.com> wrote in message <jknrcs$mgl$1@newscl01ah.mathworks.com>...
> > Hi, I am having trouble keeping only certain coloured pixels and removing the others.
> >
> > I have already done region props and know that the pixels in the image (which are required) are above .130 and below .200 in the green channel.
> >
> > The question I have is how would I tell matlab to keep only the pixels that are between these two limits. And from there display only the pixels that match the criteria set?
> =============
>
> [m,n,p]=size(YourImage);
>
> YourImage=reshape(YourImage,[],3);
>
> bad=YourImage(:,2)<.130 | YourImage(:,2)>.200; %middle column is green
>
> YourImage(bad,:)=nan;
>
> YourImage=reshape(YourImage,m,n,p);

Thank you for the reply. This is perfect, exactly what I needed.

There is a small problem with it though, its seems to mirror the same information 3 times. It repeats the remaining pixels 3 times going from left to right. Any idea why this is hapening and also how to stop it?

Subject: Very basic Question

From: Matt J

Date: 26 Mar, 2012 13:24:10

Message: 4 of 4

"Student " <slowlygoes@hotmail.com> wrote in message <jko8mg$10d$1@newscl01ah.mathworks.com>...
> "Matt J" wrote in message <jko4l3$j43$1@newscl01ah.mathworks.com>...
> > "Student " <slowlygoes@hotmail.com> wrote in message <jknrcs$mgl$1@newscl01ah.mathworks.com>...
> > > Hi, I am having trouble keeping only certain coloured pixels and removing the others.
> > >
> > > I have already done region props and know that the pixels in the image (which are required) are above .130 and below .200 in the green channel.
> > >
> > > The question I have is how would I tell matlab to keep only the pixels that are between these two limits. And from there display only the pixels that match the criteria set?
> > =============
> >
> > [m,n,p]=size(YourImage);
> >
> > YourImage=reshape(YourImage,[],3);
> >
> > bad=YourImage(:,2)<.130 | YourImage(:,2)>.200; %middle column is green
> >
> > YourImage(bad,:)=nan;
> >
> > YourImage=reshape(YourImage,m,n,p);
>
> Thank you for the reply. This is perfect, exactly what I needed.
>
> There is a small problem with it though, its seems to mirror the same information 3 times. It repeats the remaining pixels 3 times going from left to right. Any idea why this is hapening and also how to stop it?
================

This might be what you want,

 YourImage(bad,2)=nan;

though I'm not sure what difference it makes to you.

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