creating sliding windows for own purpose(do not want to calculate std or mean or any of that stuff)

조회 수: 4 (최근 30일)
Hi
I want to creat a non overlapping sliding window over a padded image which contains grayscale pixels. I need to create sliding windows over the padded image and then find the mode(majority) pixel values in that sliding window. my code so far looks like this. the problem with it is that it is overlapping and it starts from the first pixel of the padded image which should be starting from the first pixel of the original image. I came across a function named blockproc which seems promising. however i'm not sure how to use it to define my function. I'm still working on this code so there might be bugs so I would appreciate it if you could tell me if you see one. any help is appreciated.
function k = dynamic_k (image,nhood,mean,imageD)% mean is the mean of the pixels in the window
[rows, columns] = size(image); % size of the original image
% Always use double because uint8 would be too small.
imageD = double(imagePP); % this is the padded image
m = nhood(1);% nhood is the neighboring window
n = nhood(2);
h = (m-1)/2;
v = (n-1)/2;
for i = 1:rows
for j = 1:columns
a = imageD(i-h:i+h,j-v:j+v);
majority = mode(a,'all');
if majority > mean
k = -0.2;
elseif majority < mean
k = 0.2;
else
k = 0;
end
end
end

채택된 답변

Image Analyst
Image Analyst 2020년 6월 2일
There is a function that does this in the Image Processing Toolbox. It is called blockproc(). You can define your overlap (if any) and custom function to apply (like mode). See attached demos.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 3-D Volumetric Image Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by