how to masked RGB Image
8 views (last 30 days)
Show older comments
Asep Muhammad Taufik
on 31 Mar 2015
Commented: Asep Muhammad Taufik
on 23 Apr 2015
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);
0 Comments
Accepted Answer
More Answers (2)
Asep Muhammad Taufik
on 20 Apr 2015
Edited: Asep Muhammad Taufik
on 20 Apr 2015
2 Comments
Image Analyst
on 20 Apr 2015
Your image didn't come through. Anyway, start at the mode, which you can find from mode() or max() functions. Then start marching down the left side of the histogram with a for or while loop until it turns around.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!