banikr:

itkwidgets


Dear Sir,
This is my code
import torch
import nibabel as nib
import matplotlib.pyplot as plt
tmap_img = nib.load(’/home/nitika/PHD/rough/Image1.nii.gz’)
print(tmap_img.shape)
plt.imshow(tmap_img.get_fdata()[10])
S = tmap_img.shape[0] # channel dim
W = tmap_img.shape[1] # width
H = tmap_img.shape[2] # height
batch_size = 1
x = torch.randn(batch_size, S, W, H)
kc, kh, kw = 32, 32, 32  # kernel size
dc, dh, dw = 32, 32, 32  # stride

Pad to multiples of 32
x = F.pad(x, (x.size(2)%kw // 2, x.size(2)%kw // 2,
x.size(1)%kh // 2, x.size(1)%kh // 2,
x.size(0)%kc // 2, x.size(0)%kc // 2))
patches = x.unfold(1, kc, dc).unfold(2, kh, dh).unfold(3, kw, dw)
unfold_shape = patches.size()
patches = patches.contiguous().view(-1, kc, kh, kw)
print(patches.shape)

Reshape back
patches_orig = patches.view(unfold_shape)
output_c = unfold_shape[1] * unfold_shape[4]
output_h = unfold_shape[2] * unfold_shape[5]
output_w = unfold_shape[3] * unfold_shape[6]
patches_orig = patches_orig.permute(0, 1, 4, 2, 5, 3, 6).contiguous()
patches_orig = patches_orig.view(1, output_c, output_h, output_w)
import tensorflow as tf

Check for equality
print((patches_orig == x[:, :output_c, :output_h, :output_w]).all())
print(‘HI’, patches_orig.shape)
#============PLease help here how to view this original image reconstructed in python notebook====
#plt.imshow(patches_orig) ==> THrows an error ypeError: Invalid shape (1, 64, 128, 96) for image data
#tensor(1, dtype=torch.uint8)
and this is output
(91, 109, 91)
torch.Size([24, 32, 32, 32])
tensor(True)
HI torch.Size([1, 64, 128, 96])
also one image is displayed
Can you please help in last section of verifying original image
#============PLease help here how to view this original image reconstructed in python notebook====
#plt.imshow(patches_orig) ==> THrows an error ypeError: Invalid shape (1, 64, 128, 96) for image data
Also how can we send these patches directly to 3D -CNN.
It would be very helpful if you can guide please.