Skip to content

Commit

Permalink
Merge branch 'ThruSections' of https://github.com/simoneponcioni/spli…
Browse files Browse the repository at this point in the history
…ne-mesher into ThruSections
  • Loading branch information
simoneponcioni committed Jun 21, 2024
2 parents 2955772 + f031f51 commit a6b7ba3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/pyhexspline/spline_mesher.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,9 @@ def mesher(
)

cortical_v.plot_mhd_slice()
image_pad = cortical_v.binary_threshold()
print(f'Image size before entering binary_threshold(): {cortical_v.sitk_image.GetSize()}')
image_pad = cortical_v.binary_threshold(img_path=cortical_v.img_path)
print(f'Image size after entering binary_threshold(): {image_pad.GetSize()}')
cortical_ext_split, cortical_int_split, cortical_int_sanity = (
cortical_v.volume_spline_fast_implementation(image_pad)
)
Expand Down
24 changes: 14 additions & 10 deletions src/pyhexspline/spline_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import gmsh
import imutils
import matplotlib

# matplotlib.use("TkAgg")
import matplotlib.pyplot as plt
import numpy as np
Expand Down Expand Up @@ -306,8 +305,8 @@ def pad_image(self, image: Image, iso_pad_size: int) -> Image:
constant = int(sitk.GetArrayFromImage(image).min())
image_thr = sitk.ConstantPad(
image,
(0, iso_pad_size, iso_pad_size),
(0, iso_pad_size, iso_pad_size),
(iso_pad_size, iso_pad_size, 0),
(iso_pad_size, iso_pad_size, 0),
constant,
)
return image_thr
Expand All @@ -324,20 +323,22 @@ def binary_threshold(self, img_path: str) -> Tuple[ndarray, ndarray]:
image = sitk.ReadImage(img_path)
else:
image = self.sitk_image
image = sitk.PermuteAxes(image, [2, 0, 1])
image.SetSpacing(self.sitk_image.GetSpacing())
# image = sitk.PermuteAxes(image, [2, 0, 1])
# image.SetSpacing(self.sitk_image.GetSpacing())

image_thr = self.exec_thresholding(image, THRESHOLD_PARAM)
# image_thr = self.exec_thresholding(image, THRESHOLD_PARAM)

image_thr = self.pad_image(image_thr, iso_pad_size=10)
image_pad = self.pad_image(image, iso_pad_size=10)

if self.show_plots is True:
self.plot_slice(
image_thr, SLICE, f"Padded Image on slice n. {SLICE}", ASPECT
image_pad, SLICE, f"Padded Image on slice n. {SLICE}", ASPECT
)
else:
self.logger.info(f"Padded Image\t\t\tshow_plots:\t{self.show_plots}")
return image_thr

print(f'Image size after padding: {image_pad.GetSize()}')
return image_pad

"""
img_thr_join = self.get_binary_contour(image_thr)
Expand Down Expand Up @@ -884,7 +885,7 @@ def process_slice(self, mask, slice_idx):

def classify_contours(self, mask, slice_idx):
"""Classify and extract outer and inner contours from the mask."""
contours = find_contours(mask[:, :, slice_idx], level=0.5)
contours = find_contours(mask[:, :, slice_idx]) #, level=127)
outer_contour = contours[0] if contours else None
inner_contour = contours[1] if len(contours) > 1 else None
return outer_contour, inner_contour
Expand Down Expand Up @@ -935,10 +936,13 @@ def volume_spline_fast_implementation(
self, imsitk_pad: Image
) -> Tuple[ndarray, ndarray]:
imnp = sitk.GetArrayFromImage(imsitk_pad)
self.spacing = imsitk_pad.GetSpacing()
imnp = np.transpose(imnp, [2, 1, 0])
imnp = np.flip(imnp, axis=1)
height = imnp.shape[2]
self.logger.debug(f"Height:\t{height}")

print(f'Image size of numpy array inside volume_spline_fast_implementation(): {imnp.shape}')

# Get number of slices / ThruSections
total_slices = np.linspace(0, height - 1, self.SLICING_COEFFICIENT, dtype=int)
Expand Down

0 comments on commit a6b7ba3

Please sign in to comment.