Skip to content

Commit

Permalink
Alternative method to segment
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigovimieiro committed Jul 20, 2022
1 parent 6676daa commit 75db86c
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion pydbt/functions/dataPreProcess.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import numpy as np
from scipy.ndimage.filters import uniform_filter1d
from skimage.filters import threshold_otsu

def dataPreProcess(proj, geo, flagtransfIntensity=True, flagCropProj=True):

Expand Down Expand Up @@ -38,7 +39,25 @@ def cropProj(proj):
secondDv = np.gradient(uniform_filter1d(firstDv, size=100))

# Takes its min second derivative
indX = np.argmin(secondDv) - Gap
indX = np.argmin(secondDv)

# Alternative method to compare
# Otsu
thresh = threshold_otsu(proj[:,:,proj.shape[2]//2 - 1])

# Get mask
mask = proj[:,:,proj.shape[2]//2 - 1] < thresh

# Weight bounds
mask_w = np.sum(mask, 0) > 0
res = np.where(mask_w == True)
w_min, w_max = res[0][0], res[0][-1]

# If the difference is big, take the min (most left)
if np.abs(indX - w_min) > 200:
indX = np.min([indX, w_min])

indX -= Gap

proj_crop = proj[:,indX::,:]

Expand Down

0 comments on commit 75db86c

Please sign in to comment.