Unexpected behaviour by imread and imwrite

workingDir = 'frames';
filename = [sprintf('%d',1) '.jpg'];
fullname = fullfile(workingDir,'imagesV',filename);
a2=imread(fullname);
a2(1,1)=1;
imwrite(a2,fullname);
a1=imread(fullname);
if a1==a2
disp(23)
else
disp(45)
end
The code above displays 45 instead of 23. What is the reason for this?

 Respuesta aceptada

Rik
Rik el 30 de Mzo. de 2018

0 votos

JPEG is not a lossless compression algorithm. This means that re-writing a loaded image might (and generally will) result in a different image. Another reason in your case would be that you changed a pixel value.
(side note: technically there are versions of JPEG that do support lossless compression, but the support is very limited)

2 comentarios

Walter Roberson
Walter Roberson el 30 de Mzo. de 2018
Yup.
You should only use the original JPEG for display purposes, not for data archive, because JPEG lossy mode will blur all straight lines, similar in effect to anti-aliasing.
Walter Roberson
Walter Roberson el 31 de Mzo. de 2018
Avoid JPEG, JPEG2000, and (I suppose) GIF. The other formats do not lose information.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Images en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 30 de Mzo. de 2018

Comentada:

el 31 de Mzo. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by