超分辨率分割SLIC算法实现过程遇到的问题
shape mismatch: value array of shape (3,) could not be broadcast to indexing result of shape (9360,4)图像不匹配报错的解决方法
代码
coding=utf-8
导入相应的python包
import argparse
from skimage import io
import matplotlib.pyplot as plt
from skimage.segmentation import slic
from skimage.util import img_as_float
from skimage.segmentation import mark_boundaries
设置并解析参数
ap = argparse.ArgumentParser()
ap.add_argument(“-i”, “–image”, required = True, help = “Path to the image”)
args = vars(ap.parse_args())
读取图片并将其转化为浮点型
image = img_as_float(io.imread(args[“image”]))
循环设置不同的超像素组
for numSegments in (100, 200, 300):
# 应用slic算法并获取分割结果
segments = slic(image, n_segments = numSegments, sigma = 5)
# 绘制结果
fig = plt.figure("Superpixels -- %d segments" % (numSegments))
ax = fig.add_subplot(1, 1, 1)
ax.imshow(mark_boundaries(image, segments))
plt.axis("off")
显示结果
plt.show()
效果图
报错1
usage: dhxhk.py [-h] -i IMAGE
dhxhk.py: error: the following arguments are required: -i/–image
解决方案在命令行里输入
python D:\pythonProject\chaofenge\dhxhk.py --image D:\pythonProject\chaofenge\45.png
就可以了
报错2
DLL load failed while importing _arpack: 找不到指定的程序。
pip uninstall scipy
pip install scipy -i https://pypi.douban.com/simple
在命令行里卸载重新安装scipy
报错3
shape mismatch: value array of shape (3,) could not be broadcast to indexing result of shape (9360,4)
图片格式不匹配的解决方法
image = img_as_float(io.imread(args[“image”]))
image = img_as_float(cv2.imread(args[“image”]))
io.改成cv2.就可以了
别忘了import cv2
代码参考
https://blog.csdn.net/WZZ18191171661/article/details/91039457