# In Class # Your Name: Kenneth Liang # GTID: 902 798 997 # Your Name: Katie Sclafani # GTID: 902 913 547 import cv2 import numpy as np import scipy as sp # findGrout stores locations where there is grout. It returns an array of 1s and 0s the size of the image, with 0s representing grout. def findGrout(wallHSV): # The upper and lower values of grout color should be defined here, iteratively tweaked lower_grout_color = np.array([0,0,100], dtype=np.uint8) upper_grout_color = np.array([28,100,255], dtype=np.uint8) groutMask = cv2.inRange(wallHSV, lower_grout_color, upper_grout_color) cv2.imwrite("groutMask.jpg",groutMask) return groutMask def mergeImgs(inWall, inPaint, inMask): # using the input mask and the inverse of that, the hue and saturation values of the paint image are mapped onto the bricks of the wall outImg = np.zeros(inWall.shape) invertMask = np.invert(inMask)/255 inMask = inMask/255 outImg[:,:,0] = inWall[:,:,0]*inMask[:,:] + inPaint[:,:,0]*invertMask[:,:] outImg[:,:,1] = inWall[:,:,1]*inMask[:,:] + inPaint[:,:,1]*invertMask[:,:] outImg[:,:,2] = inWall[:,:,2]*inMask[:,:] + inPaint[:,:,2]*invertMask[:,:] outImg = np.uint8(outImg) return outImg def paintWall(inWall, inPaint): wallHSV = cv2.cvtColor(inWall, cv2.COLOR_BGR2HSV) paintHSV = cv2.cvtColor(inPaint, cv2.COLOR_BGR2HSV) groutMask = findGrout(wallHSV) mergedImg = mergeImgs(wallHSV, paintHSV, groutMask) outImg = cv2.cvtColor(mergedImg, cv2.COLOR_HSV2BGR) outImg = cv2.GaussianBlur(outImg,(5,5),1.7) return outImg image1 = cv2.imread("brick5.JPG") image2 = cv2.imread("streetArtCollage.jpg") outImage = paintWall(image1, image2) cv2.imwrite("mergeImage.jpg",outImage)