gaussian_functions.py
def gaussian_filter_density(non_zero_points, map_h, map_w, distances=None,
                            kernels_dict=None, min_sigma=2, method=1,
                            const_sigma=15):
    """
    Fast gaussian filter implementation : using precomputed distances and kernels
    """
    gt_count = non_zero_points.shape[0]
    density_map = np.zeros((map_h, map_w), dtype=np.float32)

    for i in range(gt_count):
        point_y, point_x = non_zero_points[i]
        sigma = compute_sigma(gt_count, distances[i], min_sigma=min_sigma,
                              method=method, fixed_sigma=const_sigma)
        closest_sigma = find_closest_key(kernels_dict, sigma)
        kernel = kernels_dict[closest_sigma]
        full_kernel_size = kernel.shape[0]
        kernel_size = full_kernel_size // 2

        # get min and max x and y coordinates for kernel around point
        min_img_x = max(0, point_x - kernel_size)
        min_img_y = max(0, point_y - kernel_size)
        max_img_x = min(point_x + kernel_size + 1, map_h - 1)
        max_img_y = min(point_y + kernel_size + 1, map_w - 1)

        # get slice coordinates of kernel if kernal goes over image boundary
        kernel_x_min = kernel_size - point_x if point_x <= kernel_size else 0
        kernel_y_min = kernel_size - point_y if point_y <= kernel_size else 0
        kernel_x_max = kernel_x_min + max_img_x - min_img_x
        kernel_y_max = kernel_y_min + max_img_y - min_img_y

        # Apply kernel
        density_map[min_img_x:max_img_x, min_img_y:max_img_y] += kernel[kernel_x_min:kernel_x_max, kernel_y_min:kernel_y_max]
    return density_map

    Fast gaussian filter implementation : using precomputed distances and kernels
    
Fast gaussian filter implementation : using precomputed distances and kernels
Fast gaussian filter implementation : using precomputed distances and kernels
def gaussian_filter_density(non_zero_points, map_h, map_w, distances=None,
                            kernels_dict=None, min_sigma=2, method=1,
                            const_sigma=15):
    gt_count = non_zero_points.shape[0]
    density_map = np.zeros((map_h, map_w), dtype=np.float32)
    for i in range(gt_count):
        point_y, point_x = non_zero_points[i]
        sigma = compute_sigma(gt_count, distances[i], min_sigma=min_sigma,
                              method=method, fixed_sigma=const_sigma)
        closest_sigma = find_closest_key(kernels_dict, sigma)
        kernel = kernels_dict[closest_sigma]
        full_kernel_size = kernel.shape[0]
        kernel_size = full_kernel_size // 2
        min_img_x = max(0, point_x - kernel_size)
        min_img_y = max(0, point_y - kernel_size)
        max_img_x = min(point_x + kernel_size + 1, map_h - 1)
        max_img_y = min(point_y + kernel_size + 1, map_w - 1)
        kernel_x_min = kernel_size - point_x if point_x <= kernel_size else 0
        kernel_y_min = kernel_size - point_y if point_y <= kernel_size else 0
        kernel_x_max = kernel_x_min + max_img_x - min_img_x
        kernel_y_max = kernel_y_min + max_img_y - min_img_y
        density_map[min_img_x:max_img_x, min_img_y:max_img_y] += kernel[kernel_x_min:kernel_x_max, kernel_y_min:kernel_y_max]
    return density_map
def gaussian_filter_density ( non_zero_points , map_h , map_w , distances = None , kernels_dict = None , min_sigma = 2 , method = 1 , const_sigma = 15 ) : gt_count = non_zero_points . shape [ 0 ] density_map = np . zeros ( ( map_h , map_w ) , dtype = np . float32 ) for i in range ( gt_count ) : point_y , point_x = non_zero_points [ i ] sigma = compute_sigma ( gt_count , distances [ i ] , min_sigma = min_sigma , method = method , fixed_sigma = const_sigma ) closest_sigma = find_closest_key ( kernels_dict , sigma ) kernel = kernels_dict [ closest_sigma ] full_kernel_size = kernel . shape [ 0 ] kernel_size = full_kernel_size // 2 min_img_x = max ( 0 , point_x - kernel_size ) min_img_y = max ( 0 , point_y - kernel_size ) max_img_x = min ( point_x + kernel_size + 1 , map_h - 1 ) max_img_y = min ( point_y + kernel_size + 1 , map_w - 1 ) kernel_x_min = kernel_size - point_x if point_x <= kernel_size else 0 kernel_y_min = kernel_size - point_y if point_y <= kernel_size else 0 kernel_x_max = kernel_x_min + max_img_x - min_img_x kernel_y_max = kernel_y_min + max_img_y - min_img_y density_map [ min_img_x : max_img_x , min_img_y : max_img_y ] += kernel [ kernel_x_min : kernel_x_max , kernel_y_min : kernel_y_max ] return density_map
Fast gaussian filter implementation : using precomputed distances and kernels
Fast gaussian filter implementation : using precomputed distances and kernels
"""
    Fast gaussian filter implementation : using precomputed distances and kernels
    """ # get min and max x and y coordinates for kernel around point # get slice coordinates of kernel if kernal goes over image boundary # Apply kernel
non_zero_points
map_h
map_w
distances
kernels_dict
min_sigma
method
const_sigma