libraries such as PIL, Skimage and matplotlib mping all produced the same result
img1 = io.imread("1.3/blurry-moon.tif")
img1 = img1.astype('int32')
img2 = io.imread("1.3/blurry-moon.tif")
imageArray = np.copy(img1)
image1 = np.copy(img1)
image2 = np.copy(img2)
applying a fir filter to these two images produces different results
FIR = [[0, -1, 0], [-1, 5 , -1], [0, -1, 0]]
img1 produces an enhanced image while img2 loses some detail in darker regions
I don't understand why the imported image type by default produces such bad results, any ideas on what is going on?
Thank you.
complete code:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import math
from skimage import io
# if current row of image exceeds row of convolutional filter, find the right row of the filter to apply
def convolve(image,filter, i, e):
tot = 0
for x in range(3):
for v in range(3):
tot += image[i+x][e+v]*filter[x][v]
return tot
# let img1 be an image with no features
img1 = io.imread("1.3/blurry-moon.tif")
# change image encoding, keeps the source image as it is. What conversion happened when using the Library?
# ***********************************
img1 = img1.astype('int32')
img2 = io.imread("1.3/blurry-moon.tif")
# These are their own individual new images
imageArray = np.copy(img1)
image1 = np.copy(img1)
image2 = np.copy(img2)
# gets the size of the image array
imageSize = imageArray.shape
FIR = [[0, -1, 0],
[-1, 5 , -1],
[0, -1, 0]]
for i, row in enumerate(imageArray):
for e, value in enumerate(row):
# make sure we done apply the filter outside the image boundary
if i < (imageSize[0]-3) and e < (imageSize[1]-3):
image1[i+1][e+1] = convolve(imageArray, FIR, i ,e)
for i, row in enumerate(imageArray):
for e, value in enumerate(row):
if i < (imageSize[0]-3) and e < (imageSize[1]-3):
image2[i+1][e+1] = convolve(imageArray, FIR, i ,e)
plt.imshow(img1, cmap='gray')
plt.axis('off')
plt.title('original')
plt.show()
plt.imshow(image1, cmap='gray')
plt.axis('off')
plt.title('Laplacian filter')
plt.show()
plt.imshow(image2, cmap='gray')
plt.axis('off')
plt.title('FIR filter')
plt.show() ```