예제 #1
0
# performing convolution
b = scipy.ndimage.filters.convolve(a, k)
plt.imshow(b)
plt.show()

# The mean filter effectively removed the noise but in the process blurred the image.
#Advantages of the mean lter
# Removes noise.
# Enhances the overall quality of the image, i.e. mean filter brightens an image.
#Disadvantages of the meanlter
# In the process of smoothing, the edges get blurred.
# Reduces the spatial resolution of the image.

# b is converted from an ndarray to an image
b = Image.fromarray(b)
#b.save('./image_data/elephant_marked_mean_filter.png')

# Median Filter
#The median lter is most commonly used in removing salt-and-pepper (black and white spots) noise and impulse

# performing the median filter
b = scipy.ndimage.filters.median_filter(a,
                                        size=5,
                                        footprint=None,
                                        output=None,
                                        mode='reflect',
                                        cval=0.0,
                                        origin=0)
plt.imshow(b)
plt.show()
예제 #2
0
# # Plot the CDF of the image

# In[88]:

# Plot the cdf of the image
plt.figure(figsize=(6, 6))
plt.plot(cdf_m)
plt.title("CDF of the Original Image")
plt.xlabel("Pixel Intensity")
plt.ylabel("Cumulative Sum")
plt.show()

# In[89]:

# Convert the reshaped array into an image
histogram_equalized = Image.fromarray(histogram_equalized_array)

# ## Plot images before and after histogram equalization

# In[239]:

fig, ax = plt.subplots(1, 2, figsize=(10, 10))
ax[0].imshow(image, cmap='gray')
ax[0].title.set_text("Before")

ax[1].imshow(histogram_equalized, cmap='gray')
ax[1].title.set_text("After")
plt.show()

# ## We can see that the distribution of pixel intensities is now much wider this in theory should improve the contrast in the image
#