Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

169 | 4 MetaData and PreprocessCT refactored, grt123 processing adopted #170

Merged
merged 2 commits into from
Oct 19, 2017

Conversation

vessemer
Copy link
Contributor

@vessemer vessemer commented Oct 17, 2017

Refactored classes PreprocessCT and MetaData. Preprocessing of grt123 algorithm has been replaced by them.

Description

PreprocessCT is now a subclass of Params, both are documented along with MetaData.
Correct me if I've mistaken, but there is a bug in the processing part of the grt123 prediction algorithm adoptation:

image = sitk.GetArrayFromImage(image_itk)
spacing = np.array(image_itk.GetSpacing())[::-1]  
image = lum_trans(image)
image = resample(image, spacing, np.array([1, 1, 1]), order=1)[0]
  • spacing will became redundant after re-sampling.
for nodule in nodule_list:
    print(nodule)
    nod_location = np.array([np.float32(nodule[s]) for s in ["z", "y", "x"]])
    nod_location *= spacing 
  • estimation of the nod_location should also take into account both the origin of the CT scan and new_spacing = [1, 1, 1] and therefore shal looks like
nod_location = (nod_location - origin) / new_spacing

Neglection of the origin and new_spacing leads to estimation of a complitely different CT part.

  • the old estimation of patches by SimpleCrop requires np.pad to be applied on each patch independently for the same CT scan.

The aforementioned bugs were corrected along with the adoptation of grt123 preprocessing via preprocess_ct.py

Reference to official issue

This addresses #169 and partially covers #4

How Has This Been Tested?

For the grt123_preprocess, all tests lie in test_grt123_preprocess and are written in order to ensure fully interchangeability.

CLA

  • I have signed the CLA; if other committers are in the commit history, they have signed the CLA as well

@vessemer vessemer changed the title 169 MetaData and PreprocessCT refactored 4 grt123 169 | 4 MetaData and PreprocessCT refactored, grt123 processing adopted Oct 17, 2017
@@ -288,23 +242,17 @@ def predict(image_itk, nodule_list, model_path="src/algorithms/classify/assets/g

if torch.cuda.is_available():
casenet = torch.nn.DataParallel(casenet).cuda()
# else:
# else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if the indentation level is now correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :)

@vessemer vessemer force-pushed the 169_metadata_refactoring branch 2 times, most recently from 1c51d07 to 92addb1 Compare October 17, 2017 07:21
@@ -21,10 +21,12 @@ def mm2voxel(coord, origin=0., spacing=1.):
origin = scipy.ndimage._ni_support._normalize_sequence(origin, len(coord))
spacing = scipy.ndimage._ni_support._normalize_sequence(spacing, len(coord))
coord = np.ceil(coord - np.array(origin)) / np.array(spacing)
print(coord)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Committed by accident?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep

import numpy as np
import scipy.ndimage
from src.preprocess import load_ct


class Params:
"""Params for CT data preprocessing.
"""Params for CT data pre-processing.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try and make these sorts of changes in a separate commit in future.. much easier to review :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thank you for the review :)

@@ -52,61 +59,81 @@ def __init__(self, hu_transform=False, clip_lower=None, clip_upper=None,
raise ValueError('The min_max_normalize should be bool or int')
self.min_max_normalize = min_max_normalize

if not isinstance(scale, (int, float)) and (scale is not None):
raise ValueError('The scale should be float or int')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeError would seem more suitable here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed it is.


class PreprocessCT:
if dtype not in np.typeDict.keys() and (dtype is not None):
raise ValueError('The dtype should be one of appropriate np.dtype')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(ditto)

assert all([m_axis == o_axis for m_axis, o_axis in zipped])

meta = load_ct.load_ct(metaimage_path, voxel=False)
spacing = list(reversed(meta.GetSpacing()))
spacing = meta.GetSpacing()[::-1]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SimpleITK reads CT scan array from MetaImages in zyx order, methods like GetSpacing | GetOrigin return values in xyz order, though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add this as a comment in the code? :)

@vessemer vessemer force-pushed the 169_metadata_refactoring branch 7 times, most recently from 14543c3 to 389824f Compare October 18, 2017 03:06
self.stride = 4
self.filling_value = 160

def __call__(self, imgs, target):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda gross to abuse dunderscore call. I'm assuming this code is from elsewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this code had been taken from the edited version of the original SimpleCrop class. I've put unchanged functions into test_grt123_preprocess.py in order to ensure absolute interchangeability.

@vessemer vessemer force-pushed the 169_metadata_refactoring branch from 389824f to 1acd7c7 Compare October 19, 2017 11:23
@lamby lamby merged commit 81972cc into drivendataorg:master Oct 19, 2017
@lamby
Copy link
Contributor

lamby commented Oct 19, 2017

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants