MATLAB Answers

Image Processing B&W Picture Calculate Color Percentage

8 views (last 30 days)
Andar
Andar on 9 Sep 2019
Edited: Shunichi Kusano on 9 Sep 2019
I'm trying to do image processing on a B&W image.
I want to select a certain grayscale color and find out the perfectage of pixels that are lighter than that value.
Any starting points or code to help would be greatly appreciated. Thanks!

  0 Comments

Sign in to comment.

Answers (1)

Shunichi Kusano
Shunichi Kusano on 9 Sep 2019
Edited: Shunichi Kusano on 9 Sep 2019
Hi Andar, this is the sample code.
img = imread('cameraman.tif');
imshow(img);
th = 100; % threshold to select brighter pixels
totalPixelNumber = numel(img);
%% method 1: making binary image
bw1 = img > th;
imshow(bw1)
nnz(bw1) / totalPixelNumber * 100% percentage
%% method2: finding brighter pixels directly
pixels = find(img > th);
length(pixels) / totalPixelNumber * 100% percentage
hope this helps.

  0 Comments

Sign in to comment.

Sign in to answer this question.


Translated by