필터 지우기
필터 지우기

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
Thomas
Thomas 2013년 6월 14일
편집: Thomas 2013년 6월 15일
I was asking how to convert the code so that it does not need to actually write to disk.
Image Analyst
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
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.

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by