def test_robust_to_ordering(self, axial_slices): ''' The DICOM slices should be able to be passed in in any order, and they should be recombined appropriately. ''' assert np.array_equal( _merge_slice_pixel_arrays([axial_slices[0], axial_slices[1], axial_slices[2]]), _merge_slice_pixel_arrays([axial_slices[1], axial_slices[0], axial_slices[2]]) ) assert np.array_equal( _merge_slice_pixel_arrays([axial_slices[0], axial_slices[1], axial_slices[2]]), _merge_slice_pixel_arrays([axial_slices[2], axial_slices[0], axial_slices[1]]) )
def test_no_rescale_if_forced_false(self): slice_datasets = [ MockSlice(np.ones((10, 20), dtype=np.uint8), 0, RescaleSlope=2, RescaleIntercept=3) ] voxels = _merge_slice_pixel_arrays(slice_datasets, rescale=False) assert voxels.dtype == np.uint8
def test_robust_to_ordering(self, axial_slices): """ The DICOM slices should be able to be passed in in any order, and they should be recombined appropriately using the sort function. """ assert np.array_equal( _merge_slice_pixel_arrays( sort_by_slice_position( [axial_slices[0], axial_slices[1], axial_slices[2]])), _merge_slice_pixel_arrays( sort_by_slice_position( [axial_slices[1], axial_slices[0], axial_slices[2]]))) assert np.array_equal( _merge_slice_pixel_arrays( sort_by_instance_number( [axial_slices[0], axial_slices[1], axial_slices[2]])), _merge_slice_pixel_arrays( sort_by_instance_number( [axial_slices[2], axial_slices[0], axial_slices[1]])))
def test_casting_rescale_slope_and_intercept(self): ''' Some DICOM modules contain the `RescaleSlope` and `RescaleIntercept` DICOM attributes. ''' slices = [ MockSlice(np.ones((10, 20), dtype=np.uint8), 0, RescaleSlope=2, RescaleIntercept=3), MockSlice(np.ones((10, 20), dtype=np.uint8), 1, RescaleSlope=2, RescaleIntercept=3), ] voxels = _merge_slice_pixel_arrays(slices) assert voxels.dtype == np.dtype('float32') assert voxels[0, 0, 0] == 5.0
def test_casting_if_only_rescale_slope(self): ''' If the `RescaleSlope` DICOM attribute is present, the `RescaleIntercept` attribute should also be present, however, we handle this case anyway. ''' slices = [ MockSlice(np.ones((10, 20), dtype=np.uint8), 0, RescaleSlope=2), MockSlice(np.ones((10, 20), dtype=np.uint8), 1, RescaleSlope=2), ] voxels = _merge_slice_pixel_arrays(slices) assert voxels.dtype == np.dtype('float32') assert voxels[0, 0, 0] == 2.0
def test_rescales_if_forced_true(self): slice_datasets = [MockSlice(np.ones((10, 20), dtype=np.uint8), 0)] voxels = _merge_slice_pixel_arrays(slice_datasets, rescale=True) assert voxels.dtype == np.float32