Skip to content

Commit e6cd9b5

Browse files
committed
Use 16-bit mode, not coloration, to check for RCM images
1 parent 0fd2bb9 commit e6cd9b5

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

isic/ingest/models/accession.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,7 @@ def generate_blob(self): # noqa: PLR0915
527527
self.height = img.height
528528
self.width = img.width
529529

530-
is_rcm = not self.is_color(img)
531-
530+
is_rcm = img.mode.startswith("I;16")
532531
if is_rcm:
533532
self.is_cog = self.meets_cog_threshold(img)
534533
if self.is_cog:
@@ -542,6 +541,8 @@ def generate_blob(self): # noqa: PLR0915
542541
else:
543542
if self.meets_cog_threshold(img):
544543
raise InvalidBlobError("Blob is too large to be stored.") # noqa: TRY301
544+
if not img.mode.startswith("RGB"):
545+
raise InvalidBlobError("Blob has non-RGB mode.") # noqa: TRY301
545546
self.is_cog = False
546547
converter = self._convert_blob_to_rgb
547548
converted_blob_type = "image/jpeg"
@@ -843,10 +844,6 @@ def metadata_keys():
843844
field.name for field in Accession._meta.fields if hasattr(AccessionMetadata, field.name)
844845
]
845846

846-
@staticmethod
847-
def is_color(img: PIL.Image.Image) -> bool:
848-
return img.mode in {"RGB", "RGBA"}
849-
850847
@staticmethod
851848
def meets_cog_threshold(img: PIL.Image.Image) -> bool:
852849
return img.height * img.width > IMAGE_COG_THRESHOLD

0 commit comments

Comments
 (0)