Borrar filtros
Borrar filtros

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 visualización (últimos 30 días)
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 comentarios
Thomas
Thomas el 14 de Jun. de 2013
Editada: Thomas el 15 de Jun. de 2013
I was asking how to convert the code so that it does not need to actually write to disk.
Image Analyst
Image Analyst el 15 de Jun. de 2013
I don't believe there is a function to generate the jpeg artifacts other than by calling imwrite followed by imread.

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 14 de Jun. de 2013
Editada: Walter Roberson el 14 de Jun. de 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.

Categorías

Más información sobre Convert Image Type en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by