Exemple #1
0
def create_random_suppressed(shape=(356, 299), radius=10, noise=.1, n_rays=32, nms_thresh=.4):
    prob, dist = create_random_data(shape, radius, noise, n_rays)
    coord = dist_to_coord(dist)
    nms = non_maximum_suppression(coord, prob, prob_thresh=0.9,
                                  nms_thresh=nms_thresh,
                                  verbose=True)
    return nms
Exemple #2
0
def test_bbox_search(img):
    prob = edt_prob(img)
    dist = star_dist(img, n_rays=32, mode="cpp")
    coord = dist_to_coord(dist)
    nms_a = non_maximum_suppression(
        coord, prob, prob_thresh=0.4, verbose=False, max_bbox_search=False)
    nms_b = non_maximum_suppression(
        coord, prob, prob_thresh=0.4, verbose=False, max_bbox_search=True)
    check_similar(nms_a, nms_b)
Exemple #3
0
def test_acc(img):
    prob = edt_prob(img)
    dist = star_dist(img, n_rays=32, mode="cpp")
    coord = dist_to_coord(dist)
    points = non_maximum_suppression(coord, prob, prob_thresh=0.4)
    img2 = polygons_to_label(coord, prob, points, shape=img.shape)
    m = matching(img, img2)
    acc = m.accuracy
    print("accuracy {acc:.2f}".format(acc=acc))
    assert acc > 0.9
Exemple #4
0
def _star_convex_polynoms(dapi_path,
                          membrane_dic,
                          model_path,
                          full_output=False):
    """Nuclei segmentation using the stardist algorithm.

    Parameters
    ----------
    dapi_path : string
      path to the DAPI image
    membrane_dic: dic obtained with extract_membranes.
      Dictionnary containing relevant informations about the membranes.
    model_path : string
      path to the stardist model

    Returns
    -------

    clockwise_centers : np.ndarray
      An array of cell centers, sort in clockwise order.
    """
    images = sorted(glob(dapi_path))
    images = list(map(imread, images))
    img = normalize(images[0], 1, 99.8)
    model_sc = StarDist2D(None,
                          name="stardist_shape_completion",
                          basedir=model_path)
    prob, dist = model_sc.predict(img)
    coord = dist_to_coord(dist)
    points = non_maximum_suppression(coord, prob, prob_thresh=0.4)
    points = np.flip(points, 1)

    rho, phi = _card_coords(points, membrane_dic["center_inside"])
    cleaned = _quick_del_art(points, rho, membrane_dic["rIn"])
    clockwise_centers = _quick_clockwise(cleaned, phi, rho,
                                         membrane_dic["rIn"])

    clockwise_centers = np.subtract(np.float32(clockwise_centers),
                                    np.array(membrane_dic["img_shape"]) / 2.0)
    if full_output:
        return clockwise_centers, (prob, dist, points)

    return clockwise_centers
    plt.show()
        
def predictions(model_dist,i):
    img = normalize(X[i],1,99.8,axis=axis_norm)
    input = torch.tensor(img)
    input = input.unsqueeze(0).unsqueeze(0)#unsqueeze 2 times
    dist,prob = model_dist(input)
    dist_numpy= dist.detach().cpu().numpy().squeeze()
    prob_numpy= prob.detach().cpu().numpy().squeeze()
    return dist_numpy,prob_numpy
    
model_dist = UNet(1,N_RAYS)
model_dist.load_state_dict(torch.load(MODEL_WEIGHTS_PATH))
print('Distance weights loaded')

apscore_nms = []
prob_thres = 0.4
for idx,img_target in enumerate(zip(X,Y)):
    print(idx)
    image,target = img_target
    dists,probs=predictions(model_dist,idx)
    dists = np.transpose(dists,(1,2,0))
    coord = dist_to_coord(dists)
    points = non_maximum_suppression(coord,probs,prob_thresh=prob_thres)
    star_label = polygons_to_label(coord,probs,points)
    apscore_nms.append(metric.calculateAPScore(star_label,target,IOU_tau=0.5))
    #plot(target,star_label) 
print('Total images',idx+1)
ap_nms = sum(apscore_nms)/(len(apscore_nms))
print('AP NMS',ap_nms)