Azzera filtri
Azzera filtri

Count the number of items that exceed a threshold

1 visualizzazione (ultimi 30 giorni)
Alber
Alber il 26 Mag 2020
Commentato: Alber il 26 Mag 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 Commenti
Johannes Hougaard
Johannes Hougaard il 26 Mag 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 il 26 Mag 2020
Yes, I think it makes more sense. Thank you

Accedi per commentare.

Risposte (0)

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by