Prev: Efficient Frontier Weights
Next: Separatrix Curve
From: fatema on 8 May 2010 01:20 I want to change the background of my image which ir green to black, I tried the following code, it makes other parts which theyare not green as black, any help please: img=imread('fish.jpg'); [x y z]=size(img) for i=1:1:(x-1) for j=1:1:(y-1) if (img(i,j,3)>=150) img(i,j,:)=0; end end end imshow(img);
From: Walter Roberson on 8 May 2010 12:58 fatema wrote: > I want to change the background of my image which ir green to black, I > tried the following code, it makes other parts which theyare not green > as black, any help please: > img=imread('fish.jpg'); > [x y z]=size(img) > for i=1:1:(x-1) > for j=1:1:(y-1) > if (img(i,j,3)>=150) > img(i,j,:)=0; > end > end > end > imshow(img); There are a lot of colors which have a green component more than 150, and yet would not be considered to have a hue that was green. Likewise, if a particular color happens to have very low red and blue components, it may be recognizably green even if the green portion is not above 150. If I recall correctly, John D'Errico has a Matlab File Exchange contribution for Fuzzy Color Matching.
From: ImageAnalyst on 8 May 2010 15:44 Take a look at my demo that finds "red" pixels: http://www.mathworks.com/matlabcentral/fileexchange/26420-simplecolordetection You can easily adapt it to find pixels in the "green" range or whatever color range you're interested in. Then simply use masking to set the green pixels to black: rgbImage(:,:,1) = rgbImage(:,:,1) .* uint8(greenMask(:,:)); rgbImage(:,:,2) = rgbImage(:,:,2) .* uint8(greenMask(:,:)); rgbImage(:,:,3) = rgbImage(:,:,3) .* uint8(greenMask(:,:)); or something like that (e.g. logical indexing).
|
Pages: 1 Prev: Efficient Frontier Weights Next: Separatrix Curve |