필터 지우기
필터 지우기

Problem with reading and writing an image

조회 수: 1 (최근 30일)
fiona rozario
fiona rozario 2017년 3월 18일
댓글: fiona rozario 2017년 3월 18일
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?

채택된 답변

Walter Roberson
Walter Roberson 2017년 3월 18일
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.
  댓글 수: 1
fiona rozario
fiona rozario 2017년 3월 18일
Thank you! I have been stuck just for this issue for hours...and it's resolved now...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by