can u make black color region in to some other color say red or green in the given image but dont change the white color?
Mostrar comentarios más antiguos
here i have attached the image in which i want green or red color instead of black color region for my academic work. please give me accurate answer.
https://mail.google.com/mail/?ui=2&ik=bcbccaefc4&view=att&th=131d66f90017f805&attid=0.1&disp=inline&realattid=f_grfxa06t0&zw
thanks in advance
9 comentarios
Friedrich
el 17 de Ag. de 2011
I can't access the image. Please upload it somewhere else.
somasekar jalari
el 17 de Ag. de 2011
Friedrich
el 17 de Ag. de 2011
The above link requieres a google mail account. You can use http://tinypic.com/ to upload pictures.
somasekar jalari
el 17 de Ag. de 2011
Jan
el 17 de Ag. de 2011
If your project is important (for you), take the time to post the link to the image here...
Which format does your picture have? A DOUBLE or UINT8 RGB array? A greyscale image?
Do you want to replace only exact black pixels with the value [0,0,0] or all very dark colors?
@native speakers: Is "please give me accurate answer" polite? Is it inpolite to give an inaccurate answer?
Image Analyst
el 17 de Ag. de 2011
I didn't take it as impolite. I took it as just typical, normal non-native wording like you often see from non-native speakers.
somasekar jalari
el 17 de Ag. de 2011
Jan
el 17 de Ag. de 2011
Please post more details by editing your original question: Does "binary image" mean a LOGICAL array? If you "detect some portion", in which format is this portion stored?
The more details, the more likely is a meaningful answer. Otherwise we waste time with guessing.
@Image Analyst: Thanks. Converting a message twice by non-native speakers with different mother-tongues leads to strange results, usually.
Walter Roberson
el 17 de Ag. de 2011
http://www.mathworks.com/matlabcentral/answers/7924-where-can-i-upload-images-and-files-for-use-on-matlab-answers
Respuesta aceptada
Más respuestas (4)
Jan
el 17 de Ag. de 2011
If you have an UINT8 RGB image and want to replace [0,0,0] pixels:
rgb = uint8(floor(rand(640, 480, 3) * 10));
isBlack = all(rgb == uint8(0), 3);
r = rgb(:, :, 1);
r(isBlack) = 1;
g = rgb(:, :, 2);
g(isBlack) = 0;
b = rgb(:, :, 3);
b(isBlack) = 0;
rgb2 = cat(3, r, g, b);
Daniel Shub
el 17 de Ag. de 2011
While there are faster and better ways ...
x = rand(100, 100, 3);
x(1:10, 1:10, :) = 0;
y = logical([100, 100]);
z = x;
for i = 1:100
for j = 1:100
y(i, j) = all(x(i, j, :) == [0, 0, 0]);
end
end
figure
image(x)
figure
image(z)
1 comentario
Jan
el 17 de Ag. de 2011
"all(x(i, j) == [0,0,0])" is not correct. This checks only the red channel of the 3D image array. I assume you want: "all(x(i, j, :) == [0,0,0])". But then a comparison with a scalar 0 is enough and faster. Vectorization is efficient here: replace the loops by: "all(x==0, 3)".
Image Analyst
el 17 de Ag. de 2011
0 votos
See my color segmentation demos: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862. With the proper method of segmentation you should be able to achieve the color replacement you want, regardless if the color is a single [r,g,b] triplet or a more spread out gamut.
Andrei Bobrov
el 17 de Ag. de 2011
rgb = uint8(rand(5,5,3)<.25)
rgb(rgb~=0) = uint8(randi([1 255],nnz(rgb),1))
bk = im2uint8(all(rgb==0,3))
rgb2 = rgb;
choose one from variants
% red
rgb2(:,:,1) = bk + rgb2(:,:,1)
% green
rgb2(:,:,2) = bk + rgb2(:,:,2)
% blue
rgb2(:,:,3) = bk + rgb2(:,:,3)
OR
rgb = +(rand(5,5,3)<.25)
rgb(rgb~=0) = rand(nnz(rgb),1)
bk = all(rgb==0,3)
rgb2 = rgb
rgb2(:,:,1) = rgb2(:,:,1)+bk
image(rgb2) % red
ADD MORE (about binary image)
d = +(rand(10)<.3) %binary image
d1 = d(:,:,[ 1 1 1])
d1(:,:,1)=ones(size(d)) % red
image(d1)
1 comentario
somasekar jalari
el 18 de Ag. de 2011
Categorías
Más información sobre Blue en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!