MATLAB: How to masked RGB Image

digital image processingimage analysisimage processingImage Processing Toolboximage segmentation

Hi there…
is there anyone can help? I've tried to do a masked to a certain image based on the histogram of RGB color intensity. for example, I try to do the masking of the Red color (150 <R <190), Green (140 <G <185) and Blue (140 <R <193).
I got this intensity number from the highway image histogram where I want to perform filtering based on the intensity of the masking for the RGB histogram.
This is the script that I've tried, but it did not work for me..
thank you,
-asep-
% script———————————————————–
I = imread('highway.tif');
J = rgb2gray(I);
figure, imshow(J);
figure, imhist(J);
R=imhist(I(:,:,1));
G=imhist(I(:,:,2));
B=imhist(I(:,:,3));
figure, imshow(I);
figure, plot(R,'r')
hold on, plot(G,'g') plot(B,'b'), legend(' Red channel','Green channel','Blue channel'); hold off,
%——————————————
binaryRed = R > 150; % i dont know how to make a function for this intensity
binaryGreen = G > 140;
binaryBlue = B > 140;
% Find where all exceed threshold.
mask = binaryRed & binaryGreen & binaryBlue;
% Mask image to be black there.
maskedRgbImage = bsxfun(@times, I, cast(mask,class(I)));
imshow(maskedRgbImage);

Best Answer

See my SimpleColorDetection application in my File Exchange.