How do I divide an image into possible number of blocks and apply a set of functions to each block?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Here is a sample image.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/171906/image.jpeg)
1 commentaire
Réponses (2)
vahid rowghanian
le 4 Avr 2021
Modifié(e) : vahid rowghanian
le 10 Juin 2021
If you want to divide the image into squares of size gs ( e.g. 2,3,4,5,6,7,8,9,10,…), you can use the following code. This function extracts gs by gs patches from the input image and stores them into 'patch' variable.
function [ patchim , npatchim ] = divideimage (im , gs)
m = size(im,1);
n = size(im,2);
if mod(m,gs)>0
m = m - mod(m,gs) + gs;
end
if mod(n,gs)>0
n = n - mod(n,gs) + gs;
end
k1 = m / gs;
k2 = n / gs;
npatch = 1;
patch = zeros(gs,gs,3,k1*k2);% for 3-D images
im = imresize(im,[m,n]);
for i = 1 : k1
for j = 1 : k2
rmin = ( i - 1 ) * gs + 1;
rmax = i * gs;
cmin = ( j - 1) * gs + 1;
cmax = j * gs;
%%%%% do processes
patch ( : , : , : , npatch) = im( rmin : rmax , cmin : cmax , : );
npatch = npatch + 1;
end
end
npatchim = npatch - 1;
patchim = patch;
end
0 commentaires
Voir également
Catégories
En savoir plus sur Polygons dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!