Skip to content
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

Minor fixes to segmentation #195

Merged
merged 2 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Derive a Segmentation image from a multi-frame Slide Microscopy (SM) image:
)

# Create the Segmentation instance
seg_dataset = Segmentation(
seg_dataset = hd.seg.Segmentation(
source_images=[image_dataset],
pixel_array=mask,
segmentation_type=hd.seg.SegmentationTypeValues.BINARY,
Expand Down
13 changes: 2 additions & 11 deletions src/highdicom/seg/sop.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ def __init__(

if pixel_array.ndim == 2:
pixel_array = pixel_array[np.newaxis, ...]
if pixel_array.ndim not in [3, 4]:
raise ValueError('Pixel array must be a 2D, 3D, or 4D array.')

super().__init__(
study_instance_uid=src_img.StudyInstanceUID,
Expand Down Expand Up @@ -568,17 +570,6 @@ def __init__(
self.NumberOfFrames = 0
self.PerFrameFunctionalGroupsSequence: List[Dataset] = []

if pixel_array.ndim == 2:
pixel_array = pixel_array[np.newaxis, ...]
Comment on lines -571 to -572
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is duplicated from above

if pixel_array.ndim not in [3, 4]:
raise ValueError('Pixel array must be a 2D, 3D, or 4D array.')
Comment on lines -573 to -574
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moving this earlier simplifies things a bit


if pixel_array.shape[1:3] != (self.Rows, self.Columns):
raise ValueError(
'Pixel array representing segments has the wrong number of '
'rows and columns.'
)
Comment on lines -576 to -580
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is true by construction of the self.Rows and self.Columns, so the check is pointless


# Check segment numbers
described_segment_numbers = np.array([
int(item.SegmentNumber)
Expand Down