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
0 个评论
采纳的回答
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 Center 和 File 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!