load file and saving in other format (image files)
3 views (last 30 days)
Show older comments
I currently trying to write a code to load my image from a directory and loop each each of them in Matlab then i need to save my image files into another folder and save into another format for example png,jpg...here is the code for me to load the images file from my directory ,but I facing the problem when I trying to save the images into another format ...anyone can tell me where is my problem because I am new on this
file = dir('C:\Users\doey\Documents\Sushi time ,Pv10'); file = file(~[file.isdir]); NF = length(file); images = cell(NF,1); for k = 1 : NF disp(file(k).name); images{k} = imread(fullfile('C:\Users\doey\Documents\Sushi time ,Pv10', file(k).name)); end savesas(file(k),'C:\Users\doey\Desktop\gg','png');
0 Comments
Accepted Answer
Image Analyst
on 22 Jul 2014
Like I said in my answer to your duplicate question, use "images" in imwrite(), not "image" . image is the name of a built in function. When you call image, you just get a handle id - a single number which is floating point. It's more than one, so you're essentially saving a single white pixel. Use "images" not "image".
2 Comments
Image Analyst
on 22 Jul 2014
Misspellings/typos are common so you're not alone. You're welcome. Can you go ahead and mark my Answer as Accepted then?
More Answers (1)
Joseph Cheng
on 21 Jul 2014
I would use imwrite(). I am not familiar with savesas() perhaps you're using saveas()?
with imwrite you can set what type of image format you want to use. Also perhaps reading and writing within the forloop would be more efficient as you're not using more memory by opening all images. That way you'll only use what you actually need (if you're not using the image data otherwise).
3 Comments
Joseph Cheng
on 21 Jul 2014
Edited: Joseph Cheng
on 21 Jul 2014
like i said in my answer you can do the writing inside the for loop
for k=1:NF
image = imread()
imwrite(image,fullfile('whatever path you want',[file(k).name(1:end-4)'.png'])) %add more parameters if you need to. and change for extension.
end
Check the documentation on imwrite for full listing of parameters and examples of how to use.
See Also
Categories
Find more on Convert Image Type 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!