超分辨率分割SLIC算法实现过程遇到的问题,shape mismatch: value array of shape (3,) could not be broadcast to indexing

本文详细介绍了使用Python实现超分辨率分割SLIC算法过程中遇到的三个问题及其解决方案:1) 缺少命令行参数-i的正确使用;2) scipy库的DLL加载失败,通过卸载并重新安装scipy解决;3) 图像格式不匹配导致的形状不匹配错误,通过将skimage的io.imread替换为cv2.imread修复。同时,提供了参考代码和报错信息。
摘要由CSDN通过智能技术生成

超分辨率分割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

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值