Skip to content

Otsu staging clean #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: kyle
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions lama/seg_methods/external_hole_filler.py

This file was deleted.

22,711 changes: 0 additions & 22,711 deletions lama/seg_methods/get-pip.py

This file was deleted.

110 changes: 7 additions & 103 deletions lama/seg_methods/mask.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
import SimpleITK as sitk
from lama.seg_methods.seg import ws_mask, binary_mask, binary_mask_split, auto_thres_mask
from lama.seg_methods.seg import auto_thres_mask
import argparse
import textwrap
import os
Expand Down Expand Up @@ -40,33 +40,17 @@ def main(args):
parser.add_argument('-option', dest='option', help='Otsu, huang, li, ws, binary, binary_split', required=False)
parser.add_argument("-external", dest='external', action="store_true",
help='If external holes are to be filled.', required=False)
parser.add_argument("-external2", dest='external2', action="store_true",
help='If external holes are to be filled. New method using 3D whole filling', required=False)
parser.add_argument("-manual", dest='manual', action="store_true",
help='supply manual threshold value', required=False)


parser.add_argument("-tight", dest='tight', action="store_true",
help='If a tight mask is required [Default False]', required=False)
parser.add_argument("-ndilate", dest='ndilate', action="store_true",
help='If no dilation to occur [Default False]', required=False)

# Options for manual binary
parser.add_argument('-lt', dest='lt', help='[Binary only] level of threshold if man binary used', required=False)

# Options for watershed
parser.add_argument('-ws_level', dest='ws_level', help='[WS only] watershed level default is 0.9', required=False)
parser.add_argument('-force', dest='force_background_in', help='[WS only] If the out put for the background '
'is not zero', required=False)

# Options for auto thresh
parser.add_argument('-bins', dest='bins', help='[auto-thres options only e.g Otsu, Huang] Number of histogram bins'
' to use', required=False)

# For option manual binary_split
parser.add_argument("-split", dest='split', help='If binary_split used. The 3D image is slit in two in its '
'z-axis by this value', required=False)
parser.add_argument("-lt1", dest='lt1', help='[Binary_split option only] Lower threshold for first'
' half of image', required=False)
parser.add_argument("-lt2", dest='lt2', help='[Binary_split option only] Lower threshold for second'
' half of image', required=False)
args = parser.parse_args(args)
#====================================================================================================
# Setting up folders and parameters
Expand Down Expand Up @@ -97,22 +81,7 @@ def main(args):
bins = args.bins
else:
bins = False

# This is required if the user wants to perform a binary threshold with a low threshold specified
if args.lt:
lt = args.lt
else:
lt = False

# This is required if the user wanted to perform a tight mask. (Potentially would get whole volume)
if args.ws_level:
ws_level = float(args.ws_level)
else:
ws_level = 0.9

# This is for watershed, sometimes need to force the background.
if not args.force_background_in:
args.force_background_in = False


# Check if dilation to occur
if args.ndilate:
Expand All @@ -121,40 +90,14 @@ def main(args):
dilate = True

#arg.in_file is geetinng a random space from somewhere (which is why I slice it)
img = sitk.ReadImage(args.in_file)

if args.in_file[-4:] == '.mnc':
import minc
sg = minc.MincRawSliceGenerator(args.in_file)
img = sitk.GetImageFromArray(sg.volume)
else:
img = sitk.ReadImage(args.in_file)
print("I read file")

# All the methods used are in the seg.py module. Split into three types of masking

#====================================================================================================
# Binary threshold binary_mask()
#====================================================================================================
# - This includes a binary mask where we choose just a lower threshold value
# - Also if no-lower threshold use, we calculate a binary threshold using the maximum inensity and variance of the
# the first slice

if option == "binary":
seg = binary_mask(img,
out_dir,
lt,
tight = args.tight,
external = args.external,
external2=args.external2,
dilate = dilate)

#====================================================================================================
# Auto threshold auto_thres_mask()
#====================================================================================================
# - When standard autothres is to be used e.g. otsu, li, huang....

elif option == "otsu" or option == "li" or option == "isodata" or option == "triangle" or option == "huang":
print("otsu")
if option == "otsu" or option == "li" or option == "isodata" or option == "triangle" or option == "huang":
seg = auto_thres_mask(
option,
img,
Expand All @@ -165,44 +108,5 @@ def main(args):
external2 = args.external2,
dilate = dilate)


#====================================================================================================
# Watershed threshold
#====================================================================================================
# - Use the watershed algorithm to mask
elif option == "ws":

seg = ws_mask(img,
out_dir,
force_background = args.force_background_in,
tight = args.tight,
external = args.external,
external2=args.external2,
ws_level = ws_level,
dilate = dilate)


#====================================================================================================
# Binary split threshold
#====================================================================================================
# - Can split the 3D image in the Z-axis by a user defined value
# - Can then use a different lower thershold for each section.
elif option == "binary_split":

seg = binary_mask_split(img,
out_dir,
lt1 = args.lt1,
lt2 = args.lt2,
split = args.split,
tight =args.tight,
external = args.external,
external2=args.external2,
dilate = dilate)
print("##############################################################################")


if __name__ == '__main__':

main()


106 changes: 0 additions & 106 deletions lama/seg_methods/minc.py

This file was deleted.

Loading