icon-lab / SynDiff

Official PyTorch implementation of SynDiff described in the paper (https://arxiv.org/abs/2207.08208).
Other
229 stars 39 forks source link

toy data question #41

Open Xiao-R-Y opened 6 months ago

Xiao-R-Y commented 6 months ago

Thanks for your excellent work. I have a question when transform the .mat data to the .png data and found the slices are not correspond. There are 25 images in T1 and T2 each, however ,with the same index, the corresponding images are not the same location, T1_image_0 T2_image_0 The transform code are as follows: ` import torch.utils.data import numpy as np, h5py import random

load_dir = 'SynDiff-main/SynDiff_sample_data/data_val_T1.mat' padding = True Norm = True variable = 'data_fs'

f = h5py.File(load_dir,'r') if np.array(f[variable]).ndim==3: data=np.expand_dims(np.transpose(np.array(f[variable]),(0,2,1)),axis=1) else: data=np.transpose(np.array(f[variable]),(1,0,3,2)) data=data.astype(np.float32)

if padding: pad_x=int((256-data.shape[2])/2) pad_y=int((256-data.shape[3])/2) print('padding in x-y with:'+str(pad_x)+'-'+str(pad_y)) data=np.pad(data,((0,0),(0,0),(pad_x,pad_x),(pad_y,pad_y)))
if Norm:
data=(data-0.5)/0.5

from PIL import Image import numpy as np

data = ((data + 1) 0.5 255).astype(np.uint8)

print(data.shape)

for i, sample in enumerate(data):

print(sample.shape,sample)

# image = Image.fromarray(sample.transpose(1, 2, 0))
image = Image.fromarray(sample[0])
image.save(f'show/vT1_image_{i}.png')

` I would like to know after registration, should the data not correspond? Thank you.

muzafferozbey commented 5 months ago

SynDiff was proposed for Unsupervised Medical Image Translation with unpaired source-target images. Hence, training data doesn't have to be matched/registered. However, you can still employ SynDiff with paired images.