Filter löschen
Filter löschen

How to sum pixels from each sliding window in a picture?

4 Ansichten (letzte 30 Tage)
Aneta Chwala
Aneta Chwala am 11 Dez. 2018
Kommentiert: Guillaume am 12 Dez. 2018
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 Kommentare
Guillaume
Guillaume am 11 Dez. 2018
Do the sliding windows overlap?
What is the number of pixels relevant to setpoint rgb intervals?
Aneta Chwala
Aneta Chwala am 11 Dez. 2018
my picture size: 3133x2375x3 uint8
sliding window size: 64x64 with step 64
The sliding picture moves starting with left up corner and ending at right down corner.
I have two variables A and B which are numbers of pixels for rgb intervals for A it's: (R > 45 & R < 180), (G > 50 & G < 185), (B > 160 & B < 215), and for B: (R > 40 & R < 115), (G > 6 & G < 80), (B > 10 & B < 75).
I need a sum of A and B from every slide (which is from the whole picture).

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Guillaume
Guillaume am 11 Dez. 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 Kommentare
Aneta Chwala
Aneta Chwala am 11 Dez. 2018
Thanks! Actually I have a sliding window which counts the pixels for one slide. I need to sum pixels from all slides.
Guillaume
Guillaume am 12 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by