Hide an Image in Another Image
来源:互联网 发布:linux zip命令解压 编辑:程序博客网 时间:2024/06/05 22:59
For one assignment of web programming, there is some requirement like below for hiding images, the idea idea is important to remember.
So I paste the code I written before for the record.
Requirement:
Create a web page for the steganography program you wrote for Part 3 and include on the page:
Four images:
Two original images of which you plan to hide one image in the other image
Your combined image that has the other image hidden in it with the hidden image hiding in the lower 2 bits
The extracted hidden image
An explanation of how you modified your code to hide an image in 2 bits
The hidden message found in the provided picture above that is hiding in the lower two bits
The link for the result is: http://codepen.io/williamcs/post/e-portfolio
Below is js code for the implementation:
function crop(image, width, height){ var n = new SimpleImage(width,height); for(var p of image.values()){ var x = p.getX(); var y = p.getY(); if (x < width && y < height) { var np = n.getPixel(x,y); np.setRed(p.getRed()); np.setBlue(p.getBlue()); np.setGreen(p.getGreen()); } } return n;}function pixchange(pixval){ var x = Math.floor(pixval/4) * 4; return x;}function pixrevert(pixval) { var x = (pixval % 4) * 64; return x;}function chop2hide(image){ for(var px of image.values()){ px.setRed(pixchange(px.getRed())); px.setGreen(pixchange(px.getGreen())); px.setBlue(pixchange(px.getBlue())); } return image;}function shift(im){ var nim = new SimpleImage(im.getWidth(), im.getHeight()); for(var px of im.values()){ var x = px.getX(); var y = px.getY(); var npx = nim.getPixel(x,y); npx.setRed(Math.floor(px.getRed()/64)); npx.setGreen(Math.floor(px.getGreen()/64)); npx.setBlue(Math.floor(px.getBlue()/64)); } return nim;}function newpv(p,q){ var answer = p+q; if (p+q > 255) answer = 255; //print("error too big: answer"); return answer;}function combine(a,b){ var n = new SimpleImage(a.getWidth(), a.getHeight()); for(var pa of a.values()){ var x = pa.getX(); var y = pa.getY(); var pb = b.getPixel(x,y); var np = n.getPixel(x,y); np.setRed(newpv(pa.getRed(),pb.getRed())); np.setGreen(newpv(pa.getGreen(),pb.getGreen())); np.setBlue(newpv(pa.getBlue(),pb.getBlue())); } return n;}function extract(image) { var img = new SimpleImage(image.getWidth(), image.getHeight()); for (var px of image.values()) { var x = px.getX(); var y = px.getY(); var npx = img.getPixel(x, y); npx.setRed(pixrevert(px.getRed())); npx.setGreen(pixrevert(px.getGreen())); npx.setBlue(pixrevert(px.getBlue())); } return img;}var start = new SimpleImage("usain.jpg");//("astrachan.jpg");var hide = new SimpleImage("skyline.jpg");//("duvall.jpg")var cropWidth = start.getWidth();if (hide.getWidth() < cropWidth) {cropWidth = hide.getWidth();}var cropHeight = start.getHeight();if (hide.getHeight() < cropHeight) {cropHeight = hide.getHeight();}start = crop(start,cropWidth, cropHeight);hide = crop(hide,cropWidth, cropHeight);print(start);print(hide);start = chop2hide(start);hide = shift(hide);var new_im = combine(start, hide);print(new_im);var extract_img = extract(new_im);print(extract_img);var hilton_hiden = new SimpleImage("hilton_hiden.png");var extract_hilton = extract(hilton_hiden);print(extract_hilton);
Below is the code for hiding image in 4 bits:
function crop(image, width, height){ var n = new SimpleImage(width,height); for(var p of image.values()){ var x = p.getX(); var y = p.getY(); if (x < width && y < height) { var np = n.getPixel(x,y); np.setRed(p.getRed()); np.setBlue(p.getBlue()); np.setGreen(p.getGreen()); } } return n;}function pixchange(pixval){ var x = Math.floor(pixval/16) * 16; return x;}function pixrevert(pixval) { var x = (pixval % 16) * 16; return x;}function chop2hide(image){ for(var px of image.values()){ px.setRed(pixchange(px.getRed())); px.setGreen(pixchange(px.getGreen())); px.setBlue(pixchange(px.getBlue())); } return image;}function shift(im){ var nim = new SimpleImage(im.getWidth(), im.getHeight()); for(var px of im.values()){ var x = px.getX(); var y = px.getY(); var npx = nim.getPixel(x,y); npx.setRed(Math.floor(px.getRed()/16)); npx.setGreen(Math.floor(px.getGreen()/16)); npx.setBlue(Math.floor(px.getBlue()/16)); } return nim;}function newpv(p,q){ var answer = p+q; if (p+q > 255) answer = 255; //print("error too big: answer"); return answer;}function combine(a,b){ var n = new SimpleImage(a.getWidth(), a.getHeight()); for(var pa of a.values()){ var x = pa.getX(); var y = pa.getY(); var pb = b.getPixel(x,y); var np = n.getPixel(x,y); np.setRed(newpv(pa.getRed(),pb.getRed())); np.setGreen(newpv(pa.getGreen(),pb.getGreen())); np.setBlue(newpv(pa.getBlue(),pb.getBlue())); } return n;}function extract(image) { var img = new SimpleImage(image.getWidth(), image.getHeight()); for (var px of image.values()) { var x = px.getX(); var y = px.getY(); var npx = img.getPixel(x, y); npx.setRed(pixrevert(px.getRed())); npx.setGreen(pixrevert(px.getGreen())); npx.setBlue(pixrevert(px.getBlue())); } return img;}var start = new SimpleImage("usain.jpg");//("astrachan.jpg");var hide = new SimpleImage("skyline.jpg");//("duvall.jpg")var cropWidth = start.getWidth();if (hide.getWidth() < cropWidth) {cropWidth = hide.getWidth();}var cropHeight = start.getHeight();if (hide.getHeight() < cropHeight) {cropHeight = hide.getHeight();}start = crop(start,cropWidth, cropHeight);hide = crop(hide,cropWidth, cropHeight);print(start);print(hide);start = chop2hide(start);hide = shift(hide);var new_im = combine(start, hide);print(new_im);var extract_img = extract(new_im);print(extract_img);print(extract(new SimpleImage("9.png")));print(extract(new SimpleImage("10.png")));
0 0
- Hide an Image in Another Image
- Copying an image from one server to another using PHP
- Where to put the Image in an Image Caption Generator
- Add text to an image in Java
- Save an userform as an image in EXCEL
- Fading an Image Away
- Drawing an Image:画一幅图
- Drawing to an Image
- Capturing an Image
- NavigationBar ( with an image )
- Image thumbnail in an optimized way for J2Me platform
- How to store an image file to SQliteDB in android
- How to store an image file to SQliteDB in android
- Reducing the Number of Gray Levels in an Image
- detects edges in an image using the homogeneity operator
- Displaying an image with EJS in node.js/express
- How to convert an input image from one color space to another space
- Embedded image missed after moving page to another space in Confluence
- css样式大全
- 使用Android Studio创建Android项目
- 测试ActiveMQ主从复制
- 算法总结—数论
- cocoapods 引入错误
- Hide an Image in Another Image
- jquery datatable刷新请求方式
- 自定义Android流布局实现推荐标签功能
- 剑指offer系列之二十四:复杂链表的复制
- DevExpress GridControl使用方法
- Network In Network
- MSSQL server2008R2 智能提示消失的处理
- mysql不同版本说明
- 用到的资料链接