def windowExplore(image, winSize = 40): """ def windowExplore(image, win)->None Divides an image into grids of size win*win """ WAIT_TIME = 50 WIN = winSize image = Image.border(image, WIN) image = cv2.GaussianBlur(image, (5,5), 5) oilPaint = np.zeros_like(image, np.uint8) avgPaint = oilPaint.copy() # cv2.imshow("OIL PAINT", oilPaint) row, col = image.shape[:2] startH = 0 for i in xrange(0, row/WIN): startW = 0 for j in xrange(0, col/WIN): roiQ = image[startH: startH + WIN, startW : startW + WIN] startK = 0 # startK = startW colors = [] colorsRed = [] colorsBlue = [] colorsGreen = [] # for k in xrange(0, col/WIN): roi = image[startH : startH + WIN, startW : startW + WIN] # colors = [roi[i][j] for i in WIN for j in WIN] for i in xrange(0,WIN): for j in xrange(0,WIN): colors.append(roi[i][j]) center = group(colors) avg = np.average(roi) # print center, avg oilWindow = np.ones(roi.shape, np.uint8)*center avgWindow = np.ones(roi.shape, np.uint8)*avg oilPaint[startH : startH + WIN, startW : startW + WIN] = oilWindow avgPaint[startH : startH + WIN, startW : startW + WIN] = avgWindow # cv2.imshow("OIL", oilPaint) # cv2.imshow("AVERAGE", avgPaint) # cv2.imshow("INPUT", image) # cv2.waitKey(WAIT_TIME) startW = startW + WIN startH = startH + WIN # cv2.imshow("OIL", oilPaint) # cv2.imshow("AVERAGE", avgPaint) # cv2.imshow("INPUT", image) # cv2.imshow("BLURRED", cv2.GaussianBlur(oilPaint, (5,5), 5)) # cv2.waitKey(WAIT_TIME*0) blurred = cv2.GaussianBlur(oilPaint, (5,5), 5) print oilPaint.shape return oilPaint, blurred