-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support channeled dicom slices #16
Changes from 5 commits
9b29a87
cb0d926
1ab1954
7cc1961
899d277
6a8b0b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -11,6 +11,7 @@ | |||||
negative_z_cos = (0, 0, -1) | ||||||
|
||||||
arbitrary_shape = (10, 11) | ||||||
arbitrary_rgb_shape = (10, 11, 3) | ||||||
|
||||||
|
||||||
class MockSlice: | ||||||
|
@@ -28,15 +29,21 @@ def __init__(self, pixel_array, slice_position, row_cosine=None, column_cosine=N | |||||
if column_cosine is None: | ||||||
column_cosine = y_cos | ||||||
|
||||||
na, nb = pixel_array.shape | ||||||
shape = pixel_array.shape | ||||||
if len(shape) == 2: | ||||||
na, nb = shape | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
SamplesPerPixel = 1 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||||||
else: | ||||||
na, nb, SamplesPerPixel = shape | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 except of the order: |
||||||
|
||||||
self.pixel_array = pixel_array | ||||||
|
||||||
self.SeriesInstanceUID = 'arbitrary uid' | ||||||
self.SOPClassUID = 'arbitrary sopclass uid' | ||||||
self.PixelSpacing = [1.0, 1.0] | ||||||
self.Rows = na | ||||||
self.Columns = nb | ||||||
self.Columns = na | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that your code appears to swap
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 for naming, but the swap is intentional: |
||||||
self.Rows = nb | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||||||
self.SamplesPerPixel = SamplesPerPixel | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||||||
self.Modality = 'MR' | ||||||
|
||||||
# assume that the images are centered on the remaining unused axis | ||||||
|
@@ -63,5 +70,16 @@ def axial_slices(): | |||||
] | ||||||
|
||||||
|
||||||
@pytest.fixture | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||||||
def axial_rgb_slices(): | ||||||
# SamplesPerPixel = 3 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The purpose and meaning of this comment wasn't entirely clear to me There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, unnecessary - removed |
||||||
return [ | ||||||
MockSlice(randi(*arbitrary_rgb_shape), 0), | ||||||
MockSlice(randi(*arbitrary_rgb_shape), 1), | ||||||
MockSlice(randi(*arbitrary_rgb_shape), 2), | ||||||
MockSlice(randi(*arbitrary_rgb_shape), 3), | ||||||
] | ||||||
|
||||||
|
||||||
def randi(*shape): | ||||||
return np.random.randint(1000, size=shape, dtype='uint16') |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -30,6 +30,12 @@ def test_single_slice_spacing(self, axial_slices): | |||
assert np.array_equal(array, dataset.pixel_array.T[:, :, None]) | ||||
assert np.isclose(np.linalg.norm(affine[:, 2]), np.abs(slice_spacing)) | ||||
|
||||
def test_rgb_axial_set(self, axial_rgb_slices): | ||||
combined, _ = combine_slices(axial_rgb_slices) | ||||
|
||||
manually_combined = np.stack([ds.pixel_array for ds in axial_rgb_slices], axis=0).T | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the transpose expected? Perhaps it was necessary because of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is expected because we return the transposed pixel array: dicom-numpy/dicom_numpy/combine_slices.py Line 98 in f0cc77d
With more convenient shape: voxels.shape == (num_rows, num_columns, num_slices) Or: voxels.shape == (num_channels, num_rows, num_columns, num_slices)
|
||||
assert np.array_equal(combined, manually_combined) | ||||
|
||||
|
||||
class TestMergeSlicePixelArrays: | ||||
def test_casting_if_only_rescale_slope(self): | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I won't have a chance to read through this in detail until later, but two comments:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW thanks for making a PR for this---it will definitely make dicom-numpy more useful and generic!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My pleasure :)
Rows
,Columns
,BitsStored
- the attributeSamplesPerPixel
is necessary for calculatingpixel_array
(and its shape) fromPixelData
. If there are some slices with different shape, they cannot be combined.The current error will be something related to numpy's incompatible shapes.
In order to avoid it, maybe we should add
SamplesPerPixel
to theinvariant_properties
list? (in_validate_slices_form_uniform_grid
)