how to set the dpi while using 'imwrite' to save a matrix into an image of 'jpg' format?
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Li Shenguang
el 13 de Mayo de 2012
Comentada: David Young
el 12 de Jul. de 2023
A is a matrix of 1000*1000*3
I want to export A as a 'jpg' image with dpi=240
imwrite(A,'filename.jpg');
the default dpi value is 96, how to change it into 240?
0 comentarios
Respuesta aceptada
Image Analyst
el 13 de Mayo de 2012
That is not one of the parameters that you can set with MATLAB's imwrite() function.
4 comentarios
David Young
el 11 de Jul. de 2023
It seems silly that you can't set the resolution parameter for jpegs when you can for tiffs. It surely would be the work of moments to put it into the imwrite code - it's just a number to go into the file header.
Más respuestas (1)
DGM
el 11 de Jul. de 2023
You use external tools. If you have exiftool, use that.
% take a clean image
inpict = imread('peppers.png');
% write it to a degraded 4:2:0 JPG at 75% quality
fname = 'crustBelongsOnPies.jpg';
imwrite(inpict,fname)
% set x and y resolution tags and units using external tools
resolution = 240;
comstr = sprintf(['exiftool %s '...
'-xresolution=%d '...
'-yresolution=%d '...
'-resolutionunit=inches -v2'],...
fname,resolution,resolution)
system(comstr,'-echo')
% inspect to see that the tags have been set
imfinfo(fname)
1 comentario
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!