Exemplo n.º 1
0
    def get_data_4_fusion(self, p_target_img, p_target_lab, p_atlas_imgs, p_atlas_labs, is_aug=True):
        p_imgs = p_target_img + p_atlas_imgs
        p_labs = p_target_lab + p_atlas_labs
        imgs, labs = sitk_read_img_lab(p_imgs, p_labs, is_aug)

        imgs = np.stack([convert_img_2_nor_array(img) for img in imgs], axis=-1)
        labs = np.stack([convert_lab_2_array(lab) for lab in labs], axis=-1)

        atlas_img = imgs[..., 1:]
        atlas_lab = labs[..., 1:]
        target_img = imgs[..., 0]
        target_lab = labs[..., 0]
        return np.expand_dims(target_img, axis=-1), np.expand_dims(target_lab,axis=-1), np.expand_dims(atlas_img,axis=-1), np.expand_dims(atlas_lab,axis=-1)
Exemplo n.º 2
0
    def get_dataV3(self, p_target_img, p_target_lab, p_atlas_imgs, p_atlas_labs, is_aug=True):

        p_imgs = p_target_img

        p_labs = p_target_lab+[p_atlas_labs[np.random.randint(len(p_atlas_labs))]]


        imgs, labs = sitk_read_img_lab(p_imgs, p_labs, is_aug)

        imgs = np.stack([convert_img_2_nor_array(img) for img in imgs], axis=-1)
        labs = np.stack([convert_lab_2_array(lab) for lab in labs], axis=-1)

        # atlas_img = imgs[..., 1:]
        atlas_lab = labs[..., 1:]
        target_img = imgs[..., 0]
        target_lab = labs[..., 0]
        # return np.expand_dims(target_img, axis=-1), np.expand_dims(target_lab,axis=-1), np.expand_dims(atlas_img,axis=-1), np.expand_dims(atlas_lab,axis=-1)
        return np.expand_dims(target_img, axis=-1), np.expand_dims(target_lab,axis=-1),None, np.expand_dims(atlas_lab,axis=-1)
Exemplo n.º 3
0
    def get_data(self, p_target_img, p_target_lab, p_atlas_imgs, p_atlas_labs,is_aug=True):
        p_imgs= p_target_img + p_atlas_imgs
        p_labs= p_target_lab + p_atlas_labs
        imgs,labs=sitk_read_img_lab(p_imgs, p_labs, is_aug)

        # mk_or_cleardir('./tmp/')
        # for img,lab,p_img,p_lab in zip(imgs,labs,p_imgs,p_labs):
        #     sitk_write_image(img,dir='./tmp/',name=get_name_wo_suffix(p_img))
        #     sitk_write_image(lab,dir='./tmp/',name=get_name_wo_suffix(p_lab))
        imgs = np.stack([convert_img_2_nor_array(img) for img in imgs], axis=-1)
        labs = np.stack([convert_lab_2_array(lab) for lab in labs], axis=-1)

        atlas_imgs= imgs[ ...,1:]
        target_img=imgs[ ...,0]

        atlas_labs= labs[ ...,1:]
        target_lab=labs[ ...,0]

        return np.expand_dims(target_img,axis=-1), to_categorical(target_lab),atlas_imgs,atlas_labs
Exemplo n.º 4
0
    def get_dataV2(self, p_target_img, p_target_lab, p_atlas_imgs, p_atlas_labs, is_aug=True):
        p_imgs = p_target_img + p_atlas_imgs
        p_labs = p_target_lab + p_atlas_labs
        imgs, labs = sitk_read_img_lab(p_imgs, p_labs, is_aug)

        # mk_or_cleardir('./tmp/')
        # for img,lab,p_img,p_lab in zip(imgs,labs,p_imgs,p_labs):
        #     sitk_write_image(img,dir='./tmp/',name=get_name_wo_suffix(p_img))
        #     sitk_write_image(lab,dir='./tmp/',name=get_name_wo_suffix(p_lab))
        imgs = np.stack([convert_img_2_nor_array(img) for img in imgs], axis=-1)
        labs = np.stack([convert_lab_2_array(lab) for lab in labs], axis=-1)

        atlas_img = imgs[..., 1]
        atlas_lab = labs[..., 1]
        target_img = imgs[..., 0]
        target_lab = labs[..., 0]
        conv_target_lab=ndimage.convolve(target_lab,np.ones([self.args.patch_size,self.args.patch_size,self.args.patch_size]))
        conv_atlas_lab=ndimage.convolve(atlas_lab,np.ones([self.args.patch_size,self.args.patch_size,self.args.patch_size]))
        denominator=conv_atlas_lab+conv_target_lab
        numerator=ndimage.convolve(target_lab*atlas_lab,np.ones([self.args.patch_size,self.args.patch_size,self.args.patch_size]))
        sim=2*numerator.astype(np.float32)/(denominator.astype(np.float32)+0.000001)
        # sitk_write_image(np.squeeze(atlas_labs),dir='./tmp/',name='input')
        # sitk_write_image(np.squeeze(target_lab),dir='./tmp/',name='gt')
        return np.expand_dims(target_img, axis=-1), np.expand_dims(target_lab,axis=-1), np.expand_dims(atlas_img,axis=-1), np.expand_dims(atlas_lab,axis=-1),np.expand_dims(sim,axis=-1)