Question
1. Image Merging: (10 pts.) Write code to merge the color image and black-and-white image of the apple. The inputs to your function are: (i)
1. Image Merging:
(10 pts.) Write code to merge the color image and black-and-white image of the apple.
The inputs to your function are: (i) blackwhite image: blackwhite_image.png (size: 183 Rows X 275 Cols), (ii) color image: color_image.png (size: 183 Rows X 275 Cols), (iii) image column (c) at which the images should be merged.
image_op/operations.py: Edit the function merge
Define a new image as follows: the first c columns (default value = 149) should be used from the left image (color_image.png). The remaining columns should be used from the right image (blackwhite_image.png).
Note that the blackwhite_image.png is not a greyscale image (with one channel) but a color image and has three channels with shape (183, 275, 3).
2. Color Slicing:
(20 pts.) Write code to make a color sliced image from a color image. The overall objective is to extract pixels that have color that are similar to a predefined target color. Each pixel in the final color sliced image is created by either populating the pixel from the color image or the black-and-white image. The final color sliced image should copy pixels from the color image as long as the pixel's color distance to the target color is within a predefined threshold. If the distance is greater that the thershold, pixels from the black-and-white image are copied. Below is the expected output image.
Inputs: The inputs to your function are: (i) a color image: color_image.png, (ii) blackwhite image: blackwhite_image.png, (iii) the targeted color ((0, 0, 255) by default) and (iv) a threshold (t = 180 by default).
image_op/operations.py: Edit the function color_slicing.
Create a result/output image of the same shape as the input color image
Calculate the Euclidean distance between every pixel of the color image and the target color.
If the distance is smaller than threshold, copy the color pixel, else copy the black-and-white pixel to the output image.
Note: We are restricted from importing cv2, numpy, stats and other third party libraries, with the only exception of math, importing math library is allowed (import math).
While you can import it for testing purposes, the final submission should not contain the following statements.
import cv2
import numpy
import numpy as np
import stats
etc...
The essential functions for the assignment are available in dip module one can import using the following statement
import dip from dip import *
The following functions are available
from cv2 import namedWindow, imshow, waitKey, imwrite, imread from numpy import zeros, ones, array, shape, arange from numpy import random from numpy import min, max from numpy import int, uint8, float, complex from numpy import inf from numpy.fft import fft2
Assigments that contain any files that import these libraries will not be graded. Assigments that modify the dip.py file will not be graded.
Please do not change the code structure
Usage:
- python dip_hw0.py -ic-ib -c -t -tc -tc -tc - Example: python dip_hw0.py -ic color_image.png -ib blackwhite_image.png -c 149 -t 180 -tc 0 -tc 0 -tc 255
where c = column, t = threshold, tc = blue_value green_value red_value. You can change the values of the arguments as you may want.
Please make sure the code runs when you run the above command from prompt/terminal
All the output images and files are saved to "output/" folder
Two images are provided for testing: blackwhite_image.png and color_image.png
PS. Please do not change dip.py, dip_hw0.py, requirements.txt, and Jenkinsfile.
Operation - 30 Pts.
Total - 30 Pts.
OPERATIONS.PY
import math from dip import * """ Do not import cv2, numpy and other third party libs """ class Operation: def __init__(self): pass def merge(self, image_left, image_right, column): """ Merge image_left and image_right at column (column) image_left: the input image 1 image_right: the input image 2 column: column at which the images should be merged returns the merged image at column """ # new code # add your code here # Please do not change the structure return image_left # Currently the original image is returned, please replace this with the merged image def color_slicing(self, color_image, blackwhite_image, target_color, threshold): """ Perform color slicing to create an image where only the targeted color is preserved and the rest is black and white color_image: the input color image blackwhite_image: the input black and white image target_color: the target color to be extracted threshold: the threshold to determine the pixel to determine the prximity to the target color return: output_image """ # add your code here # final = gray_image * mask_in # Please do not change the structure return color_image # Currently the input image is returned, please replace this with the color extracted image
ONLY NEED TO EDIT OPERATIONS.PY
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started