필터 지우기
필터 지우기

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

조회 수: 4 (최근 30일)
Aneta Chwala
Aneta Chwala 2018년 12월 11일
댓글: Guillaume 2018년 12월 12일
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
Guillaume
Guillaume 2018년 12월 11일
Do the sliding windows overlap?
What is the number of pixels relevant to setpoint rgb intervals?
Aneta Chwala
Aneta Chwala 2018년 12월 11일
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).

댓글을 달려면 로그인하십시오.

답변 (1개)

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

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by