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 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