Count the number of items that exceed a threshold
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Johannes Hougaard
2020-5-26
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);
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!