Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

def correlation(image, angrange, brange, sigma): imgsize = image.shape xsize =…

  1. User

    def correlation(image, angrange, brange, sigma): imgsize = image.shape

    xsize = imgsize[1]
    ysize = imgsize[0]
    subimage = image.astype(np.float32)
    
    medianint = np.median(image[image > 0])
    angles = np.arange(angrange[0], angrange[2] + 1, angrange[1])
    trans = np.arange(brange[0], brange[2] + 1, brange[1])
    corrmap = np.zeros((len(angles), len(trans)))
    
    for thetaind in range(len(angles)):
        for bind in range(len(trans)):
            theta = angles[thetaind]
            b = trans[bind]
            refline = reference_line_gen(xsize, ysize, theta, b, sigma)
            temp = refline * subimage
            temp2 = np.sum(temp)
            temp3 = temp2 / medianint
            corrmap[thetaind, bind] = temp3
    
    return corrmap
    

    def reference_line_gen(xsize, ysize, theta, b, sigma): Xmesh, Ymesh = np.meshgrid(np.arange(1, xsize+1), np.arange(1, ysize+1)) Xmesh = Xmesh - xsize / 2 Ymesh = Ymesh - ysize / 2

    angle = np.radians(theta)
    dist = b - (Xmesh * np.sin(angle)) - (Ymesh * np.cos(angle))
    distance = (dist ** 2) / (sigma ** 2)
    result = np.exp(-distance)
    
    return result
    

    def max_intensity_finding(correlation_map, dist_input=10): size_corr = correlation_map.shape label_map = np.zeros(size_corr) xgrid, ygrid = np.meshgrid(np.arange(1, size_corr[1]+1), np.arange(1, size_corr[0]+1))

    for indx in range(size_corr[1]):
        for indy in range(size_corr[0]):
            dist = np.sqrt((xgrid - indx)**2 + (ygrid - indy)**2)
            pixuseful = dist < dist_input
            if correlation_map[indy, indx] >= np.max(correlation_map[pixuseful]):
                label_map[indy, indx] = 1
    
    label_map[correlation_map == 0] = 0
    
    return label_map
    

    Загрузка изображения и предварительная обработка

    image = cv2.imread("0.0/01.gpm", cv2.COLOR_BGR2GRAY)

    image = cv2.GaussianBlur(image, (3, 3), 0)

    Параметры алгоритма

    angrange = [0, 5, 45] # Диапазон углов brange = [-10, 1, 10] # Диапазон сдвигов sigma = 1.0 # Сигма для функции расстояния

    Вызов алгоритма

    corr_map = correlation(image, angrange, brange, sigma) label_map = max_intensity_finding(corr_map)

    Визуализация результатов

    plt.imshow(corr_map) plt.show() plt.imshow(label_map) plt.show()


    error Traceback (most recent call last) in <cell line: 57>() 55 image = cv2.imread("0.0/01.gpm", cv2.COLOR_BGR2GRAY) 56 ---> 57 image = cv2.GaussianBlur(image, (3, 3), 0) 58 59 # Параметры алгоритма

    error: OpenCV(4.8.0) /io/opencv/modules/imgproc/src/smooth.dispatch.cpp:617: error: (-215:Assertion failed) !_src.empty() in function 'GaussianBlur' исправь ошибку

  2. Assistant

    Ошибка возникает из-за того, что функция cv2.GaussianBlur() не может обработать пустое изображение. Вам нужно проверить, правильно ли загружено изображение, и убедиться, что оно не является пустым.