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
Best Answer