Problem with reading and writing an image
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
fiona rozario
el 18 de Mzo. de 2017
Comentada: fiona rozario
el 18 de Mzo. de 2017
I have two programs - one to encrypt and the other to decrypt an image.
At the end of the encryption, I am concatenating RGB matrices and writing it into a file.
encrimage=uint8(cat(3,ered,egreen,eblue));
imwrite(encrimage,'eimage.jpeg');
In the decryption program, when I read the file eimage.jpeg I expect to get the same values as in 'encrimage'. But the values are changed. Why is this happening? Does imwrite change to some other datatype?
0 comentarios
Respuesta aceptada
Walter Roberson
el 18 de Mzo. de 2017
imwrite(encrimage,'eimage.jpeg', 'mode', 'lossless');
However, as soon as someone does not notice that it needs to be a lossless JPEG and "helpfully" re-saves it, your program would fail again.
Lesson: Don't use JPEG for storing data.
If you are required to use JPEG for storing data then you need to do the DCT yourself, work with the values obtained, make whatever changes, and do an inverse DCT on that -- so that when you imwrite() the file, the DCT that it does automatically will end up with the data you want to store.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!