0

i'm trying to use this implementation of Pix2Pix algorithm https://github.com/mrzhu-cool/pix2pix-pytorch. In this implementation they are using small UInt8 (max color value : 255) images so they are normalizing their images like this :

Image.MAX_IMAGE_PIXELS = None
        a = Image.open(join(self.a_path, self.image_filenames[index])).convert('RGB')
        b = Image.open(join(self.b_path, self.image_filenames[index])).convert('RGB')
        a = a.resize((286, 286), Image.BICUBIC)
        b = b.resize((286, 286), Image.BICUBIC)

        a = transforms.ToTensor()(a)
        b = transforms.ToTensor()(b)
        w_offset = random.randint(0, max(0, 286 - 256 - 1))
        h_offset = random.randint(0, max(0, 286 - 256 - 1))
    
        a = a[:, h_offset:h_offset + 256, w_offset:w_offset + 256]
        b = b[:, h_offset:h_offset + 256, w_offset:w_offset + 256]
    
        a = transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))(a)
        b = transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))(b)

        if random.random() < 0.5:
            idx = [i for i in range(a.size(2) - 1, -1, -1)]
            idx = torch.LongTensor(idx)
            a = a.index_select(2, idx)
            b = b.index_select(2, idx)

        if self.direction == "a2b":
            return a, b
        else:
            return b, a

But in my case, I want to use UInt16 images (max color value : 65535) , so, if I want to normalize UInt16 images I just need to replace 256 by 65536 or do I need to do other things ?

s1o
  • 1
  • 1
  • Check the maximum value of your image when it is loaded as a torch tensor. Additionally, `256` of the above code doesn't seem to be related to the data type but to the image size and random cropping. Also, torch tensor does not support uint16 data type. – Hayoung May 31 '22 at 08:48
  • Ok thank you @Hayoung! :) But are you sure about "Also, torch tensor does not support uint16 data type.", because when I execute my code with Uint16 image there is no errors, my tensor got dtype = torch.float32 like when i use Uint8 image – s1o May 31 '22 at 12:04
  • As you said in your comment, your tensor is a type of `float32`, not `uint16`. – Hayoung May 31 '22 at 12:11

0 Answers0