Skip to content

Commit

Permalink
Merge pull request #163 from biigle/patch-1
Browse files Browse the repository at this point in the history
Handle CMYK image conversion
  • Loading branch information
mzur authored Feb 26, 2024
2 parents 9a062cc + 5583d34 commit 1c4c249
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/resources/scripts/novelty-detection/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ def is_corrupt(self):

def pil_image(self):
image = PilImage.open(self.path)
if image.mode == 'RGBA':
if image.mode in ['RGBA', 'L', 'P', 'CMYK']:
image = image.convert('RGB')
elif image.mode == 'LA':
image = image.convert('L')
elif image.mode in ['I', 'I;16']:
# I images (32 bit signed integer) and I;16 (16 bit unsigned imteger)
# need to be rescaled manually before converting.
# image/256 === image/(2**16)*(2**8)
image = Image.fromarray((np.array(image)/256).astype(np.uint8)).convert('RGB')

return image

Expand Down
4 changes: 2 additions & 2 deletions src/resources/scripts/novelty-detection/NoveltyDetector.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ def apply(self, image_path, chunk_dim = 512, chunk_stride = 256):
height = image.height
width = image.width

if image.mode in ['RGBA', 'L', 'P']:
if image.mode in ['RGBA', 'L', 'P', 'CMYK']:
image = image.convert('RGB')
elif image.mode =='I' or image.mode == 'I;16':
elif image.mode in ['I', 'I;16']:
# I images (32 bit signed integer) and I;16 (16 bit unsigned imteger)
# need to be rescaled manually before converting.
# image/256 === image/(2**16)*(2**8)
Expand Down

0 comments on commit 1c4c249

Please sign in to comment.