Skip to content

Commit

Permalink
Merge pull request #161 from biigle/patch-1
Browse files Browse the repository at this point in the history
Implement support for I;16 images
  • Loading branch information
mzur authored Feb 23, 2024
2 parents 5d34384 + a5cfc8d commit 28b3240
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/resources/scripts/novelty-detection/NoveltyDetector.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,11 @@ def apply(self, image_path, chunk_dim = 512, chunk_stride = 256):

if image.mode in ['RGBA', 'L', 'P']:
image = image.convert('RGB')

if image.mode =='I':
# I images (32 bit signed integer) need to be rescaled manually before converting.
image = Image.fromarray(((np.array(image)/(2**16))*2**8).astype(np.uint8)).convert('RGB')
elif image.mode =='I' or image.mode == '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')

novelty_map = torch.zeros((height, width), dtype=torch.float, device=self.device)
# This counts how many chunks were added to each pixel.
Expand Down

0 comments on commit 28b3240

Please sign in to comment.