MrGiovanni / SyntheticTumors

[CVPR 2023] Label-Free Liver Tumor Segmentation
https://www.cs.jhu.edu/~alanlab/Pubs23/hu2023label.pdf
Other
301 stars 26 forks source link

Request for Evaluation of Tumor Detection Performance Code and Small Tumor Detection Assessment #8

Closed koukihk closed 6 months ago

koukihk commented 10 months ago

Hi, Thanks for your great work!

I've been trying to locate code for evaluating tumor detection performance (not segmentation), like sensitivity metrics, but couldn't seem to find it in the repository. If I've overlooked this section, could you kindly point me in the right direction or provide any code related to assessing tumor detection performance?

Additionally, I'm interested in evaluating small tumor detection. If there's any code or guidance related to this aspect within your project, I'd greatly appreciate it.

qixinhu11 commented 6 months ago

Hi, thanks for your interest in this work. The small tumor detection computes the hit number of connected components (by size), I calculate the number and plot the figure somewhere else. The code is a mess and not suitable for the public. I will give you some insights for your request and you can write your version.

import os 
import numpy as np
from scipy import ndimage
import nibabel as nib

def voxel2mm(N, spacing):
    return int(N * np.prod(spacing))

def size2r(size):
    r = np.cbrt(3 * size / (4 * np.pi))
    return r

all_r = []
# [0-5) [5-10) [10-15) [15-20) >= 20
interval_count = [0, 0, 0, 0, 0]
hit_count = [0, 0, 0, 0, 0]

for file in files:
    gt = nib.load(os.path.join(gt_root, file)).get_fdata()
    pred = nib.load(os.path.join(pred_root, file)).get_fdata()

    gt = (gt == 2)
    pred = (pred == 2)

    labels, nb = ndimage.label(gt)
    print(file, nb)
    for idx in range(1, nb+1):
        component = (labels == idx)
        pixel_sum = np.sum(component)
        size = voxel2mm(pixel_sum, (1,1,1))
        r = size2r(size)

        if (pixel_sum > 20): # too small is noise
            size = voxel2mm(pixel_sum, (1,1,1))
            r = size2r(size)
            all_r.append(r)

            pred_hit = np.sum(np.logical_and(pred, component)) > 0  # check if prediction hit this component
            # check r
            if r < 5:
                pos = 0
            elif r >= 5 and r < 10:
                pos = 1
            elif r >= 10 and r < 15:
                pos = 2
            elif r >= 15 and r < 20:
                pos = 3
            else:
                pos = 4

            interval_count[pos] += 1
            hit_count[pos] += pred_hit

            print('[{} {:.1f} {}]'.format(size, r, pred_hit), end='\t')
    print('\n')

print("all count",interval_count)
print("hit",hit_count)

Hope this could help you.