def output(partIdx): """Uses the student code to compute the output for test cases.""" outputString = '' if partIdx == 0: # splitrgb outputString = str(int(part0.test())) elif partIdx == 1: # interlace outputString = str(int(part1.test())) elif partIdx == 2: # greyscale outputString = str(int(part2.test())) return outputString
def output(partIdx): """Uses the student code to compute the output for test cases.""" outputString = '' if partIdx == 0: # reduce and expand outputString = str(int(part0.test())) elif partIdx == 1: # gauss_pyr and lapl_pyr outputString = str(int(part1.test())) elif partIdx == 2: # blend and collapse outputString = str(int(part2.test())) return outputString
def output(partIdx): """Uses the student code to compute the output for test cases.""" outputString = '' if partIdx == 0: outputString = str(int(part0.test())) elif partIdx == 1: outputString = str(int(part1.test())) elif partIdx == 2: outputString = str(int(part2.test())) return outputString
def output(partIdx): """Uses the student code to compute the output for test cases.""" outputString = '' if partIdx == 0: # convolve outputString = str(int(part0.test())) elif partIdx == 1: # gaussian outputString = str(int(part1.test())) elif partIdx == 2: # sharpen outputString = str(int(part2.test())) elif partIdx == 3: # median outputString = str(int(part3.test())) elif partIdx == 4: # theta and mag outputString = str(int(part4.test())) return outputString
else: outimg = [] for channel in range(img.shape[2]): outimg.append(conv_func(img[:,:,channel], kernel)) outimg = cv2.merge(outimg) outpath = os.path.join(outfolder, name + kernel_name + ext) print "Writing image {}.\n\n".format(outpath) cv2.imwrite(outpath, outimg) if __name__ == "__main__": # Testing code -------------------------------------------------------------- # feel free to modify this to try out different filters and parameters. print "-"*15 + "part0" + "-"*15 t0 = part0.test() print "Unit test: {}".format(t0) conv_func = signal.convolve2d if t0: conv_func = part0.convolve apply_filter(conv_func, box_filter(2), 'box2') else: print "Please test your code using part0.py prior to using this function." print "-"*15 + "part1" + "-"*15 t1 = part1.test() print "Unit test: {}".format(t1) if t1: apply_filter(conv_func, part1.make_gaussian(5,3), 'gaussian5_3') else: print "Please test your code using part1.py prior to using this function."
outimg = [] for channel in range(img.shape[2]): outimg.append(conv_func(img[:, :, channel], kernel)) outimg = cv2.merge(outimg) outpath = os.path.join(outfolder, name + kernel_name + ext) print "Writing image {}.\n\n".format(outpath) cv2.imwrite(outpath, outimg) if __name__ == "__main__": # Testing code -------------------------------------------------------------- # feel free to modify this to try out different filters and parameters. print "-" * 15 + "part0" + "-" * 15 t0 = part0.test() print "Unit test: {}".format(t0) conv_func = signal.convolve2d if t0: conv_func = part0.convolve apply_filter(conv_func, box_filter(2), 'box2') else: print "Please test your code using part0.py prior to using this function." print "-" * 15 + "part1" + "-" * 15 t1 = part1.test() print "Unit test: {}".format(t1) if t1: apply_filter(conv_func, part1.make_gaussian(5, 3), 'gaussian5_3') else: print "Please test your code using part1.py prior to using this function."
diff2 = part1.diff2(diff1) alpha = 1.5*10**6 idxs = part2.find_biggest_loop(diff2, alpha) diff3 = np.zeros(diff2.shape, float) for i in range(diff2.shape[0]): for j in range(diff2.shape[1]): diff3[i,j] = alpha*(i-j) - diff2[i,j] return viz_diff(diff1), viz_diff(diff2), viz_diff(diff3),\ part2.synthesize_loop(video_volume, idxs[0]+2, idxs[1]+2) if __name__ == "__main__": print 'Performing unit tests.' if not part0.test(): print 'part0 failed. halting' sys.exit() if not part1.test(): print 'part1 failed. halting' sys.exit() if not part2.test(): print 'part2 failed. halting' sys.exit() print 'Unit tests passed.' sourcefolder = os.path.abspath(os.path.join(os.curdir, 'videos', 'source')) outfolder = os.path.abspath(os.path.join(os.curdir, 'videos', 'out'))
outpyr = part2.blend(lapl_pyr_black, lapl_pyr_white, gauss_pyr_mask) outimg = part2.collapse(outpyr) outimg[ outimg < 0] = 0 # blending sometimes results in slightly out of bound numbers. outimg[outimg > 255] = 255 outimg = outimg.astype(np.uint8) return lapl_pyr_black, lapl_pyr_white, gauss_pyr_black, gauss_pyr_white, \ gauss_pyr_mask, outpyr, outimg if __name__ == "__main__": print 'Performing unit tests.' if not part0.test(): print 'part0 failed. halting' sys.exit() if not part1.test(): print 'part1 failed. halting' sys.exit() if not part2.test(): print 'part2 failed. halting' sys.exit() print 'Unit tests passed.' sourcefolder = os.path.abspath(os.path.join(os.curdir, 'images', 'source')) outfolder = os.path.abspath(os.path.join(os.curdir, 'images', 'output'))