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

Further segmentation efficiency improvements #285

Merged
merged 13 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 16 additions & 6 deletions src/highdicom/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import numpy as np
from pydicom.dataset import Dataset
from pydicom import DataElement
from pydicom.sequence import Sequence as DataElementSequence
from pydicom.sr.coding import Code
from pydicom.sr.codedict import codes
Expand Down Expand Up @@ -469,18 +470,27 @@ def __init__(
'Position in Pixel Matrix must be specified for '
'slide coordinate system.'
)
col_position, row_position = pixel_matrix_position
x, y, z = image_position
item.XOffsetInSlideCoordinateSystem = DS(x, auto_format=True)
item.YOffsetInSlideCoordinateSystem = DS(y, auto_format=True)
item.ZOffsetInSlideCoordinateSystem = DS(z, auto_format=True)
col_position, row_position = pixel_matrix_position
if row_position < 0 or col_position < 0:
raise ValueError(
'Both items in "pixel_matrix_position" must be positive '
'integers.'
)
item.RowPositionInTotalImagePixelMatrix = row_position
item.ColumnPositionInTotalImagePixelMatrix = col_position

# Use hard-coded tags to avoid the keywork dictionary lookup
# (this constructor is called a large number of times in large
# multiframe images, so some optimization makes sense)
x_tag = 0x0040072a # XOffsetInSlideCoordinateSystem
y_tag = 0x0040073a # YOffsetInSlideCoordinateSystem
z_tag = 0x0040074a # ZOffsetInSlideCoordinateSystem
row_tag = 0x0048021f # RowPositionInTotalImagePixelMatrix
column_tag = 0x0048021e # ColumnPositionInTotalImagePixelMatrix
item.add(DataElement(x_tag, 'DS', DS(x, auto_format=True)))
item.add(DataElement(y_tag, 'DS', DS(y, auto_format=True)))
item.add(DataElement(z_tag, 'DS', DS(z, auto_format=True)))
item.add(DataElement(row_tag, 'SL', int(row_position)))
item.add(DataElement(column_tag, 'SL', int(col_position)))
elif coordinate_system == CoordinateSystemNames.PATIENT:
item.ImagePositionPatient = [
DS(ip, auto_format=True) for ip in image_position
Expand Down
18 changes: 9 additions & 9 deletions src/highdicom/seg/pyramid.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,16 +336,16 @@ def create_segmentation_pyramid(
if n_pix_arrays > 1:
pixel_array = pixel_arrays[output_level]
else:
need_resize = True
if n_sources > 1:
output_size = (
source_image.TotalPixelMatrixColumns,
source_image.TotalPixelMatrixRows
)
if output_level == 0:
pixel_array = pixel_arrays[0]
need_resize = False
else:
if output_level == 0:
pixel_array = pixel_arrays[0]
need_resize = False
need_resize = True
if n_sources > 1:
output_size = (
source_image.TotalPixelMatrixColumns,
source_image.TotalPixelMatrixRows
)
else:
f = downsample_factors[output_level - 1]
output_size = (
Expand Down
Loading