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 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Image Analyst
am 15 Jun. 2013
I don't believe there is a function to generate the jpeg artifacts other than by calling imwrite followed by imread.
Antworten (1)
Walter Roberson
am 14 Jun. 2013
Bearbeitet: Walter Roberson
am 14 Jun. 2013
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 Kommentare
Siehe auch
Kategorien
Mehr zu Convert Image Type finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!