Skip to content

Commit 38f848a

Browse files
fix: make FrameView width & height work for DICOM (#1036)
1 parent 12ba12a commit 38f848a

File tree

2 files changed

+363
-44
lines changed

2 files changed

+363
-44
lines changed

encord/objects/ontology_labels_impl.py

Lines changed: 20 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,59 +1264,25 @@ def __init__(self, images_data: LabelRowV2.LabelRowReadOnlyDataImagesDataEntry):
12641264
@property
12651265
def title(self) -> str:
12661266
return self._image_data.title
1267-
"""
1268-
Get the title of the image.
1269-
1270-
Returns:
1271-
str: The image title.
1272-
"""
12731267

12741268
@property
12751269
def file_type(self) -> str:
12761270
return self._image_data.file_type
1277-
"""
1278-
Get the file type of the image.
1279-
1280-
Returns:
1281-
str: The image file type.
1282-
"""
12831271

12841272
@property
12851273
def width(self) -> int:
12861274
return self._image_data.width
1287-
"""
1288-
Get the width of the image.
1289-
1290-
Returns:
1291-
int: The image width.
1292-
"""
12931275

12941276
@property
12951277
def height(self) -> int:
12961278
return self._image_data.height
1297-
"""
1298-
Get the height of the image.
1299-
1300-
Returns:
1301-
int: The image height.
1302-
"""
13031279

13041280
@property
13051281
def image_hash(self) -> str:
1306-
"""Get the hash of the image.
1307-
1308-
Returns:
1309-
str: The image hash.
1310-
"""
13111282
return self._image_data.image_hash
13121283

13131284
@property
13141285
def frame_number(self) -> int:
1315-
"""Get the frame number.
1316-
1317-
Returns:
1318-
int: The frame number.
1319-
"""
13201286
return self._image_data.index
13211287

13221288
class FrameView:
@@ -1384,33 +1350,43 @@ def frame(self) -> int:
13841350

13851351
@property
13861352
def width(self) -> int:
1387-
"""Get the width of the image or image group.
1388-
1389-
Returns:
1390-
int: The width of the image or image group.
1353+
"""Get the width of the frame.
13911354
13921355
Raises:
13931356
LabelRowError: If the width is not set for the data type.
13941357
"""
1395-
if self._label_row.data_type in [DataType.IMG_GROUP]:
1358+
if self._label_row.data_type == DataType.IMG_GROUP:
13961359
return self._frame_level_data().width
1360+
elif self._label_row.data_type == DataType.DICOM:
1361+
frame_metadata = self._label_row._frame_metadata[self._frame]
1362+
if frame_metadata is not None:
1363+
return frame_metadata.width
1364+
elif self._label_row_read_only_data.width is not None:
1365+
return self._label_row_read_only_data.width
1366+
else:
1367+
raise LabelRowError(f"Width is expected but not set for the data type {self._label_row.data_type}")
13971368
elif self._label_row_read_only_data.width is not None:
13981369
return self._label_row_read_only_data.width
13991370
else:
14001371
raise LabelRowError(f"Width is expected but not set for the data type {self._label_row.data_type}")
14011372

14021373
@property
14031374
def height(self) -> int:
1404-
"""Get the height of the image or image group.
1405-
1406-
Returns:
1407-
int: The height of the image or image group.
1375+
"""Get the height of the frame.
14081376
14091377
Raises:
14101378
LabelRowError: If the height is not set for the data type.
14111379
"""
1412-
if self._label_row.data_type in [DataType.IMG_GROUP]:
1380+
if self._label_row.data_type == DataType.IMG_GROUP:
14131381
return self._frame_level_data().height
1382+
elif self._label_row.data_type == DataType.DICOM:
1383+
frame_metadata = self._label_row._frame_metadata[self._frame]
1384+
if frame_metadata is not None:
1385+
return frame_metadata.height
1386+
elif self._label_row_read_only_data.height is not None:
1387+
return self._label_row_read_only_data.height
1388+
else:
1389+
raise LabelRowError(f"Height is expected but not set for the data type {self._label_row.data_type}")
14141390
elif self._label_row_read_only_data.height is not None:
14151391
return self._label_row_read_only_data.height
14161392
else:

0 commit comments

Comments
 (0)