tutorials icon indicating copy to clipboard operation
tutorials copied to clipboard

Where to find medical segmentation decathlon 10 datasets' scaleintensity range?

Open dirtycomputer opened this issue 3 years ago • 5 comments

This ➡️ _ScaleIntensityRanged(keys=["image"], a_min=-87.0, a_max=199.0, b_min=0.0, b_max=1.0, clip=True) is for task07 where to find other 9 dataset intensity range?

train_transforms = Compose( [ LoadImaged(keys=["image", "label"]), EnsureChannelFirstd(keys=["image", "label"]), Orientationd(keys=["image", "label"], axcodes="RAS"), Spacingd(keys=["image", "label"], pixdim=spacing, mode=("bilinear", "nearest"), align_corners=(True, True)), CastToTyped(keys=["image"], dtype=(torch.float32)), ScaleIntensityRanged(keys=["image"], a_min=-87.0, a_max=199.0, b_min=0.0, b_max=1.0, clip=True), CastToTyped(keys=["image", "label"], dtype=(np.float16, np.uint8)), CopyItemsd(keys=["label"], times=1, names=["label4crop"]), Lambdad( keys=["label4crop"], func=lambda x: np.concatenate(tuple([ndimage.binary_dilation((x==_k).astype(x.dtype), iterations=48).astype(float) for _k in range(output_classes)]), axis=0), overwrite=True, ), EnsureTyped(keys=["image", "label"]), CastToTyped(keys=["image"], dtype=(torch.float32)), SpatialPadd(keys=["image", "label", "label4crop"], spatial_size=patch_size, mode=["reflect", "constant", "constant"]), RandCropByLabelClassesd( keys=["image", "label"], label_key="label4crop", num_classes=output_classes, ratios=[1,] * output_classes, spatial_size=patch_size, num_samples=num_patches_per_image ), Lambdad(keys=["label4crop"], func=lambda x: 0), RandRotated(keys=["image", "label"], range_x=0.3, range_y=0.3, range_z=0.3, mode=["bilinear", "nearest"], prob=0.2), RandZoomd(keys=["image", "label"], min_zoom=0.8, max_zoom=1.2, mode=["trilinear", "nearest"], align_corners=[True, None], prob=0.16), RandGaussianSmoothd(keys=["image"], sigma_x=(0.5,1.15), sigma_y=(0.5,1.15), sigma_z=(0.5,1.15), prob=0.15), RandScaleIntensityd(keys=["image"], factors=0.3, prob=0.5), RandShiftIntensityd(keys=["image"], offsets=0.1, prob=0.5), RandGaussianNoised(keys=["image"], std=0.01, prob=0.15), RandFlipd(keys=["image", "label"], spatial_axis=0, prob=0.5), RandFlipd(keys=["image", "label"], spatial_axis=1, prob=0.5), RandFlipd(keys=["image", "label"], spatial_axis=2, prob=0.5), CastToTyped(keys=["image", "label"], dtype=(torch.float32, torch.uint8)), ToTensord(keys=["image", "label"]), ] )

val_transforms = Compose(
    [
        LoadImaged(keys=["image", "label"]),
        EnsureChannelFirstd(keys=["image", "label"]),
        Orientationd(keys=["image", "label"], axcodes="RAS"),
        Spacingd(keys=["image", "label"], pixdim=spacing, mode=("bilinear", "nearest"), align_corners=(True, True)),
        CastToTyped(keys=["image"], dtype=(torch.float32)),
        **_ScaleIntensityRanged(keys=["image"], a_min=-87.0, a_max=199.0, b_min=0.0, b_max=1.0, clip=True),_**
        CastToTyped(keys=["image", "label"], dtype=(np.float32, np.uint8)),
        EnsureTyped(keys=["image", "label"]),
        ToTensord(keys=["image", "label"])
    ]
)

dirtycomputer avatar Sep 19 '22 15:09 dirtycomputer

I use

analyser = DataAnalyzer(sim_datalist, dataroot)
datastat = analyser.get_all_case_stats()
print(datastat.keys())
pprint(datastat["stats_summary"]["image_stats"])

to get {channels: {'max': 1, 'mean': 1.0, 'median': 1.0, 'min': 1, 'percentile': [1, 1, 1, 1], 'percentile_00_5': 1, 'percentile_10_0': 1, 'percentile_90_0': 1, 'percentile_99_5': 1, 'stdev': 0.0}, cropped_shape: {'max': [43, 59, 47], 'mean': [35.37692307692308, 49.98076923076923, 35.65384615384615], 'median': [35.0, 50.0, 36.0], 'min': [31, 40, 24], 'percentile': [[31, 40, 26], [33, 46, 30], [38, 54, 41], [41, 58, 45]], 'percentile_00_5': [31, 40, 26], 'percentile_10_0': [33, 46, 30], 'percentile_90_0': [38, 54, 41], 'percentile_99_5': [41, 58, 45], 'stdev': [1.979764494989571, 3.2539348051207666, 4.210264998898141]}, intensity: {'max': 1704295.25, 'mean': 29411.816703869747, 'median': 29634.744104356032, 'min': 0.0, 'percentile_00_5': 1499.0803447980147, 'percentile_10_0': 10888.021187620896, 'percentile_90_0': 46410.96342914288, 'percentile_99_5': 54237.95997103178, 'stdev': 13406.155988869301}, shape: {'max': [43, 59, 47], 'mean': [35.37692307692308, 49.98076923076923, 35.65384615384615], 'median': [35.0, 50.0, 36.0], 'min': [31, 40, 24], 'percentile': [[31, 40, 26], [33, 46, 30], [38, 54, 41], [41, 58, 45]], 'percentile_00_5': [31, 40, 26], 'percentile_10_0': [33, 46, 30], 'percentile_90_0': [38, 54, 41], 'percentile_99_5': [41, 58, 45], 'stdev': [1.979764494989571, 3.2539348051207666, 4.210264998898141]}, spacing: {'max': [1.0, 1.0, 1.0], 'mean': [1.0, 1.0, 1.0], 'median': [1.0, 1.0, 1.0], 'min': [1.0, 1.0, 1.0], 'percentile': [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]], 'percentile_00_5': [1.0, 1.0, 1.0], 'percentile_10_0': [1.0, 1.0, 1.0], 'percentile_90_0': [1.0, 1.0, 1.0], 'percentile_99_5': [1.0, 1.0, 1.0], 'stdev': [0.0, 0.0, 0.0]}}

dirtycomputer avatar Sep 19 '22 15:09 dirtycomputer

intensity: {'max': 1704295.25, 'mean': 29411.816703869747, 'median': 29634.744104356032, 'min': 0.0,

dirtycomputer avatar Sep 19 '22 15:09 dirtycomputer

'max': 1704295.25 is too high

dirtycomputer avatar Sep 19 '22 15:09 dirtycomputer

Hi @dirtycomputer, you can use DataAnalyzer to analyze given medical image dataset which can return a json include intensity range. https://github.com/Project-MONAI/MONAI/blob/9689abf834f004f49ca59c7fe931caf258da0af7/monai/apps/auto3dseg/data_analyzer.py#L57

from monai.apps.auto3dseg.data_analyzer import DataAnalyzer
datalist = {
    "testing": [{"image": "image_003.nii.gz"}],
    "training": [
        {"fold": 0, "image": "image_001.nii.gz", "label": "label_001.nii.gz"},
        {"fold": 0, "image": "image_002.nii.gz", "label": "label_002.nii.gz"},
        {"fold": 1, "image": "image_001.nii.gz", "label": "label_001.nii.gz"},
        {"fold": 1, "image": "image_004.nii.gz", "label": "label_004.nii.gz"},
    ],
}
dataroot = '/datasets' # the directory where you have the image files (nii.gz)
da = DataAnalyzer(datalist, dataroot, output_path=output_yaml)
da.get_all_case_stats()

Hope it can help you! Thanks!

KumoLiu avatar Sep 20 '22 01:09 KumoLiu

Hi @dirtycomputer , I am not sure if your question was resolved.

I found a relevant discussion here: https://github.com/Project-MONAI/MONAI/discussions/2583

Also, the percentile_99_5 (99.5%) and percentile_00_5 (0.5%) of the foreground image stats (e.g. datastat["stats_summary"]["image_foreground_stats"]) seemed more proper to use, according to this line of code: https://github.com/Project-MONAI/research-contributions/blob/d7bf36c07a0f5882cfddbc7f5aecafea61bf9c39/auto3dseg/algorithm_templates/dints/scripts/algo.py#L91

mingxin-zheng avatar Oct 11 '22 08:10 mingxin-zheng

Hi @dirtycomputer , I will be closing this issue if there is no other follow-up, and please feel free to reopen it if the issue is still bothering you. Thanks!

mingxin-zheng avatar Oct 19 '22 02:10 mingxin-zheng