How do i threshold a green channel of an RGB image using average and standard deviation of the image.

2 views (last 30 days)
I want to threshold green channel of an RGB image, i have the average, standard deviation, and variance of the RGB component both the foreground and the background, how do i do this?

Answers (1)

Image Analyst
Image Analyst on 17 Mar 2013
If you already have "both the foreground and the background", as you said, then you must have thresholded it already or else come up with some way of specifying what is foreground and what is background. But you can threshold it again to find different foreground and background:
thresholdValue = some function of average & std dev in the first foreground & background.
% Get new foreground based on values determined from first pass
% at guessing what the foreground and background were.
binaryImage = greenChannel > thresholdValue; % Or can use <, <=, or >=
  2 Comments
ELIJAH JOSEPH
ELIJAH JOSEPH on 17 Mar 2013
Edited: Image Analyst on 18 Mar 2013
Thank you for your answer it has been helpful, this is the code i wrote, please help do a check on the code, if it is okay.
clc
E = imread('Kate.jpg');
M= E (:,:,1);
J= E(:,:,2);
K=E(:,:,3);
subplot (3,4,1);
imshow(E);
subplot(3, 4, 2);
imshow(M)
subplot(3, 4, 3);
imshow(J)
subplot(3, 4, 4);
imshow(K)
L=J>=115.6709677
subplot(3, 4, 5);
imshow (L)
Image Analyst
Image Analyst on 18 Mar 2013
It's okay except for the lack of comments and variable names that are not descriptive. Please add comments and give your variables names that describe what they are.

Sign in to comment.

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!