How to save save split images in multiple filenames?

I have a code which shows the multiple images of a scanned *.tif document.
for i=1:5
d=imshow(imread('gi2.tif',i));
figure;
end
I need to save these images as multiple files. I used the following code for that:
basename='im_'
for i=1:5
d=imshow(imread('gi2.tif',i));
figure;
filename=[basename,num2str(i)];
end
But the code is just creating a variable filename with data im_5. I also tried using "sprintf" using the following code:
for i=1:5
d=imread('gi2.tif',i));
filename=sprintf('im_%d.jpg',i)
end
But this basically prints the filename im_<no.> and nothing else.
Please support!!

 Réponse acceptée

That solves your problem?
for i=1:5
imwrite(imread('gi2.tif',i),['im_' num2str(i) '.tif']);
end

1 commentaire

Thank you very much. Issue Resolved. Thanks for the quick support!! :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Printing and Saving dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by