How do I encode a jpg to a set quality level in order to calculate it's ela without first writing it to a temp file?
1 次查看(过去 30 天)
显示 更早的评论
I have tried looking at using a encoder some exist in the File Exchange, but are not written to allow adjustable quality levels or are faithful adaptation of the original jpeg encoder!
I'm now using a virtual ram disk to hold the temp file, which is then deleted!
function [] = generate_ela(filename,quality)
if nargin > 2 | nargin < 2
error('usage: generate_ela(filename,quality)');
end;
img_orig = imread(filename);
tempfile = 'z:\temp.jpg';
imwrite(img_orig,tempfile,'jpeg','Quality',quality);
temp = imread(tempfile);
delete(tempfile);
idiff = uint8(abs(double(img_orig)-double(temp))*30);
me = max(max(max(idiff)));
idiff = uint8(double(idiff)*255/double(me));
%imwrite(idiff,'ela.jpg');
figure; imshow(idiff);
end
3 个评论
Image Analyst
2013-6-15
I don't believe there is a function to generate the jpeg artifacts other than by calling imwrite followed by imread.
回答(1 个)
Walter Roberson
2013-6-14
编辑:Walter Roberson
2013-6-14
Writing to file is by far the easiest method. If you had a RAMDISK or solid state drive then the writing (and reading) would be quite fast.
Otherwise...
Have a look at this which shows how to do JPEG compression in Java. There is a point where the code creates an output stream associated with a disk file. I suspect that it is potentially possible to create an output stream into memory instead of into a file. Or you could probably connect the output stream from the compressor as the input stream to the decompresser. I have not worked with Java more than a little, so I am not certain that these can be done.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Import, Export, and Conversion 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!