我试图在DICOM图像中分割圆。我正在尝试用opencv实现hough变换。我得到这个错误:
cv2.error: OpenCV(4.1.0) /Users/travis/build/skvark/opencv-python/opencv/modules/imgproc/src/hough.cpp:1736: error: (-215:Assertion failed) !_image.empty() && _image.type() == CV_8UC1 && (_image.isMat() || _image.isUMat()) in function 'HoughCircles'
代码:
#Segment circle code using openCV
def segment_circles(self):
image = np.float(self.image)
output = image.copy()
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1.2, 100)
if circles is not None:
circles = np.round(circles[0, :].astype("int"))
for (x, y, r) in circles:
cv2.circle(output, (x,y), r, (0, 255, 0), 4)
cv2.rectangle(output, (x - 5, y - 5), (x + 5, y + 5), (0, 128, 255), -1)
cv2.imshow("output", np.hstack([image, output]))
cv2.waitKey(0)
#how self.image is created in another function
self.image = PIL.Image.fromarray(numpy_array)
事先谢谢你的帮助。你知道吗
这是一个可以用来从磁盘读取DICOM文件并执行Hough变换的工作流
当我在我的电脑上用一个真实的MR图像运行这个时,这里是输出。。。你知道吗
当然,Hough变换的结果对你来说是不同的,但是我认为它显示了在真实的DICOM图像上运行cv2 houghcirles函数所必须做的事情。你知道吗
请参阅威尔夫的答案,以获得正确的解决方案。你知道吗
原始代码的快速修复:
我想我应该在“gray=”后面加几行代码。。。“行分别测试这些条件。你确定gray().isEmpty()真的是假的吗?只需一两分钟就可以找出哪些条件无法通过验证测试。你知道吗
图像是什么形态?你知道吗
相关问题 更多 >
编程相关推荐