"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
