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

Commit

Permalink
Browse files Browse the repository at this point in the history
Remarks
  • Loading branch information
vessemer committed Jan 26, 2018
1 parent a4f5846 commit f5e1619
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 11 additions & 2 deletions prediction/src/preprocess/preprocess_ct.py
Expand Up @@ -16,7 +16,11 @@ class Params:
If None is set (default), then no lower bound will applied.
clip_upper (int | float): clip the voxels' value to be less or equal to clip_upper.
If None is set (default), then no upper bound will applied.
spacing (boolean): If True, resample CT array according to the meta.spacing.
spacing (float | sequence[float]): re-sample CT array in order to satisfy
the desired spacing (voxel size along the axes).
If a float, `voxel_shape` is the same for each axis.
If a sequence, `voxel_shape` should contain one value for each axis.
If None is set (default), then no re-sampling will applied.
order ({0, 1, 2, 3, 4}): the order of the spline interpolation used by re-sampling.
The default value is 0.
ndim (int): the dimension of CT array, should be greater than 1. The default value is 3.
Expand Down Expand Up @@ -135,11 +139,14 @@ def __call__(self, voxel_data, meta): # noqa: C901
if self.scale is not None:
voxel_data *= self.scale

# `spacing` is the shape of a voxel in real-world units
if self.spacing:
zoom_fctr = meta.spacing / np.asarray(self.spacing)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
voxel_data = scipy.ndimage.interpolation.zoom(voxel_data, zoom_fctr, order=self.order)

# No more need to store the redundant spacing in `meta`
meta.spacing = self.spacing

if self.dtype:
Expand All @@ -152,7 +159,7 @@ def mm_coordinates_to_voxel(coord, meta):
""" Transfer coordinates in mm into voxel's location
Args:
coord (scalar | list[scalar]): coordinates in mm.
coord (scalar | list[scalar]): coordinates in mm (real-world point).
meta (src.preprocess.load_ct.MetaData): meta information of the CT scan.
Returns:
Expand All @@ -165,6 +172,8 @@ def mm_coordinates_to_voxel(coord, meta):
coord = np.array(coord)
origin = scipy.ndimage._ni_support._normalize_sequence(meta.origin, len(coord))
spacing = scipy.ndimage._ni_support._normalize_sequence(meta.spacing, len(coord))

# N-dimensional array coordinates for the point in real world should be computed in the way below:
coord = np.rint((coord - np.array(origin)) / np.array(spacing))

return coord.astype(np.int)
3 changes: 2 additions & 1 deletion prediction/src/tests/test_grt123_preprocess.py
Expand Up @@ -144,7 +144,8 @@ def test_preprocess(metaimage_path):

for nodule in nodule_list:
nod_location = np.array([np.float32(nodule[s]) for s in ["z", "y", "x"]])
nod_location = (nod_location - origin) * spacing
# N-dimensional array coordinates for the point in real world should be computed in the way below:
nod_location = (nod_location - origin) / spacing
cropped_image, coords = crop(image, nod_location)

preprocess = preprocess_ct.PreprocessCT(clip_lower=-1200., clip_upper=600., min_max_normalize=True, scale=255,
Expand Down

0 comments on commit f5e1619

Please sign in to comment.