How to sum pixels from each sliding window in a picture?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have a picture and a sliding window on it. Sliding window is moving and ectracts the number of pixels relevant to setpoint rgb intervals. But I need the whole sum from the picture. How to calculate that ?
3 Commenti
Guillaume
il 11 Dic 2018
Do the sliding windows overlap?
What is the number of pixels relevant to setpoint rgb intervals?
Risposte (1)
Guillaume
il 11 Dic 2018
There are many ways you can apply the sliding window. For contiguous, non-overlapping blocks you can use blockproc. If the blocks overlap you can use nlfilter or colfilt, or even simpler since your operation is simply a sum conv2. In any, case before any of these, you can first calculate your A and B per pixel:
rgbAlower = uint8(cat(3, 45, 50, 160)); %lower thresholds stored across pages
rgbAupper = uint8(cat(3, 180, 185, 215)); %upper thresholds stored across pages
A = all(yourimage > rgbAlower & yourimage < rgbAupper, 3); %is pixel within threshold. Requires R2016b or later
Applying blockproc to that is trivial
result = blockproc(A, [64 64], @(bloc) sum(bloc.data(:))) %with suitable options for what you want to do at the edges
or with a convolution
fullconv = conv2(A, ones(64, 64), 'valid'); %window of 64x64 with step of 1
result = fullconv(1:64:end, 1:64:end) %extract blocks with step of 64
2 Commenti
Guillaume
il 12 Dic 2018
I have no idea what a slide is. In any case, it should be trivial to adapt the code to your requirements, whatever these are.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!