def sharpen(im: np.array): laplacian = np.array([ [0, -1, 0], [-1, 4, -1], [0, -1, 0] ]) ### START YOUR CODE HERE ### (You can change anything inside this block) im_filt = convolve_im(im, laplacian, verbose=True) # JUST FOR TESTING # im_filt = im_filt-im_filt.min() # im_filt = im_filt/im_filt.max() # # im = im-im.min() # im = im/im.max() # im_filt = np.where(im+im_filt > im.max(), im.max(), im_filt) # im_filt = np.where(im+im_filt < im.min(), im.min(), im_filt) # im_sharp = im+im_filt #im_sharp = np.where(im_sharp > im.max(), im.max(), im_sharp) plt.imshow(im_sharp,cmap="gray") ### END YOUR CODE HERE ### return im_sharp
def sharpen(im: np.array): """ Sharpens a grayscale image using the laplacian operator. Args: im: np.array of shape [H, W] Returns: im: np.array of shape [H, W] """ laplacian = np.array([[0, -1, 0], [-1, 4, -1], [0, -1, 0]]) im = im + convolve_im(im, laplacian) plt.show() return im
def sharpen(im: np.array): """ Sharpens a grayscale image using the laplacian operator. Args: im: np.array of shape [H, W] Returns: im: np.array of shape [H, W] """ laplacian = np.array([[0, -1, 0], [-1, 4, -1], [0, -1, 0]]) ### START YOUR CODE HERE ### (You can change anything inside this block) conv_im = convolve_im(im, laplacian, verbose=False) im = im + conv_im ### END YOUR CODE HERE ### return im
def sharpen(im: np.array): """ Sharpens a grayscale image using the laplacian operator. Args: im: np.array of shape [H, W] Returns: im: np.array of shape [H, W] """ laplacian = np.array([ [0, -1, 0], [-1, 4, -1], [0, -1, 0] ]) ### START YOUR CODE HERE ### (You can change anything inside this block) ###just adds the image and the convolve_im result together and returns it im=np.add(im,convolve_im(im, laplacian, True)) ### END YOUR CODE HERE ### return im
def sharpen(im: np.array): """ Sharpens a grayscale image using the laplacian operator. Args: im: np.array of shape [H, W] Returns: im: np.array of shape [H, W] """ laplacian = np.array([[0, -1, 0], [-1, 4, -1], [0, -1, 0]]) ### START YOUR CODE HERE ### (You can change anything inside this block) # Convolute image and Laplacian to find image details. sharpened = convolve_im(im, laplacian) # Attenuate the details in the image. im = im + sharpened ### END YOUR CODE HERE ### return im
def sharpen(im: np.array): """ Sharpens a grayscale image using the laplacian operator. Args: im: np.array of shape [H, W] Returns: im: np.array of shape [H, W] """ laplacian = np.array([[0, -1, 0], [-1, 4, -1], [0, -1, 0]]) ### START YOUR CODE HERE ### (You can change anything inside this block) # Convolve img with laplacian kernel convolved_im = convolve_im(im, laplacian, verbose=True) # Use equation 6. resulting_im = np.add(im, (im * convolved_im)) # Limit values between [0,1] im = np.add(resulting_im, resulting_im.min()) im = np.multiply(im, 1 / im.max()) ### END YOUR CODE HERE ### return im
import skimage import os import numpy as np import utils from task4b import convolve_im from matplotlib import pyplot as plt if __name__ == "__main__": # DO NOT CHANGE impath = os.path.join("images", "clown.jpg") im = skimage.io.imread(impath) im = utils.uint8_to_float(im) kernel = np.load("images/notch_filter.npy") ### START YOUR CODE HERE ### (You can change anything inside this block) im_filtered = convolve_im(im, kernel) plt.show() ### END YOUR CODE HERE ### utils.save_im("clown_filtered.png", im_filtered)
plt.imshow(conv_result, cmap="gray") ### END YOUR CODE HERE ### return conv_result if __name__ == "__main__": # DO NOT CHANGE impath = os.path.join("images", "clown.jpg") im = skimage.io.imread(impath) im = utils.uint8_to_float(im) kernel = np.load("images/notch_filter.npy") ### START YOUR CODE HERE ### (You can change anything inside this block) im_filtered = convolve_im(im, kernel, verbose = True) ### END YOUR CODE HERE ### utils.save_im("clown_filtered.png", im_filtered) H,W = np.shape(im) h,w = np.shape(kernel) t_b = (H-h)//2 l_r = (W-w)//2 kernel_padded = np.pad(kernel, ((0, 2*t_b),(0, 2*l_r)), 'constant') plt.figure(figsize=(20, 5)) plt.subplot(1, 3, 1) f_im = np.fft.fftshift(np.fft.fft2(im, s=None, axes=(-2, -1), norm=None)) plt.imshow(np.abs(f_im), norm=LogNorm(vmin=1, vmax = 1000), aspect='auto')
import matplotlib.pyplot as plt from task4b import convolve_im if __name__ == "__main__": # DO NOT CHANGE impath = os.path.join("images", "noisy_moon.png") im = utils.read_im(impath) # START YOUR CODE HERE ### (You can change anything inside this block) im_freq = np.fft.fft2(im) im_freq_old = im_freq.copy() neigboor_average = np.ones((5, 5))/25 neigboor_average[2, 2] = 0 neigboor_convolved = convolve_im(np.abs(im_freq), neigboor_average, False) ratio = np.abs(im_freq) / neigboor_convolved noise_arg = np.unravel_index( np.argmax(ratio), im_freq.shape) print(noise_arg) im_freq[noise_arg] = 0 im_freq[-noise_arg[0], -noise_arg[1]] = 0 im_filtered = np.fft.ifft2(im_freq) fig, ax = plt.subplots(2, 2) ax[0, 0].imshow(im, cmap="gray") ax[0, 1].imshow(np.abs(im_filtered), cmap="gray") # ax[0, 2].set_axis_off() ax[1, 0].imshow(np.abs(np.fft.fftshift(im_freq_old)), cmap="gray", norm=SymLogNorm(1))