MATLAB: I am not getting why secret message(x) is changing when apply dwt on image.

digital image processingdigital signal processingdwtimreadimwriteintegerwavletiwtsteganographyWavelet Toolbox

x=-4.335145935643288e-04;
img = imread('frame286.png');
img1=rgb2gray(img);
img2=im2double(img1);
liftscheme = liftwave('haar','int2int');
[cA cH cV cD]=lwt2(img2,'liftscheme');
cD(180,1)=x;
X = idwt2(cA,cH,cV,cD,'liftscheme');
imwrite(X,'gg23.png');
x2= imread('gg23.png');
img5=im2double(x2);
[cA1 cH1 cV1 cD1]=lwt2(x2,'liftscheme');
rr3=cD1(180,1);
now value is changed ie (rr3!=x)
but when i does not create image then it gives same values
x=-4.335145935643288e-04;
img = imread('frame286.png');
img1=rgb2gray(img);
img2=im2double(img1);
liftscheme = liftwave('haar','int2int');
[cA cH cV cD]=lwt2(img2,'liftscheme');
cD(180,1)=x;
X = idwt2(cA,cH,cV,cD,'liftscheme');
[cA1 cH1 cV1 cD1]=lwt2(X,'liftscheme');
rr3=cD1(180,1);
plz someone explain why this is happening because of imwrite?

Best Answer

Round off error. See this bit of documentation in imwrite():
"If A is a grayscale or RGB color image of data type double or single, then imwrite assumes that the dynamic range is [0,1] and automatically scales the data by 255 before writing it to the file as 8-bit values. If the data in A is single, convert A to double before writing to a GIF or TIFF file."
Therefore when you are writing to the .png file, your floating point values are being quantized. That is not happening when you do not write to file.
Related Question