Skip to content

Commit

Permalink
correct brain extraction to get better masks
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamza Kebiri committed Oct 9, 2020
1 parent 9054b11 commit 05ad4b6
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
Binary file not shown.
Binary file not shown.
5 changes: 3 additions & 2 deletions pymialsrtk/interfaces/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,8 @@ def _extractBrain(self, dataPath, modelCkptLoc, thresholdLoc, modelCkptSeg, thre
img_nib = nibabel.load(os.path.join(dataPath))
image_data = img_nib.get_data()
images = np.zeros((image_data.shape[2], width, height, n_channels))
pred3dFinal = np.zeros((image_data.shape[2], width, height, n_channels))
#pred3dFinal = np.zeros((image_data.shape[2], width, height, n_channels))
pred3dFinal = np.zeros((image_data.shape[2], image_data.shape[0], image_data.shape[1], n_channels))

slice_counter = 0
for ii in range(image_data.shape[2]):
Expand Down Expand Up @@ -801,7 +802,7 @@ def _extractBrain(self, dataPath, modelCkptLoc, thresholdLoc, modelCkptSeg, thre
for i in range(np.asarray(pred3d).shape[0]):
if np.sum(pred3d[i, :, :]) != 0:
pred3d[i, :, :] = self._extractLargestCC(pred3d[i, :, :].astype('uint8'))
contours, _ = cv2.findContours(pred3d[i, :, :].astype('uint8'), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
contours, hierarchy = cv2.findContours(pred3d[i, :, :].astype('uint8'), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
area = cv2.minAreaRect(np.squeeze(contours))
heights.append(area[1][0])
widths.append(area[1][1])
Expand Down

0 comments on commit 05ad4b6

Please sign in to comment.