在 Python 中绘制霍夫空间

问题描述

我使用以下代码在超声图像上生成霍夫线:

image = mpimg.imread("img.png")
data = np.array(image)
num_lines = 0

gray_image = cv2.cvtColor((image*255).astype(np.uint8),cv2.COLOR_RGB2GRAY)
blurred_image = cv2.GaussianBlur(gray_image,(9,9),0)
edges_image = cv2.Canny(blurred_image,50,120)

def draw_lines(img,houghlines,color=[0,255,0],thickness=2):
    global num_lines
    for line in houghlines:
        num_lines += 1
        for rho,theta in line:
            a = np.cos(theta)
            b = np.sin(theta)
            x0 = a*rho
            y0 = b*rho
            x1 = int(x0 + 1000*(-b))
            y1 = int(y0 + 1000*(a))
            x2 = int(x0 - 1000*(-b))
            y2 = int(y0 - 1000*(a))
 
            cv2.line(img,(x1,y1),(x2,y2),color,thickness)   
                
 
def weighted_img(img,initial_img,α=0.8,β=1.,λ=0.):
    return cv2.addWeighted(initial_img,α,img,β,λ) #blending or transparency

rho_resolution = 1
theta_resolution = np.pi/180
threshold = 145

h_lines = cv2.houghlines(edges_image,rho_resolution,theta_resolution,threshold)
 
    
#draw lines    
h_lines_image = np.zeros_like(image) #array of zeros
draw_lines(h_lines_image,h_lines)
image_hough = weighted_img(h_lines_image,image) #blending or transparency

但它不会产生输出来可视化霍夫空间中的点,例如此示例中的底部绘图:

enter image description here

我已经按照 this post 中的图片示例进行操作,但出现以下错误

'ValueError: The truth value of an array with more than one element is ambiguous.'

为了

for j,pixel in enumerate(row):   
            if pixel != val : continue

IndexError: only integers,slices (`:`),ellipsis (`...`),numpy.newaxis (`None`) and integer or boolean arrays are valid indices

为了

feature_space[i,d] += 1

任何帮助将不胜感激!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...