how to masked RGB Image
9 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
更多回答(2 个)
Asep Muhammad Taufik
2015-4-20
编辑:Asep Muhammad Taufik
2015-4-20
2 个评论
Image Analyst
2015-4-20
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!