Count the number of items that exceed a threshold
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Johannes Hougaard
am 26 Mai 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);
Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!