Azzera filtri
Azzera filtri

Error using imwrite in the following code

5 visualizzazioni (ultimi 30 giorni)
MUHAMMAD ALKHUDAYDI
MUHAMMAD ALKHUDAYDI il 24 Ott 2019
Risposto: Guillaume il 24 Ott 2019
I have the following code :
Height=5; width=5;
currentimage = imread('peppers.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]);
outDirectory = fullfile('/Users','m','Download','P1')
imwrite(Image,outDirectory,num2str(count),'png');
end
end
end
It is used to divide an image of m*n*3 to equal parts of images of size 5*5 and I want to save them in outDirectory. I recive the following error:
Error using imwrite (line 448)
Unable to determine the file format from the file name.
Error in cropping (line 12)
imwrite(Image,outDirectory,num2str(count),'png');
Can someone help me to sort that and explaind what is causing the error.
Many thanks and I appricate your help

Risposte (1)

Guillaume
Guillaume il 24 Ott 2019
Yes, the documentation of imwrite doesn't say that you can path as input a folder and a filename. That's because you can't.
imwrite(Image, fullfile(outDirectory, num2str(count)), 'png'); %use fullfile to combine folder and filename

Categorie

Scopri di più su Convert Image Type in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by