cyclomon / 3dbraingen

Official Pytorch Implementation of "Generation of 3D Brain MRI Using Auto-Encoding Generative Adversarial Network" (accepted by MICCAI 2019)
MIT License
126 stars 38 forks source link

Regarding ADNI dataset loader #3

Closed LUYU0004 closed 4 years ago

LUYU0004 commented 4 years ago

Hi,

Thank you very much!

        img = nib.load(os.path.join(path,'image.nii'))

        img = np.swapaxes(img.get_data(),1,2)
        img = np.flip(img,1)
        img = np.flip(img,2)

        sp_size = 64
        img = resize(img, (sp_size,sp_size,sp_size), mode='constant')
        if self.augmentation:
            random_n = torch.rand(1)
            random_i = 0.3*torch.rand(1)[0]+0.7
            if random_n[0] > 0.5:
                img = np.flip(img,0)

            img = img*random_i.data.cpu().numpy()

        imageout = torch.from_numpy(img).float().view(1,sp_size,sp_size,sp_size)
        imageout = imageout*2-1

        return imageout 
cyclomon commented 4 years ago

Hi, thank you for the comment.

In python 0.4.1 (maybe in the other versions), if the numpy data is changed into float by torch.from_numpy function, the output tensors are within the range of [0,1]. Thus, I just included imageout*2-1 to make them into [-1,1].

I just changed the x,y,z order into the form that is familiar to me. It's just for a good visualization, and also to make the x,y,z order to be same as that of BRATS/ATLAS datasets. There is no necessity to change the order.

Thanks!

LUYU0004 commented 4 years ago

Thank you very much for the information!