D:\python3.8\python.exe D:/pythonProject1/图像增强.py Traceback (most recent call last): File "D:/pythonProject1/图像增强.py", line 17, in <module> io.imshow('Equalized Image', equ) File "D:\python3.8\lib\site-packages\skimage\io\_io.py", line 165, in imshow arr = call_plugin('imread', arr, plugin=plugin) File "D:\python3.8\lib\site-packages\skimage\io\manage_plugins.py", line 200, in call_plugin _load(plugin) File "D:\python3.8\lib\site-packages\skimage\io\manage_plugins.py", line 287, in _load if plugin in find_available_plugins(loaded=True): TypeError: unhashable type: 'numpy.ndarray' 进程已结束,退出代码1
时间: 2023-07-21 21:05:54 浏览: 153
这个错误是因为在调用`io.imshow`时,传递了一个`numpy.ndarray`类型的参数,但该参数是不可哈希的,因此无法在`find_available_plugins`函数中使用。解决方法是将传递给`io.imshow`的参数转换为可哈希的类型,例如使用`tuple`类型来包装数组。你可以尝试这样修改代码:
```
from skimage import io, exposure
# 读取图像
image = io.imread('example.jpg')
# 直方图均衡化
equ = exposure.equalize_hist(image)
# 显示原图和处理后的图像
io.imshow((equ * 255).astype('uint8'))
io.show()
```
这里将数组先乘以255,然后转换为`uint8`类型,最后使用`tuple`类型包装数组,传递给`io.imshow`函数。
相关问题
D:\python3.8\python.exe D:/pythonProject1/图像增强.py Traceback (most recent call last): File "D:/pythonProject1/图像增强.py", line 18, in <module> new_image = img_contrast_bright(img, a, b, g) File "D:/pythonProject1/图像增强.py", line 8, in img_contrast_bright dst = cv.addWeighted(img, a,blank,b,g) NameError: name 'cv' is not defined 进程已结束,退出代码1
这个错误提示告诉我们在图像增强.py文件中第8行的cv未被定义。这通常是因为OpenCV库没有被正确导入所致。你需要在文件开头添加以下代码来导入OpenCV库:
```
import cv2 as cv
```
这应该可以解决这个问题。
D:\python3.8\python.exe D:/pythonProject1/canny.py Traceback (most recent call last): File "D:/pythonProject1/canny.py", line 26, in <module> img_canny = canny(gray_smoothed, low_threshold, high_threshold) File "D:\python3.8\lib\site-packages\skimage\feature\_canny.py", line 314, in canny raise ValueError("low_threshold should be lower then high_threshold") ValueError: low_threshold should be lower then high_threshold 进程已结束,退出代码1
这个错误提示是因为你在调用canny函数时,传入的低阈值参数小于了高阈值参数。可以检查一下你传入的参数是否正确,或者尝试交换一下参数的位置。下面是一个示例代码:
```python
import cv2
import numpy as np
def canny(image, low_threshold, high_threshold):
return cv2.Canny(image, low_threshold, high_threshold)
if __name__ == '__main__':
img = cv2.imread('test.jpg', 0)
gray_smoothed = cv2.GaussianBlur(img, (3, 3), 0)
low_threshold = 50
high_threshold = 150
img_canny = canny(gray_smoothed, low_threshold, high_threshold)
cv2.imshow('Canny', img_canny)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
你可以将上述代码保存为canny.py,并且将一张图片命名为test.jpg放在相同的目录下,然后运行代码。
阅读全文