For this assignment, you are provided with an image (mountain.png). This image is actually hiding another image inside it. Your mission, as a Comp208 detective, is to retrieve the hidden image and...

1 answer below »

For this assignment, you are provided with an image (mountain.png). This image is actually


hiding another image inside it. Your mission, as a Comp208 detective, is to retrieve the


hidden image and then implement some utility methods.


Let’s implement the software step by step:


Step 1 (10 pts)


First you need to create a class called ImageAnalysis.


1. This class will take an image name as a constructor argument and will assign the


numpy array of the image to a member attribute called image.


2. The class will also implement a method called show. When show is called the image


will be displayed on the screen.


3. If you try to print any object of type ImageAnalysis, the shape of the image should


be printed out to the screen.


Example code:


i = ImageAnalysis("mountain.png")


print(i) # this will print the following: Shape is: (1512, 2016, 3)


i.show() # this will open a window showing the picture


Step 2 (25 pts)


Add a method called retriveHidden that will retrieve the concealed image within the


mountain image.


1. The retrieved numpy array of the image will be stored in a member attribute called


hiddenImage and then it will be saved to the disk under the name “hidden.jpg”.


You can use imsave method from skimage.io library to save the image.


2. To retrieve the image, you have to reverse engineer the algorithm that was being


used to hide the image. The algorithm works like this:


a. The hidden image has the following shape(131, 100, 3)


5


b. The hidden image was integrated to the mountain image by replacing pixels


from the mountain image by the pixels from the hidden image


c. The first pixel (row 0 col 0) from the mountain image was replaced by the


first pixel (row 0 col 0) from the hidden image.


d. The 12th pixel (row 0 col 11) from the mountain image was replaced by the


second pixel (row 0 col 1) from the hidden image and so on until all the pixels


on the first row from the hidden image were concealed.


e. Same thing for all the rows by spacing them by 11 pixels each time. Meaning


that both rows and columns are spaced by 11 pixels in the mountain image.


f. Your starting point is row 0 col 0 in the mountain image.


You need to reverse engineer this algorithm, meaning that you need to do the


opposite operations in order to retrieve the hidden image from the mountain


image. The algorithm is simple, you just need to know that every 2 consecutive


pixels from the hidden image are separated by 11 pixels in the mountain image.


You can make sure that the image is retrieved by displaying it to the screen. The


code to run your software will now look like this:


i = ImageAnalysis("mountain.png")


print(i)


#i.show()


i.retrieveHidden()


Open your file explorer and look for the created hidden.jpg. Open it to reveal the


mystery. If you don’t see the picture of someone, then you have to try harder and to


review your implementation.


Step 3 (15 pts)


After retrieving the hidden image, you need now to fix the original mountain image. You


have obviously noticed that the pixels from the hidden image are creating noise in the


mountain picture. One way of fixing this, is to replace each of these pixels by the average


color code from the neighboring pixels. This means that you need to replace the RGB tuple


for these pixels by the average RGB from the 4 neighboring pixels.


6


Implement this algorithm in a method called fix.


The code to test your software will now look like this:


i = ImageAnalysis("mountain.png")


print(i)


i.retrieveHidden()


i.fix()


i.show()


Step 4 (25 pts)


Now we need to average the color in each pixel of the retrieved image and store the result


to a file on the disk. Write a method called averageRGB that will do the following:


1. It will read the numpy array of the retrieved hidden image


2. For each pixel, it will average the values of R, G and B.


3. Write the average value to a new matrix. For example if the RGB tuple was (100, 120,


140), the average of the three is 120, so the new RGB value will be one element


instead of 3: 120


4. Write the content of the newly created matrix to a file called RGB.csv


5. Please note that the number of lines in the file should match the number of rows in


the corresponding matrix. You can check the number of rows by examining the


shape method. The values should be separated by comma “,”.


The code to test your software will now look like this:


i = ImageAnalysis("mountain.png")


#print(i)


i.retrieveHidden()


i.fix()


#i.show()


i.averageRGB()


Open your file explorer and look for the created file RGB.csv. Check that the content of


the file is OK.


7


Step 5 (25 pts)


The last step is now to write a method called load_rgb_from_file that will read the values


from the RGB.csv file (provided as argument) and construct a numpy array out of it. The


shape of the numpy array should be (nbre_of_lines, nbre_of_columns, 3). Meaning that


axis-0 will match the number of lines in the file, axis-1 will match the number of columns


(values separated by comma) and each element in the array is a tuple of 3 elements


corresponding to R, G and B. However, the 3 values will be the same and equal to the


average value from the file.


After successfully building the array, use the following to test your code:


i = ImageAnalysis("mountain.png")


#print(i)


i.retrieveHidden()


i.fix()


#i.show()


i.averageRGB()


i.load_rgb_from_file(“RGB.csv”)


The method load_rgb_from_file should display to the screen the new image. What do you


notice about it?





Answered 3 days AfterApr 06, 2021

Answer To: For this assignment, you are provided with an image (mountain.png). This image is actually hiding...

Sandeep Kumar answered on Apr 10 2021
144 Votes
class ImageAnalysis(object):
def __init__(self, image):
self.image = io.imread(image)

dim = self.image.shape
print(dim)
def show(self):
self.show = io.imshow(self.image)
self.x = io.show()
print(self.x)
def retriveHidden(self):
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here