load file and saving in other format (image files)

2 ビュー (過去 30 日間)
aldif
aldif 2014 年 7 月 21 日
コメント済み: Image Analyst 2014 年 7 月 22 日
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 Center および File ExchangeConvert Image Type についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by