How do I divide an image into possible number of blocks and apply a set of functions to each block?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Here is a sample image.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/171906/image.jpeg)
1 Kommentar
Antworten (2)
vahid rowghanian
am 4 Apr. 2021
Bearbeitet: vahid rowghanian
am 10 Jun. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Polygons finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!