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:
Index number of a grayscale image

Subject: Index number of a grayscale image

From: Mathew Thomas

Date: 9 Nov, 2010 18:11:04

Message: 1 of 4

Hello,

I have an image from which I am trying to find out all the grayscale index values for certain rows and columns. Right now I am using;

x = L(Y1,X1):L(Y2,X2), which gives the index values. However, if the index values actually present are 3 and 6; it gives me 3,4,5,6 as the index values instead of just 3 and 6, which I understand is because of my code.

(X1,Y1) and (X2,Y2) are the coordinates of the two points between which I want to obtain all the gray scale indexes present. I have tried using x = L(Y1 : Y2, X1: X2), but gives me an empty matrix more often than not.

Does anyone know how I can get just the index values present. For ex, just 3 and 6 instead of 3,4,5,6.

Thanks in advance for any help.

Mathew

Subject: Index number of a grayscale image

From: Ade

Date: 9 Nov, 2010 18:28:04

Message: 2 of 4

"Mathew Thomas" <mathew99@gmail.com> wrote in message <ibc2rn$cd8$1@fred.mathworks.com>...
> Hello,
>
> I have an image from which I am trying to find out all the grayscale index values for certain rows and columns. Right now I am using;
>
> x = L(Y1,X1):L(Y2,X2), which gives the index values. However, if the index values actually present are 3 and 6; it gives me 3,4,5,6 as the index values instead of just 3 and 6, which I understand is because of my code.
>
> (X1,Y1) and (X2,Y2) are the coordinates of the two points between which I want to obtain all the gray scale indexes present. I have tried using x = L(Y1 : Y2, X1: X2), but gives me an empty matrix more often than not.
>
> Does anyone know how I can get just the index values present. For ex, just 3 and 6 instead of 3,4,5,6.
>
> Thanks in advance for any help.
>
> Mathew


try x = [L(Y1,X1) L(Y2,X2)]

Subject: Index number of a grayscale image

From: Sean

Date: 9 Nov, 2010 18:29:06

Message: 3 of 4

"Mathew Thomas" <mathew99@gmail.com> wrote in message <ibc2rn$cd8$1@fred.mathworks.com>...
> Hello,
>
> I have an image from which I am trying to find out all the grayscale index values for certain rows and columns. Right now I am using;
>
> x = L(Y1,X1):L(Y2,X2), which gives the index values. However, if the index values actually present are 3 and 6; it gives me 3,4,5,6 as the index values instead of just 3 and 6, which I understand is because of my code.
>
> (X1,Y1) and (X2,Y2) are the coordinates of the two points between which I want to obtain all the gray scale indexes present. I have tried using x = L(Y1 : Y2, X1: X2), but gives me an empty matrix more often than not.
>
> Does anyone know how I can get just the index values present. For ex, just 3 and 6 instead of 3,4,5,6.
>
> Thanks in advance for any help.
>
> Mathew

The problem is you're extracting the points in the label image and creating the vector from them, not creating the vector of the points in the image. Ie. this is what the computer is seeing:

L(X1,Y1) = 3;
L(X2,Y2) = 6;
x = 3:6 % L(X1,Y1):L(X2,Y2)
x = 3 4 5 6 %values

What you want is something more like this:
x = L(X1:X2,Y1:Y2); %All of the value in the matrix at the rectangle created with those two points as opposite corners
x = unique(x(:)); %All separate values

Subject: Index number of a grayscale image

From: Sean

Date: 9 Nov, 2010 18:48:04

Message: 4 of 4

"Ade " <aogunmefun@tessera.com> wrote in message <ibc3rk$i9a$1@fred.mathworks.com>...
> "Mathew Thomas" <mathew99@gmail.com> wrote in message <ibc2rn$cd8$1@fred.mathworks.com>...
> > Hello,
> >
> > I have an image from which I am trying to find out all the grayscale index values for certain rows and columns. Right now I am using;
> >
> > x = L(Y1,X1):L(Y2,X2), which gives the index values. However, if the index values actually present are 3 and 6; it gives me 3,4,5,6 as the index values instead of just 3 and 6, which I understand is because of my code.
> >
> > (X1,Y1) and (X2,Y2) are the coordinates of the two points between which I want to obtain all the gray scale indexes present. I have tried using x = L(Y1 : Y2, X1: X2), but gives me an empty matrix more often than not.

This won't work when Y2>Y1 or X2>X1.

> >
> > Does anyone know how I can get just the index values present. For ex, just 3 and 6 instead of 3,4,5,6.
> >
> > Thanks in advance for any help.
> >
> > Mathew
>
>
> try x = [L(Y1,X1) L(Y2,X2)]

You can also use SUB2IND to get this
L(sub2ind(size(L),[X1 X2],[Y1 Y2]))

And that is scalable up to any value of n (X1,X2...Xn)

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