Skip to content

Commit

Permalink
Merge pull request #7 from rg2/devel
Browse files Browse the repository at this point in the history
Merging Latest Development Branch
  • Loading branch information
rg2 authored Aug 1, 2021
2 parents 7298208 + 77f4098 commit ae2ab80
Show file tree
Hide file tree
Showing 57 changed files with 4,419 additions and 1,215 deletions.
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License
#
# Copyright (c) 2020 Robert Grupp
# Copyright (c) 2020-2021 Robert Grupp
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand All @@ -22,13 +22,13 @@

cmake_minimum_required(VERSION 3.13.0 FATAL_ERROR)

if (APPLE)
# Target MacOS 10.14, Mojave
set (CMAKE_OSX_DEPLOYMENT_TARGET "10.14" CACHE STRING "MacOS Deployment Target")
endif ()
#if (APPLE)
# # Target MacOS 10.14, Mojave
# set (CMAKE_OSX_DEPLOYMENT_TARGET "10.14" CACHE STRING "MacOS Deployment Target")
#endif ()

# Version format is YYYY.MM.DD for a release and YYYY.MM.DD.1 for devel after the release
project(xreg VERSION 2020.12.13.0)
project(xreg VERSION 2020.12.13.1)

set (CMAKE_CXX_STANDARD "11" CACHE STRING "C++ Standard (needs at least 11)")
mark_as_advanced(CMAKE_CXX_STANDARD)
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ The [docker](docker) directory demonstrates how Docker may be used to build the
* Highly recomended for GPU acceleration: OpenCL (1.x)
* Only needed at runtime on Windows and Linux and is typically provided with your graphics drivers or CUDA SDK
* Included with MacOS
* Optional: [ffmpeg](https://ffmpeg.org) is used for writing videos when it is found in the system path. The OpenCV video writer is used if ffmpeg is not available.
* Optional: [ffmpeg](https://ffmpeg.org) is used for writing videos when it is found in the system path. When ffmpeg is not found, the following fallbacks are used:
* MacOS: a video writer using AVFoundation,
* Windows, Linux, something else: a writer using OpenCV.

## Testing
Functional testing is available in the form of a [python script](tests/wiki_cmds.py) that runs the commands found on the [wiki walkthrough](https://github.com/rg2/xreg/wiki#walkthrough).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ int main(int argc, char* argv[])
"Do NOT convert RAS to LPS (or LPS to RAS) for the 3D landmarks; "
"RAS to LPS conversion negates the first and second components.")
<< false;

po.add("no-log-remap", ProgOpts::kNO_SHORT_FLAG, ProgOpts::kSTORE_TRUE, "no-log-remap",
"Do NOT perform log remapping of the projection intensities during pre-processing.")
<< false;

po.add_backend_flags();

Expand Down Expand Up @@ -130,6 +134,8 @@ int main(int argc, char* argv[])

const unsigned char pelvis_label = static_cast<unsigned char>(po.get("pelvis-label").as_uint32());

const bool no_log_remap = po.get("no-log-remap");

//////////////////////////////////////////////////////////////////////////////
// Read in input intensity volume

Expand Down Expand Up @@ -167,6 +173,7 @@ int main(int argc, char* argv[])
PrintLandmarkMap(lands_3d, vout);

ProjPreProc proj_preproc;
proj_preproc.params.no_log_remap = no_log_remap;

{
vout << "reading projection data..." << std::endl;
Expand Down
7 changes: 6 additions & 1 deletion apps/image_io/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License
#
# Copyright (c) 2020 Robert Grupp
# Copyright (c) 2020-2021 Robert Grupp
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -28,4 +28,9 @@ add_subdirectory(extract_nii_from_proj_data)
add_subdirectory(add_lands_to_proj_data)
add_subdirectory(draw_xray_scene)
add_subdirectory(regi2d3d_replay)
add_subdirectory(convert_rad_raw_to_proj_data)
add_subdirectory(convert_sta_raw_to_itk)
add_subdirectory(convert_radiograph_dicom_to_proj_data)
add_subdirectory(make_video_from_image_dir)
add_subdirectory(remap_dicom_dir)

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2020 Robert Grupp
* Copyright (c) 2020-2021 Robert Grupp
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -55,6 +55,18 @@ int main(int argc, char* argv[])
po.add("no-pat-rot-up", ProgOpts::kNO_SHORT_FLAG, ProgOpts::kSTORE_TRUE, "no-pat-rot-up",
"Ignore any flags for rotating the image to achieve patient \"up\" orientation.")
<< false;

po.add("fcsv-spacing", ProgOpts::kNO_SHORT_FLAG, ProgOpts::kSTORE_DOUBLE, "fcsv-spacing",
"Default (isotopic) pixel spacing to assume when parsing FCSV landmarks when no 2D pixel "
"spacing is provided by the 2D image metadata.")
<< 1.0;

po.add("use-pd-spacing", ProgOpts::kNO_SHORT_FLAG, ProgOpts::kSTORE_TRUE, "use-pd-spacing",
"Always use the pixel spacings encoded in the projection data file when interpreting "
"FCSV files, even when the pixel spacings were not explicitly provided by the source "
"image format. This is useful when an FCSV file was created using a NIFTI file which "
"was extracted from a projection data file with estimated spacings.")
<< false;

try
{
Expand All @@ -78,6 +90,10 @@ int main(int argc, char* argv[])

const bool ignore_pat_rot_up = po.get("no-pat-rot-up");

const double default_fcsv_spacing = po.get("fcsv-spacing");

const bool use_pd_spacing = po.get("use-pd-spacing");

vout << "opening proj data for reading/writing..." << std::endl;
H5::H5File h5(po.pos_args()[0], H5F_ACC_RDWR);

Expand Down Expand Up @@ -123,6 +139,27 @@ int main(int argc, char* argv[])
CoordScalar spacing_for_phys_to_ind_x = cur_cam.det_col_spacing;
CoordScalar spacing_for_phys_to_ind_y = cur_cam.det_row_spacing;

// The following conditional addresses the UNCOMMON problem listed below:
// Suppose that our source data does not have explicit metadata listing pixel spacings,
// so the conversion to projection data HDF5 format used some additional information to
// estimate the pixel spacings. Now, also suppose that 3D Slicer is not able to read in
// the source data - this has happened with certain DICOMs from TCIA with RF modality.
// In order to annotate landmarks, a NIFTI (.nii.gz) file is extracted from the projection
// HDF5 file and then loaded into 3D Slicer for landmark annotation. This NIFTI file has
// the estimated pixel spacings embedded, and therefore the FCSV annotations are physical
// points calculated using these spacings. When the contents of the FCSV are then loaded
// back into the HDF5 projection data (e.g. using THIS TOOL), the current behavior is to use
// a user-provided spacing when the original source data did not have explicit pixel spacings
// provided. Although this is the most common case and default desired behavior, for the
// previously identified scenario we need to use the estimated pixel spacings present in the
// HDF5 file.
if (!use_pd_spacing && cur_proj_meta.det_spacings_from_orig_meta &&
!*cur_proj_meta.det_spacings_from_orig_meta)
{
spacing_for_phys_to_ind_x = default_fcsv_spacing;
spacing_for_phys_to_ind_y = default_fcsv_spacing;
}

bool need_to_rot = false;

const bool check_rot_field = !ignore_pat_rot_up && cur_proj_meta.rot_to_pat_up;
Expand Down
30 changes: 30 additions & 0 deletions apps/image_io/convert_rad_raw_to_proj_data/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# MIT License
#
# Copyright (c) 2021 Robert Grupp
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

set(EXE_NAME "${XREG_EXE_PREFIX}convert-rad-raw-to-proj-data")

add_executable(${EXE_NAME} xreg_convert_rad_raw_to_proj_data_main.cpp)

target_link_libraries(${EXE_NAME} PUBLIC ${XREG_EXE_LIBS_TO_LINK})

install(TARGETS ${EXE_NAME})

Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* MIT License
*
* Copyright (c) 2021 Robert Grupp
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include "xregProgOptUtils.h"
#include "xregH5ProjDataIO.h"
#include "xregRadRawProj.h"

using namespace xreg;

int main(int argc, char* argv[])
{
constexpr int kEXIT_VAL_SUCCESS = 0;
constexpr int kEXIT_VAL_BAD_USE = 1;

ProgOpts po;

xregPROG_OPTS_SET_COMPILE_DATE(po);

po.set_help("Converts a collection of 2D projection images from .rad/.raw format "
"into an HDF5 projection data file for use by xReg. "
"This may be used to convert projections from the Ljubljana 2D/3D datasets "
"located at: http://lit.fe.uni-lj.si/tools.php?lang=eng.");
po.set_arg_usage("<Output Proj. Data File> <.rad path #1> [<.rad path #2> [... <.rad path #N>]]");
po.set_min_num_pos_args(2);

try
{
po.parse(argc, argv);
}
catch (const ProgOpts::Exception& e)
{
std::cerr << "Error parsing command line arguments: " << e.what() << std::endl;
po.print_usage(std::cerr);
return kEXIT_VAL_BAD_USE;
}

if (po.help_set())
{
po.print_usage(std::cout);
po.print_help(std::cout);
return kEXIT_VAL_SUCCESS;
}

std::ostream& vout = po.vout();

const std::string& dst_pd_path = po.pos_args()[0];

const size_type num_rad_files = po.pos_args().size() - 1;

vout << "number of .rad files to read: " << num_rad_files << std::endl;

ProjDataF32List pd;
pd.reserve(num_rad_files);

for (size_type i = 0; i < num_rad_files; ++i)
{
const std::string& cur_rad_path = po.pos_args()[i+1];

vout << "reading .rad file #" << (i + 1) << ": " << cur_rad_path << std::endl;

pd.push_back(ReadRawProjAsProjData(cur_rad_path));
}

vout << "saving to proj data HDF5..." << std::endl;
WriteProjDataH5ToDisk(pd, dst_pd_path);

vout << "exiting..." << std::endl;
return kEXIT_VAL_SUCCESS;
}

30 changes: 30 additions & 0 deletions apps/image_io/convert_radiograph_dicom_to_proj_data/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# MIT License
#
# Copyright (c) 2021 Robert Grupp
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

set(EXE_NAME "${XREG_EXE_PREFIX}convert-radiograph-dcm-to-proj-data")

add_executable(${EXE_NAME} xreg_convert_radiograph_dcm_to_proj_data_main.cpp)

target_link_libraries(${EXE_NAME} PUBLIC ${XREG_EXE_LIBS_TO_LINK})

install(TARGETS ${EXE_NAME})

Loading

0 comments on commit ae2ab80

Please sign in to comment.