steganography-Picture steganography

Source: Internet
Author: User

steganography-Picture steganography

Today do dam homework, to do the picture watermark, think of the first minor in the words of the Court of the seed through the picture sent to me. See the following news really feel the bunker!! Technology House once again can be successful and obscure confession!! haha Ah!!

Http://war.163.com/10/0712/17/6BDLNUB90001123L.html

Below to share the following their own implementation of the steganography with Python, and later if there is time to further study the decoding problem!!

The basic ideas are:

1. Each picture has an RGB three channel, and the value of each pixel is 3 8-bit r/g/b value.

2. Remove the last two bits &11111100 (0xFC) from each RGB value, since the last two bits have little effect on the image and are invisible to the naked eye.

3. Divide the RGB values of the images you want to hide by 85 (255/3=85) so that you can represent the picture by 2bits (00-11,0-3)

4. Fill in the previous 2 empty bits with the resulting value

5. When decoding, as long as the previous in the original image hidden in the 2-bit extraction (&0x3) and then *85 can get the original information

Another way is to write the information in the alpha channel and encode it in RBG format, using the L format when decoding.

But the picture will be distorted, because after all, 2 bits of storage information will be much less than 8 bits of storage, but you can already see 80% of the picture information. So I have to praise the 28 rule, 20% of the encoded information stored 80% of the picture information ah.

ImportImage,imagechopsDefWaterMark (originfile,markfile): origin =Image.open (originfile) Mark =Image.open (markfile) size = Mark.size#Record the original size of the marked image mark = Mark.resize (origin.size)#Set the pics in same sizeOrigin.load (); Mark.load () Source1=origin.split ()#Split the PIC in 3 channel source2=Mark.split () image=[(), (), ()] watermark=[(),(),()]For XIn [0,1,2]:#Loop in 3 channel, RGB Image[x]=source1[x].point (Lambda I:i & 0xFC)#Remove the last 2 bits of the original image, 0xfc=11111100 Watermark[x]=source2[x].point (Lambda i:i/85)#Reduce the RGB value of each channel, 255/3=85Mark=image.merge ("Rgb", WaterMark) Origin=image.merge ("Rgb", image) result=Imagechops.add (Mark,origin)ReturnResult,sizeDefDeCode (watermark,size):#Watermark=image.open (WaterMark)Watermark.load () Source =Watermark.split () originsize=Size#Print Originsizemark=[(),(),()]For Xin [0,1,2]: Mark[x]=source[x].point (Lambda I: (I & 0x3) *85)#Get back the RGB value of the marked imageResult=image.merge ("Rgb", mark) result = Result.resize (originsize) return Resultif __name__ = = __main__ : Img1,size = WaterMark ( "avatar2.jpg " green.jpg ") Img2 = DeCode (img1,size) img1.show () #original image with Watermark Img2.show () #embeded image              

steganography-picture steganography

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.