how to break an image into sub images

16 vues (au cours des 30 derniers jours)
Rao
Rao le 4 Sep 2012
Commenté : Walter Roberson le 19 Oct 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 ??

Réponses (3)

José-Luis
José-Luis le 4 Sep 2012

Zainab Ishfaq
Zainab Ishfaq le 29 Mai 2018
Modifié(e) : Walter Roberson le 13 Fév 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 commentaires
shital shinde
shital shinde le 21 Fév 2020
Modifié(e) : shital shinde le 21 Fév 2020
Thanks sir. It work now. I have one question. Can we parallelize the above example using parallel computing toolbox.
Walter Roberson
Walter Roberson le 21 Fév 2020
Modifié(e) : Walter Roberson le 21 Fév 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.

Connectez-vous pour commenter.


image-pro
image-pro le 19 Oct 2021
i have an error please help
Error in p8 (line 11)
Image=imcrop(currentimage ,[(i+1) (j+1) Height width]);
  1 commentaire
Walter Roberson
Walter Roberson le 19 Oct 2021
what is the error message?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Image Processing Toolbox 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!

Translated by