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?
Ältere Kommentare anzeigen
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 Kommentare
Friedrich
am 17 Aug. 2011
I can't access the image. Please upload it somewhere else.
somasekar jalari
am 17 Aug. 2011
Friedrich
am 17 Aug. 2011
The above link requieres a google mail account. You can use http://tinypic.com/ to upload pictures.
somasekar jalari
am 17 Aug. 2011
Jan
am 17 Aug. 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
am 17 Aug. 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
am 17 Aug. 2011
Jan
am 17 Aug. 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
am 17 Aug. 2011
http://www.mathworks.com/matlabcentral/answers/7924-where-can-i-upload-images-and-files-for-use-on-matlab-answers
Akzeptierte Antwort
Weitere Antworten (4)
Jan
am 17 Aug. 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
am 17 Aug. 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 Kommentar
Jan
am 17 Aug. 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
am 17 Aug. 2011
0 Stimmen
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
am 17 Aug. 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 Kommentar
somasekar jalari
am 18 Aug. 2011
Kategorien
Mehr zu Red finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!