Count the number of items that exceed a threshold

2 views (last 30 days)
Alber
Alber on 26 May 2020
Commented: Alber on 26 May 2020
Hello, I want to create a variable called 'proportion' which is defined as the number of pixels that exceed the threshold, of the blue color. This new variable depends on the pixels of the initial and final image. My code is as follows:
function [cond,SIR] = canWeEncode(frameBuffer,alpha,threshold)
imgInicial = frameBuffer(:,:,:,1);
imgFinal = frameBuffer(:,:,:,end);
imgdiff = imgFinal - imgInicial;
I = mean(imgdiff.^2,'all');
proportion = ; % Problem in question
S = 4*(alpha^2)*proportion;
SIR = 10*log10(S/I);
cond = SIR >= threshold;
end
The conclusion is that 'proportion' has to count the number of pixels of the final and initial images that exceed the 'threshold' (located at 0 dB) in the blue color.
I have made an approach that I think may be the solution, but I'm not sure:
condition_A = imgInicial(:,:,3)>=threshold;
condition_B = imgFinal(:,:,3)>=threshold;
proportion = numel(condition_A)+numel(condition_B);
  2 Comments
Johannes Hougaard
Johannes Hougaard on 26 May 2020
I think you just need to substitute numel with sum as the number of elements in you logical remains the same regardless of the value of the logical.
condition_A = imgInicial(:,:,3)>=threshold;
condition_B = imgFinal(:,:,3)>=threshold;
proportion = numel(condition_A)+numel(condition_B); %This is constant regardless of the values in condition_A and condition_B
proportion = sum(condition_A)+sum(condition_B);
Alber
Alber on 26 May 2020
Yes, I think it makes more sense. Thank you

Sign in to comment.

Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!