MATLAB: Black and white image

blackgraygrayscaleimage processingrgbwhite

Hello every one, i want to ask two similar things
1.If image is pure black and white matlab should tell me that image is pure black & white and if grayscale it should tell that its grayscale.
2.in my grayscale image if some pure black or white part come it should save it an array and other gray scale values should be saved in another array. i am attaching a black& white image for reference. Thanks

Best Answer

Try this
[counts, grayLevels] = imhist(grayImage, 256);
if sum(counts(2:end-1)) > 0
% It's not pure black and white
end
% Get map of non-0 and non-255 pixels
grayPixels = grayImage > 0 & grayImage < 255;
% Get pure black and white image
bw = grayImage; % Initialize

bw(grayPixels) = 0; % Zero out any gray pixels.
% Get gray pixels only
grayOnly = grayImage; % Initialize
grayOnly(~grayPixels) = 0; % Zero out any pure 0 or pure 255 pixels.
Related Question