Skip to content

Commit

Permalink
change selem to footprint in skimage.morphology funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
Xunius committed Jul 12, 2023
1 parent bccbaff commit 544aec0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
14 changes: 12 additions & 2 deletions ipart/AR_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,13 @@ def partPeaks(cropmask, cropidx, orislab, area, min_area, max_ph_ratio,
ele=morphology.diamond(fill_radius//2)

gap=cropmask-mask1
op=morphology.opening(mask1, selem=ele)

try:
op=morphology.opening(mask1, selem=ele)
except:
# version >= 0.19 changes to footprint
op=morphology.opening(mask1, footprint=ele)

gap2=morphology.reconstruction(gap, mask1-op+gap)
mask1=np.where(mask1-gap2<=0, 0, mask1)
#gap2=morphology.dilation(gap, selem=ele)
Expand Down Expand Up @@ -1621,7 +1627,11 @@ def paddedClosing(mask, ele, pad, has_cv):
if has_cv:
padmask=cv.morphologyEx(padmask, cv.MORPH_CLOSE, ele)
else:
padmask=morphology.closing(padmask, selem=ele)
try:
padmask=morphology.closing(padmask, selem=ele)
except:
# version >= 0.19 changes to footprint
padmask=morphology.closing(padmask, footprint=ele)
# trim
padmask=padmask[tuple([slice(pad,-pad), slice(pad,-pad)])]
return padmask
Expand Down
40 changes: 34 additions & 6 deletions ipart/thr.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,20 @@ def THR(ivtNV, kernel, oroNV=None, high_terrain=600, verbose=True):
if verbose:
print('\n# <THR>: Computing erosion ...')

lm=morphology.erosion(ivt, selem=ele)
try:
lm=morphology.erosion(ivt, selem=ele)
except TypeError:
# version >= 0.19 changes to footprint
lm=morphology.erosion(ivt, footprint=ele)

if verbose:
print('\n# <THR>: Computing reconstruction ...')

ivtrec=morphology.reconstruction(lm, ivt, method='dilation', selem=rec_ele)
try:
ivtrec=morphology.reconstruction(lm, ivt, method='dilation', selem=rec_ele)
except TypeError:
# version >= 0.19 changes to footprint
ivtrec=morphology.reconstruction(lm, ivt, method='dilation', footprint=rec_ele)

# perform an extra reconstruction over land
if oroNV is not None:
Expand All @@ -116,8 +124,14 @@ def THR(ivtNV, kernel, oroNV=None, high_terrain=600, verbose=True):
oro_rs=oro_rs[None,...]
oro_rs=np.repeat(oro_rs, len(ivt), axis=0)

ivtrec_oro=morphology.reconstruction(lm*oro_rs, ivt, method='dilation',
selem=rec_ele)
try:
ivtrec_oro=morphology.reconstruction(lm*oro_rs, ivt, method='dilation',
selem=rec_ele)
except TypeError:
# version >= 0.19 changes to footprint
ivtrec_oro=morphology.reconstruction(lm*oro_rs, ivt, method='dilation',
footprint=rec_ele)

ivtano=np.ma.maximum(ivt-ivtrec, (ivt-ivtrec_oro)*oro_rs)
else:
ivtano=ivt-ivtrec
Expand Down Expand Up @@ -386,21 +400,35 @@ def THRCyclicLongitude(ivt, kernel, oro=None, high_terrain=600, verbose=True):
if verbose:
print('\n# <THR>: Computing erosion ...')
lm=morphology.erosion(ivt.data, selem=ele)
try:
lm=morphology.erosion(ivt.data, selem=ele)
except TypeError:
# version >= 0.19 changes to footprint
lm=morphology.erosion(ivt.data, footprint=ele)
if verbose:
print('\n# <THR>: Computing reconstruction ...')
ivtrec=recon.reconstruction(lm, ivt, method='dilation', selem=rec_ele)
try:
ivtrec=recon.reconstruction(lm, ivt, method='dilation', selem=rec_ele)
except TypeError:
# version >= 0.19 changes to footprint
ivtrec=recon.reconstruction(lm, ivt, method='dilation', footprint=rec_ele)
# perform an extra reconstruction over land
if oro is not None:
oro_rs=MV.where(oro>=high_terrain, 1, 0)
oro_rs=funcs.addExtraAxis(oro_rs,axis=0)
oro_rs=np.repeat(oro_rs, len(ivt), axis=0)
try:
ivtrec_oro=recon.reconstruction(lm*oro_rs, ivt, method='dilation',
selem=rec_ele)
except TypeError:
# version >= 0.19 changes to footprint
ivtrec_oro=recon.reconstruction(lm*oro_rs, ivt, method='dilation',
footprint=rec_ele)
ivtano=MV.maximum(ivt-ivtrec, (ivt-ivtrec_oro)*oro_rs)
else:
ivtano=ivt-ivtrec
Expand Down

0 comments on commit 544aec0

Please sign in to comment.