Back to posts Edit this post
Copy content

11 Dec 17:05

noised2 = imageio.imread('noised2.png') noised3 = imageio.imread('noised3.png') noised4 = imageio.imread('noised4.png') # Apply median filter with different mask sizes def apply_median_filter(image, size): return ndimage.median_filter(image, size=size) # Function to display images before and after median filtering def displayBeforeAfterFilter(image, size, Title="Image"): # Convert to grayscale image_gray = to_grayscale(image) # Apply median filter filtered_image = apply_median_filter(image_gray, size) # Display original and filtered images plt.figure(figsize=(2 * default_figsize, default_figsize)) # Display the original image plt.subplot(1, 2, 1) plt.imshow(image_gray, cmap='gray') plt.title(f"Original - {Title}") plt.axis('off') # Display the filtered image plt.subplot(1, 2, 2) plt.imshow(filtered_image, cmap='gray') plt.title(f"Filtered - {Title} (size={size})") plt.axis('off') # Show the plot plt.show() # Apply median filter to the noisy images for image, name in zip([noised2, noised3, noised4], ["noised2", "noised3", "noised4"]): for size in [(3, 3), (1, 5), (5, 1), (5, 5)]: displayBeforeAfterFilter(image, size, Title=name)

No files