how to break an image into sub images

12 visualizzazioni (ultimi 30 giorni)
Rao
Rao il 4 Set 2012
Commentato: Walter Roberson il 19 Ott 2021
i have an image having pixels 512*512 . i want to break it in equal sub images (for eg like into images of 8*8) and want to apply a function (can be any) on each sub image ??

Risposte (3)

José-Luis
José-Luis il 4 Set 2012

Zainab Ishfaq
Zainab Ishfaq il 29 Mag 2018
Modificato: Walter Roberson il 13 Feb 2020
Height=8; width=8;
currentimage = imread('Image.png');
[r,c,~]=size( currentimage );
count=0;
for i=0:Height:r
count=count+1;
for j=0:width:c
if((i+Height)<r && (j+width)<c)
Image=imcrop( currentimage ,[(i+1) (j+1) Height width]);
imwrite(Image,horzcat(currentfilename, num2str(count),'.tif'));
end
end
end
  9 Commenti
shital shinde
shital shinde il 21 Feb 2020
Modificato: shital shinde il 21 Feb 2020
Thanks sir. It work now. I have one question. Can we parallelize the above example using parallel computing toolbox.
Walter Roberson
Walter Roberson il 21 Feb 2020
Modificato: Walter Roberson il 21 Feb 2020
Yes. Just change for i to parfor i
As we have advised you before, the result will almost certainly be notably slower than your current code. But I know from your previous questions that you feel inclined to do that testing yourself.

Accedi per commentare.


image-pro
image-pro il 19 Ott 2021
i have an error please help
Error in p8 (line 11)
Image=imcrop(currentimage ,[(i+1) (j+1) Height width]);

Categorie

Scopri di più su Image Processing Toolbox in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by