load file and saving in other format (image files)

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

采纳的回答

Image Analyst
Image Analyst 2014-7-22
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 个评论
aldif
aldif 2014-7-22
yes,it work all fine now,thx for your help,appreciated =D
Image Analyst
Image Analyst 2014-7-22
Misspellings/typos are common so you're not alone. You're welcome. Can you go ahead and mark my Answer as Accepted then?

请先登录,再进行评论。

更多回答(1 个)

Joseph Cheng
Joseph Cheng 2014-7-21
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 个评论
Joseph Cheng
Joseph Cheng 2014-7-21
编辑:Joseph Cheng 2014-7-21
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.
aldif
aldif 2014-7-22
tq ,i have tried and rework my code as this :
file = dir('C:\Users\doey\Documents\Sushi time ,Pv10');
file = file(~[file.isdir]); NF = length(file);
for k = 1 : NF
images = imread(fullfile('C:\Users\doey\Documents\Sushi time ,Pv10', file(k).name)); imwrite(image,fullfile('C:\Users\doey\Desktop\gg',[file(k).name(1:end-4),'.jpg']))
end
this works in saving my images into my file but when i trying to open it it showing blank,i have no idea for now ...

请先登录,再进行评论。

类别

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