Farooq
Farooq

Reputation: 90

Restore distorted image

i have written this code for distorting an image, it works well but have problem to restore this distorted image running this same code again

pic=imread('pepers.png');
[imr,imc,clr]=size(pic);
img2=pic;

v=66;
for row=1:imr

    for col=1:imc
        for k=1:clr

            img2(row,col,k)=bitxor(pic(row,col,k),v);
            v=img2(row,col,k);
        end
    end
end


imwrite(img2,'pic2.png');
imshow(img2);

Upvotes: 0

Views: 1248

Answers (1)

Howard
Howard

Reputation: 39207

The method XORs each value with the encoding of the previous value. Thus the inverse is not exactly the same as the encoding function. You have to switch the assignment of v to the encoded value, thus

img2(row,col,k)=bitxor(pic(row,col,k),v);
v=pic(row,col,k);

for the decoding method.

Upvotes: 1

Related Questions