Filter löschen
Filter löschen

Error using imwrite in the following code

5 Ansichten (letzte 30 Tage)
MUHAMMAD ALKHUDAYDI
MUHAMMAD ALKHUDAYDI am 24 Okt. 2019
Beantwortet: Guillaume am 24 Okt. 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

Antworten (1)

Guillaume
Guillaume am 24 Okt. 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

Kategorien

Mehr zu Convert Image Type finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by