Skip to content
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
32 changes: 4 additions & 28 deletions applications/pctfdk/pctfdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@ def build_parser():
parser.add_argument(
"--geometry", "-g", help="XML geometry file name", type=str, required=True
)
parser.add_argument(
"--path", "-p", help="Path containing projections", type=str, required=True
)
parser.add_argument(
"--regexp",
"-r",
help="Regular expression to select projection files in path",
type=str,
required=True,
)
parser.add_argument(
"--output", "-o", help="Output file name", type=str, required=True
)
Expand All @@ -35,12 +25,6 @@ def build_parser():
help="Load only one projection per thread in memory",
action="store_true",
)
parser.add_argument(
"--wpc",
help="Water precorrection coefficients (default is no correction)",
type=float,
nargs="+",
)

# Ramp filter
parser.add_argument(
Expand Down Expand Up @@ -81,29 +65,21 @@ def build_parser():
help="Copy info from image (origin, size, spacing, direction)",
type=str,
)

pct.add_pctinputprojections_group(parser)

return parser


def process(args_info: argparse.Namespace):
from itk import RTK as rtk

# Generate file names
names = itk.RegularExpressionSeriesFileNames.New()
names.SetDirectory(args_info.path)
names.SetNumericSort(False)
names.SetRegularExpression(args_info.regexp)
names.SetSubMatch(0)
if args_info.verbose:
print(f"Regular expression matches {len(names.GetFileNames())} file(s)...")

# Projections reader
OutputPixelType = itk.F
ProjectionImageType = itk.Image[OutputPixelType, 4]
ReaderType = rtk.ProjectionsReader[ProjectionImageType]
reader = ReaderType.New()
reader.SetFileNames(names.GetFileNames())
if args_info.wpc:
reader.SetWaterPrecorrectionCoefficients([float(c) for c in args_info.wpc])
pct.SetProjectionsReaderFromArgParse(reader, args_info)

# Geometry
if args_info.verbose:
Expand Down
77 changes: 77 additions & 0 deletions applications/pctinputprojection_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import itk
from itk import PCT as pct

__all__ = [
"add_pctinputprojections_group",
"GetProjectionsFileNamesFromArgParse",
]


# Mimicks pctinputprojections_section.ggo
def add_pctinputprojections_group(parser):
pctinputprojections_group = parser.add_argument_group(
"Input projections and their pre-processing"
)
pctinputprojections_group.add_argument(
"--path", "-p", help="Path containing projections", required=True
)
pctinputprojections_group.add_argument(
"--regexp",
"-r",
help="Regular expression to select projection files in path",
required=True,
)
pctinputprojections_group.add_argument(
"--nsort",
help="Numeric sort for regular expression matches",
action="store_true",
)
pctinputprojections_group.add_argument(
"--submatch",
help="Index of the submatch that will be used to sort matches",
type=int,
default=0,
)
pctinputprojections_group.add_argument(
"--wpc",
help="Water precorrection coefficients (default is no correction)",
type=float,
nargs="+",
)


# Mimicks GetProjectionsFileNamesFromGgo
def GetProjectionsFileNamesFromArgParse(args_info):
# Generate file names
names = itk.RegularExpressionSeriesFileNames.New()
names.SetDirectory(args_info.path)
names.SetNumericSort(args_info.nsort)
names.SetRegularExpression(args_info.regexp)
names.SetSubMatch(args_info.submatch)

if args_info.verbose:
print(f"Regular expression matches {len(names.GetFileNames())} file(s)...")

fileNames = []
for fn in names.GetFileNames():
imageio = itk.ImageIOFactory.CreateImageIO(
fn, itk.CommonEnums.IOFileMode_ReadMode
)
if imageio is None:
print(f"Ignoring file: {fn}")
continue
fileNames.append(fn)

return fileNames


def SetProjectionsReaderFromArgParse(reader, args_info):
fileNames = GetProjectionsFileNamesFromArgParse(args_info)

# Water precorrection
if args_info.wpc is not None:
reader.SetWaterPrecorrectionCoefficients([float(c) for c in args_info.wpc])

# Pass list to projections reader and update information
reader.SetFileNames(fileNames)
reader.UpdateOutputInformation()
19 changes: 8 additions & 11 deletions wrapping/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,21 @@ configure_file(
)

file(
GLOB PCT_PYTHON_APP
GLOB PCT_GROUP_SCRIPTS
CONFIGURE_DEPENDS
"${PCT_SOURCE_DIR}/applications/pct*_group.py"
)
file(
GLOB PCT_APP_SCRIPTS
CONFIGURE_DEPENDS
"${PCT_SOURCE_DIR}/applications/pct*/pct*.py"
)

wrap_itk_python_bindings_install(/itk "PCT"
__init_pct__.py
${PCT_PYTHON_APP}
${PCT_GROUP_SCRIPTS}
${PCT_APP_SCRIPTS}
${PCT_VERSION_SCRIPT}
${PCT_SOURCE_DIR}/wrapping/pctExtras.py
${PCT_SOURCE_DIR}/applications/pctargumentparser.py
)

# Copy python applications to the ITK wrapping directory to ensure they can be imported in tests.
# This directory is added to the PYTHONPATH by itk_python_add_test.
if(ITK_DIR)
set(itk_wrap_python_binary_dir "${ITK_DIR}/Wrapping/Generators/Python")
else()
set(itk_wrap_python_binary_dir "${ITK_BINARY_DIR}/Wrapping/Generators/Python")
endif()
file(COPY ${PCT_PYTHON_APP} DESTINATION "${itk_wrap_python_binary_dir}")
1 change: 1 addition & 0 deletions wrapping/__init_pct__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"itk.pctversion",
"itk.pctargumentparser",
"itk.pctExtras",
"itk.pctinputprojection_group",
]
for mod_name in pct_submodules:
mod = importlib.import_module(mod_name)
Expand Down
Loading