diff --git a/labo4.py b/labo4.py index b320a387b3a8f264e84b367c48329d214596d066..32d1c6a0ea01ae5f923d65a5d82bd647a2731858 100644 --- a/labo4.py +++ b/labo4.py @@ -108,11 +108,21 @@ def sharpen(img: Img, isotropy: Isotropy) -> Img: return new_image +def gauss_kernel(length: int = 3, sigma: float = 1.0) -> Img: + half = (length - 1) / 2 + x_axis = np.linspace(-half, half, length) + + gauss = np.exp(-0.5 * np.square(x_axis) / np.square(sigma)) + kernel = np.outer(gauss, gauss) + + return kernel / np.sum(kernel) + + if __name__ == "__main__": - img = load_img("resources/hotel.png") + img = load_img("resources/noisy_hotel.png") gray = rgb_to_gray(img) - laplacian = laplace(gray, Isotropy.ISO_45) + laplacian = laplace(xcorr(gray, gauss_kernel()), Isotropy.ISO_45) thresholded = thresholding(laplacian, 50) sharp_iso_90 = sharpen(gray, Isotropy.ISO_90)