如何解决在python中导入图像时图像类型会怎样?
PIL,Skimage和matplotlib mping之类的库都产生了相同的结果
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)
对这两个图像应用冷杉滤镜会产生不同的结果
FIR = [[0,-1,0],[-1,5,-1],[0,0]]
img1产生增强的图像,而img2在较暗的区域中丢失一些细节
我不明白为什么默认情况下导入的图像类型会产生如此糟糕的结果,对发生的事情有什么想法吗?
谢谢。
完整代码:
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,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,e)
for i,value in enumerate(row):
if i < (imageSize[0]-3) and e < (imageSize[1]-3):
image2[i+1][e+1] = convolve(imageArray,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() ```
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。