def make_sharp(k, sd): '''Create a sharpen kernel. Input: k - the radius of the kernel. sd - the standard deviation of the gaussian filter used to make the kernel. Output: output - a numpy array of shape (2k+1, 2k+1) and dtype float. The sharpen filter is constructed by first taking a filter with a 2 in the center and 0's everywhere else, and subtracting from that a gaussian filter. Note: You can use the make_gaussian function from part one by typing: import part1 part1.make_gaussian(k, sd) ''' kernel = None # Insert your code here.---------------------------------------------------- # gaussian filter: import part1 gaussian_2d = part1.make_gaussian(k, sd) kernel = np.zeros((2*k+1, 2*k+1), dtype=float) # create an array, each point has value=0 kernel[k,k] = 2 # value = 2 in the center kernel = kernel - gaussian_2d # subtract the gaussian filter #--------------------------------------------------------------------------- return kernel
def make_sharp(k, sd): '''Create a sharpen kernel. Input: k - the radius of the kernel. sd - the standard deviation of the gaussian filter used to make the kernel. Output: output - a numpy array of shape (2k+1, 2k+1) and dtype float. The sharpen filter is constructed by first taking a filter with a 2 in the center and 0's everywhere else, and subtracting from that a gaussian filter. Note: You can use the make_gaussian function from part one by typing: import part1 part1.make_gaussian(k, sd) ''' kernel = None # Insert your code here.---------------------------------------------------- size = 2 * k + 1 base = np.zeros((size, size)) base[k, k] = 2 gaussian = part1.make_gaussian(k, sd) kernel = base - gaussian #--------------------------------------------------------------------------- return kernel
def make_sharp(k, sd): '''Create a sharpen kernel. Input: k - the radius of the kernel. sd - the standard deviation of the gaussian filter used to make the kernel. Output: output - a numpy array of shape (2k+1, 2k+1) and dtype float. The sharpen filter is constructed by first taking a filter with a 2 in the center and 0's everywhere else, and subtracting from that a gaussian filter. Note: You can use the make_gaussian function from part one by typing: import part1 part1.make_gaussian(k, sd) ''' gauss_kernel = part1.make_gaussian(k, sd) kernel = np.zeros((2 * k + 1, 2 * k + 1), dtype=float) kernel[k, k] = 2 kernel = kernel - gauss_kernel # Insert your code here.---------------------------------------------------- #--------------------------------------------------------------------------- return kernel
def make_sharp(k, sd): '''Create a sharpen kernel. Input: k - the radius of the kernel. sd - the standard deviation of the gaussian filter used to make the kernel. Output: output - a numpy array of shape (2k+1, 2k+1) and dtype float. The sharpen filter is constructed by first taking a filter with a 2 in the center and 0's everywhere else, and subtracting from that a gaussian filter. Note: You can use the make_gaussian function from part one by typing: import part1 part1.make_gaussian(k, sd) ''' kernel = -part1.make_gaussian(k, sd) kernel[k, k] += 2 return kernel
def make_sharp(k, sd): '''Create a sharpen kernel. Input: k - the radius of the kernel. sd - the standard deviation of the gaussian filter used to make the kernel. Output: output - a numpy array of shape (2k+1, 2k+1) and dtype float. The sharpen filter is constructed by first taking a filter with a 2 in the center and 0's everywhere else, and subtracting from that a gaussian filter. Note: You can use the make_gaussian function from part one by typing: import part1 part1.make_gaussian(k, sd) ''' kernel = None # Insert your code here.---------------------------------------------------- l = 2 * k + 1 m = math.floor(l / 2) import part1 kernel = np.negative(part1.make_gaussian(k, sd)) kernel[m, m] = 2 + kernel[m, m] #--------------------------------------------------------------------------- return kernel
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." print "-"*15 + "part2" + "-"*15 t2 = part2.test() print "Unit test: {}".format(t2) if t2: apply_filter(conv_func, part2.make_sharp(5,3), 'sharp5_3') else: print "Please test your code using part2.py prior to using this function." print "-"*15 + "part3" + "-"*15 t3 = part3.test() print "Unit test: {}".format(t3) if t3:
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." print "-" * 15 + "part2" + "-" * 15 t2 = part2.test() print "Unit test: {}".format(t2) if t2: apply_filter(conv_func, part2.make_sharp(5, 3), 'sharp5_3') else: print "Please test your code using part2.py prior to using this function." print "-" * 15 + "part3" + "-" * 15 t3 = part3.test() print "Unit test: {}".format(t3) if t3: