在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在较暗的区域中丢失一些细节

output of the two processes

我不明白为什么默认情况下导入的图像类型会产生如此糟糕的结果,对发生的事情有什么想法吗?

谢谢。

完整代码:

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 (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...