how to give color for same pixel values?

 Respuesta aceptada

Walter Roberson
Walter Roberson el 21 de Oct. de 2013
cmap = copper(22); %some color map
outimg = ind2rgb( uint8(locatn), cmap);
image(outimg);

2 comentarios

sheno39
sheno39 el 22 de Oct. de 2013
sir this coding works for simple 5x5 matrix. but it is not working for image..
sheno39
sheno39 el 23 de Oct. de 2013
sir can u help me to give different colors for different regions

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 19 de Oct. de 2013

0 votos

What do you mean by "pixels having the same value"? Do you mean, say, pixels having red color? And so you want to assign a green color to all pixels having "red" values? Meanwhile, why don't you look at my color segmentation demos in Image Analyst's awesome File Exchange?

8 comentarios

sheno39
sheno39 el 19 de Oct. de 2013
Editada: Image Analyst el 19 de Oct. de 2013
my input :
I=[...
2 3 10 4 6;
1 4 7 5 3;
5 2 8 4 3;
8 2 1 7 3;
1 9 8 3 4];
% Location of max pixel around each pixel is given as
locatn =[...
7 11 12 11 17;
3 11 11 11 21;
4 4 12 13 19;
10 10 10 13 19;
10 4 10 15 19;]
now i have to given same color for same values in 'locatn' matrix.
Image Analyst
Image Analyst el 19 de Oct. de 2013
Editada: Image Analyst el 19 de Oct. de 2013
I don't understand what it means when you say the location is 17 or 19 or 21. In a 2D image, there are immediate 8 neighbors. So I could possibly see a 1-8 if you define where they are located (like 1 is the upper left neighbor and you go around clockwise so that 8 is the left neighbor), but you have at least 21 locations. Where are they?
sheno39
sheno39 el 21 de Oct. de 2013
Editada: Walter Roberson el 21 de Oct. de 2013
I=[2 3 10 4 6; 1 4 7 5 3; 5 2 8 4 3;8 2 1 7 3;1 9 8 3 4;];
D = padarray(I,[1 1],0,'both');
s = size(I);
N = padarray(reshape(1:numel(I),s),[1 1],0,'both');
pt = [1 1 1;1 0 1;1 1 1] > 0;
s1 = s+2;
out = zeros(s);
for ii=2:s1(1)-1
for jj=2:s1(2)-1
D1 = D(ii-1:ii+1,jj-1:jj+1);
K = N(ii-1:ii+1,jj-1:jj+1);
K = K(pt);
[~,i0] = max(D1(pt));
out(ii-1,jj-1) = K(i0);
end
end
s=[5,5];
[R C]=ind2sub(s,out);
Sir i have attached the coding here.
The values in 'out' have the locations i have mentioned above.
Image Analyst
Image Analyst el 21 de Oct. de 2013
But I still don't know what this uncommented code does. Can you tell me what a location of 21 means? Is it the linear index or something?
sheno39
sheno39 el 22 de Oct. de 2013
yes sir it is linear indexing
Image Analyst
Image Analyst el 22 de Oct. de 2013
colormaps can only go up to 256 while linear indexes can far exceed that so you can't use a colormap. You'd have to create an RGB image from the linear index but I don't see how that would be meaningful. What you'll see is a gradient from upper left to lower right in color because, overall, that's how the linear indexes will go. How does that help?
sheno39
sheno39 el 24 de Oct. de 2013
sir can u help me convert RGB image from linear index.
sheno39
sheno39 el 24 de Oct. de 2013
Editada: sheno39 el 24 de Oct. de 2013
I used ind2rgb function. but i didn't get the correct output

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 19 de Oct. de 2013

Comentada:

el 24 de Oct. de 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by