I am working with 3D CT images which are consists of a series of 2D slices. I resized them into (128 x 128 x 128)
My segmentation masks are provided as xml files and have segmentations only for like 3 or 4 slices (where the tumor is visible). I am trying to construct a segmentation volume as same size as the input image (128 x 128 x 128). My question is how I can keep the same z position in my segmentation volume as the input image?
I create the numpy image array form xml file as follows:
Bs_data = BeautifulSoup(data, "lxml") # Finding all instances of tag # `unique` b_unique_X = Bs_data.find_all('x') b_unique_Y = Bs_data.find_all('y') #print(b_unique) #Extract the X, Y co-ordinates of contours from the xml file X_coord =  Y_coord =  for i,j in zip(range(0,len(b_unique_X)),range(0,len(b_unique_Y))): X_coord.append(b_unique_X[i].get('value')) Y_coord.append(b_unique_Y[i].get('value')) final = np.column_stack((X_coord, Y_coord)) np.set_printoptions(threshold=sys.maxsize) pixelCoords = final.astype(float).astype(int) arr = np.zeros((512,512)) poly = pixelCoords[:,:2].copy() cv2.fillPoly(arr, pts=[poly], color = 255) mask1 = arr.astype(int)
I can get the slice number from the xml file as follows.
description_tag = Bs_data.description # Get the attribute attribute = description_tag['value']
My input images dicom and are named based on the slice number as well (e.g., here the slice number is 215):