creating sliding windows for own purpose(do not want to calculate std or mean or any of that stuff)
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Kasra Sadatsharifi
il 1 Giu 2020
Commentato: Kasra Sadatsharifi
il 2 Giu 2020
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 Commenti
Risposta accettata
Image Analyst
il 2 Giu 2020
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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su 3-D Volumetric Image Processing in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!