问题
Is there a MATLAB function that does the following:
For an image input, it tells me what proportion of the bits are darker than a particular color of my choosing.
So if I entered an image of a chess board and used the color gray, the output would be roughly one half. (the image I need to process in this way is not that simple, though)
回答1:
function CompareMap = BitWiseCompare('filename',c) % c = [R , G , B];
A = imread('filename');
CompareMap = zeros([size(A,1),size(A,2)]);
CompareMap = (A(:,:,1) < c(1)).*(A(:,:,2) < c(2)).*(A(:,:,3) < c(3));
end
for example,
with CompareMap = BitWiseCompare('filename',[220 100 120]);
gives,
and CompareMap = BitWiseCompare('filename',[220 130 150]);
来源:https://stackoverflow.com/questions/26617221/bitwise-color-filter-in-matlab