Search code examples
matlabimage-processingimage-editingimage-effects

Bitwise color filter in MATLAB


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)


Solution

  • 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,

    enter image description here

    with CompareMap = BitWiseCompare('filename',[220 100 120]); gives,

    enter image description here

    and CompareMap = BitWiseCompare('filename',[220 130 150]);

    enter image description here