From a5cfc8d59b6a42f4d2be29613fe444bd42c97cad Mon Sep 17 00:00:00 2001 From: Martin Zurowietz Date: Fri, 23 Feb 2024 10:20:51 +0100 Subject: [PATCH] Implement support for I;16 images --- .../scripts/novelty-detection/NoveltyDetector.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/resources/scripts/novelty-detection/NoveltyDetector.py b/src/resources/scripts/novelty-detection/NoveltyDetector.py index e49bd4b..2ab01b3 100644 --- a/src/resources/scripts/novelty-detection/NoveltyDetector.py +++ b/src/resources/scripts/novelty-detection/NoveltyDetector.py @@ -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.