load file and saving in other format (image files)

2 visualizaciones (últimos 30 días)
aldif
aldif el 21 de Jul. de 2014
Comentada: Image Analyst el 22 de Jul. de 2014
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');

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (1)

Joseph Cheng
Joseph Cheng el 21 de Jul. de 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 comentarios
Joseph Cheng
Joseph Cheng el 21 de Jul. de 2014
Editada: Joseph Cheng el 21 de Jul. de 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.
aldif
aldif el 22 de Jul. de 2014
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 ...

Iniciar sesión para comentar.

Categorías

Más información sobre Convert Image Type en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by