Thursday 8 October 2015


You will be able to hide one image inside another image by hiding information inside half of each pixel's bits of data. Your task is to do the following:
  1. Select two images to use. You will hide one image in another image. They most likely will be different sizes and in the next step we will crop both of them to be the same size.
  2. In order to hide one image inside of another image, the images need to be the exact same size. Write the function crop(image, width, height) that has three parameters: image is a complete image, and width andheight are numbers. This function creates and returns a new image from the parameter image, with the new image having the width and height of the specified width and height parameters, thus cropping the picture by ignoring the pixels on the right side or bottom that are beyond the specified width or height of the picture.

3. Test the crop function you wrote by
  • Inputting two images of different sizes
  • Determining the size of the cropped images
  • Calling the function crop to create new images of the same size
  • Test the crop function by printing the values of the width and heights of the two images before and after cropping them. You will be able to tell if the images are the same sizes and If the images are dramatically different sizes, you should also see the crop quite clearly.


4. Make room to hide an image by
  • Type in the chop2Hide and pixchange functions from the steganography lesson. How well did you understand those functions. See if you can write them without looking at the code!
  • Then call the function chop2Hide with the image that will be hiding another image, saving the resulting image in a variable called start.
  • How do we know it worked correctly?--- Pick one pixel from your original image, say at location x=50 and y=60 and print out its red, green and blue values before applying chop2Hide, and then print out the same pixel location in the new image returned from the call to chop2Hide. Calculate to see if it is the correct value. You can use this method to print and see the values of a few pixels to convince yourself thatchop2Hide is working. There are too many pixels to print out all the values.


5. Prepare the image to hide by shifting the left most half of the bits to the right and replacing the leftmost half of the bits to 0.
  • Type in the shift function from the lesson. How well did you understand it? Can you write it without looking at the code from the lesson?
  • Call the shift function on the image you want to hide to prepare it for hiding.
  • You can test the function in the same way you tested the crop2Hide function by printing the RGB values of a few pixels before and after calling shift.


  • Write the function combine to create a new image that is the chopped image combined with the shifted image to create an image with another image hidden inside of it. The steps you should take are:--- Write a function called newpv(p,q) with the integer parameters p and q to return the sum of p and q. This function should print an error message if the sum is greater than 255. With the way we have written the code, the sum should never be greater than 255, so this will let us know if we did something wrong.--- Write the function combine(image1, image2) that returns a new image that is the combination of the two images. For each pixel in one image, find the pixel in the same position in the other image and add the red values together, the blue values together and the green values together to form a pixel for the new image.--- Test the resulting image by sampling a pixel that is in image1image2 and the new image and check their RGB values to see if they added together correctly.


The complete code for hiding one image inside another is given below:


Learning Objectives for this quiz:
  • Learners should understand how the parts of the steganography algorithm work to hide an image inside another image. In particular they should understand how to crop two images so they are the same size, how chop2hide makes room for hiding information in the RGB components of each pixel, how shift moves the important information into the lower half of the bits of each pixels RGB values, and how combine puts together two images to complete the hiding of one image in another.
  • Learners should understand how to convert a binary number to a decimal number and vice versa

Now we will extract the imageToHide from the imageThatHides.


The complete program that hides an image inside another and then extracts it back is given below:


Write a complete javascript program that specifies two thicknesses, one for the vertical borders and one for the horizontal borders of an image. Write a function pixelOnEdgeDifferentThicknesses( ). The parameters are not shown. You should decide on the parameters. Write the function and test it to make sure it works so you can generate pictures with borders that have different thicknesses for the vertical borders vs. the horizontal borders.
Write a complete javascript program that specifies two thicknesses, one for the vertical borders and one for the horizontal borders of an image. You should write the two boolean functions shown below. Be sure to print the image and run your program with different border values for the horizontal and vertical edges.
  1. function pixelOnVerticalEdge(pixel, image, borderWidth)—This function has three parameters where pixel is a single pixel, image is the complete image, and borderWidth is an integer specifying the thickness of the vertical borders. This function returns true if the pixel’s location is within borderWidth of any of the two vertical borders, and thus on the border. Otherwise it returns false.
  2. function pixelOnHorizontalEdge(pixel, image, borderWidth)—This function has three parameters where pixel is a single pixel, image is the complete image, and borderWidth is an integer specifying the thickness of the horizontal borders. This function returns true if the pixel’s location is within borderWidth of any of the two horizontal borders, and thus on the border. Otherwise it returns false.
Here is the code.

Write the complete JavaScript program to put the border around a picture, and include the following functions that are included from the lesson. You should be able to write these functions without looking at the code from the lesson. Be sure to print the image so you can see it and run the program with different border values. a) function setBlack(pixel) - This function has a parameter pixel that represents a single pixel, and returns a pixel that has been changed to be the color black. b) function pixelOnEdge(pixel, image, borderWidth) - This function has three parameters where pixel is a single pixel, image is the complete image, and borderWidth is an integer specifying the thickness of the borders. This function returns true if the pixel’s location is within borderWidth of any of the four borders, and thus on the border. Otherwise it returns false.

Write a JavaScript program to make an image have more red in it, by adding a given value to the red, making sure it doesn’t go over 255. Your program should have a function called moreRed with two parameters, a pixel and a value to increase the red by. Run your program on an image to see it get redder.

javascript functions:


Write a JavaScript program that has a function named swapRedGreen with one parameter pixel. This function should swap the red and green values of the pixel. Pick an image, print the image, then applyswapRedGreen to every pixel in the image, and print the new image. The choice of your image is important. For some images you may not notice any change. Think about what type of image you should use for testing your function.