how to set the dpi while using 'imwrite' to save a matrix into an image of 'jpg' format?

9 次查看(过去 30 天)
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?

采纳的回答

Image Analyst
Image Analyst 2012-5-13
That is not one of the parameters that you can set with MATLAB's imwrite() function.
  4 个评论
David Young
David Young 2023-7-11
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.

请先登录,再进行评论。

更多回答(1 个)

DGM
DGM 2023-7-11
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)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by