imwrite saving image file without extension even after specifying the extension.

8 visualizaciones (últimos 30 días)
original= iin;
for hsize=3:2:9
for sigma=0.5:0.5:2
close all;
file1 =sprintf('Intern_log_plot%d_hsize=%d_sigma=%.1f',n,hsize,sigma);
file2 =sprintf('Intern_log%d_hsize=%d_sigma=%2f',n,hsize,sigma);
s1=sprintf('%s%s%s%d%s%s',image_folder,l,filenames(n).name,n,l,file1);
s2=sprintf('%s%s%s%d%s%s',image_folder,l,filenames(n).name,n,l,file2);
h=fspecial('log',hsize,sigma);
pic=imfilter(original,h);
figure;
subplot(2,2,1);
imshow(original);title('Raw Image');
subplot(2,2,2);
imshow(pic);title('Output');
colormap('default');
h=gcf;
saveas(h,s1,'jpg');
imwrite(pic,s2,'jpg');
The imwrite function writes the file to the disk as files without any extension(so the image file is not detected by image viewer softwares), with the format being already specified as 'jpg' in the imwrite function.

Respuesta aceptada

Michael Haderlein
Michael Haderlein el 31 de Jul. de 2014
The file extension will not be added if you already provide a file extension in the filename. As you have dots (.) in your filename, everything after the dot will be seen as a file extension. If you add the file extension in your filename (you can add .jpg in your sprintf formats), it will work.
  5 comentarios
YADHUKRISHNAN
YADHUKRISHNAN el 31 de Jul. de 2014
I need not specify the extension in saveas and imwrite functions. Right?

Iniciar sesión para comentar.

Más respuestas (1)

YADHUKRISHNAN
YADHUKRISHNAN el 31 de Jul. de 2014
But the filename does not have an extension specified along with that. I can't add .jpg in sprintf because my filename is dynamic, it changes in each loop and for each images so that I have saved the filename as string

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by