Error using imwrite in the following code

4 次查看(过去 30 天)
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

回答(1 个)

Guillaume
Guillaume 2019-10-24
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

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by