Error using imwrite in the following code

4 views (last 30 days)
MUHAMMAD ALKHUDAYDI
MUHAMMAD ALKHUDAYDI on 24 Oct 2019
Answered: Guillaume on 24 Oct 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

Answers (1)

Guillaume
Guillaume on 24 Oct 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

Categories

Find more on Convert Image Type in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!