Error using imwrite in the following code
1 view (last 30 days)
Show older comments
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
0 Comments
Answers (1)
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
0 Comments
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!