Difference between jpg files from Matlab and ImageMagick
4 ビュー (過去 30 日間)
古いコメントを表示
Hi all,
I have a pgm file that I convert to jpg via matlab. To this end I use imread to read the file and imwrite to write it again. Inbetween I adjust the compression ratio by using the quality parameter. Finally I compute the error caused by the compression and compare it to the compression ratio.
If I do the same with Image Magick, I get significantly better results. For a given quality value, the resulting images look very similar (errors are roughly the same) but sometimes Graphics Magick achieves half the file size of Matlab.
Does anybody have an explanation for this? I was assuming that specifying the same quality level yields similar results independent of the software that I use for the conversion.
1 件のコメント
Geoff Hayes
2014 年 10 月 15 日
Laurent - what is the line of code that you are using in MATLAB to adjust the compression ratio?
回答 (1 件)
DGM
2024 年 9 月 22 日
I'm not familiar with whatever differences might be in the encoders, but there's one obvious thing that should be pointed out. MATLAB imwrite() always creates a 4:2:0 downsampled JPG, no matter what the -quality setting is. By default, imagemagick will adapt the downsampling to suit the specified quality parameter. That will definitely change the measured error and apparent compression ratio.
Assuming you have imagemagick and exiftool installed:
% inputs
inpict = imread('peppers.png'); % a clean file
q = 90; % quality parameter
% create the temp files
imwrite(inpict,'temp.png')
imwrite(inpict,'outml.jpg','quality',q)
cmdstr = sprintf('convert temp.png -quality %d outim.jpg',q);
system(cmdstr);
% imwrite() always produces a 4:2:0 JPG no matter what
fprintf('FileSize: %d\n',imfinfo('outml.jpg').FileSize)
[~,r] = system('exiftool -YCbCrSubSampling outml.jpg');
r = regexp(r,'YCbCr\d:\d:\d','match');
fprintf('SubSampling: %s\n',r{:})
FileSize: 41327
SubSampling: YCbCr4:2:0
% imagemagick will use 4:4:4 for 90% and up
% unless this default behavior is explicitly overridden
fprintf('FileSize: %d\n',imfinfo('outim.jpg').FileSize)
[~,r] = system('exiftool -YCbCrSubSampling outim.jpg');
r = regexp(r,'YCbCr\d:\d:\d','match');
fprintf('SubSampling: %s\n',r{:})
FileSize: 55541
SubSampling: YCbCr4:4:4
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Image Segmentation and Analysis についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!