-
Hello everyone, hope you are having a good day :) I wanted to ask how can I load just a single image for segmentation in MONAI. I trained a SegResNet on a nifti image of shape (h, w, number of images = 155) and it stacks the image (4 images) therefore the final output is (4, h, w, number of images = 155) I just want to load only a single image (4, h, w, 1) how can I do that? Also if I just want to load one single image (no nifti say a png of shape (224, 224)) to meet the requirement of channels is it okay if I just stack the image with just zeros i.e np.dstack((img, np.zeros(h, w), np.zeros(h, w), np.zeros(h, w)))? Thank you very much for you time :D |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 12 replies
-
Hi @Adwaitt , I think the reason it stacked the images is that you passed a list of file paths to Thanks. |
Beta Was this translation helpful? Give feedback.
-
Sorry I don't quite understand your question. Maybe I missed some points, could you please help show your question with some example? Thanks in advance. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
img = nib.load('path to nib image')
r = img[:, :, 100]
#Loading the 100th slice from a nifti image of 240 slicesr = tfms(image = r)['image']
#Applying my transformationstacker = np.zeros((224, 224))
r = {'image': r, 'label': None}
#dictionary to apply MONAI transformsr = new_transform(r)['image']
#New_transform = MONAI transformr = np.dstack((r, np.zeros((224, 224)), np.zeros((224, 224)), np.zeros((224, 224))))
# Stacking zeros along depth.`r = r[np.newaxis, ...]# Running this code twice to add two new axis so as to make the input compatible with the model
r = r.transpose(0, -1, 2, 3, 1) #Transposing the image so as to make it the desired shape
with torch.no_grad():
n = model.forward(t…