Skip to content

Commit

Permalink
WIP: read-segmentation.cxx updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jadh4v committed Jun 25, 2024
1 parent 29953f9 commit 7309b67
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 44 deletions.
51 changes: 30 additions & 21 deletions packages/dicom/dcmtk/read-segmentation.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
* limitations under the License.
*
*=========================================================================*/
// CLP includes
// #include "dcmqi/segimage2itkimageCLP.h"
// #include "itkSmartPointer.h"

// DCMQI includes
// #undef HAVE_SSTREAM // Avoid redefinition warning
Expand All @@ -34,14 +31,20 @@
// ITK-wasm includes
#include "itkPipeline.h"
#include "itkOutputImage.h"
#include "itkOutputTextStream.h"

typedef dcmqi::Helper helper;
constexpr unsigned int Dimension = 3;
using PixelType = short;
using ScalarImageType = itk::Image<PixelType, Dimension>;
using VectorImageType = itk::VectorImage<PixelType, Dimension>;

int runPipeline(itk::wasm::Pipeline & pipeline, const std::string & inputSEGFileName, itk::wasm::OutputImage<VectorImageType> outputImage, const bool mergeSegments)
int runPipeline(
itk::wasm::Pipeline & pipeline,
const std::string & inputSEGFileName,
itk::wasm::OutputImage<VectorImageType> outputImage,
itk::wasm::OutputTextStream& outputMetaInfoJSON,
const bool mergeSegments)
{
#if !defined(NDEBUG) || defined(_DEBUG)
// Display DCMTK debug, warning, and error logs in the console
Expand All @@ -56,7 +59,7 @@ int runPipeline(itk::wasm::Pipeline & pipeline, const std::string & inputSEGFile
DcmRLEDecoderRegistration::registerCodecs();

DcmFileFormat sliceFF;
std::cout << "Loading DICOM SEG file " << inputSEGFileName << std::endl;
// std::cout << "Loading DICOM SEG file " << inputSEGFileName << std::endl;
CHECK_COND(sliceFF.loadFile(inputSEGFileName.c_str()));
DcmDataset* dataset = sliceFF.getDataset();

Expand All @@ -71,22 +74,25 @@ int runPipeline(itk::wasm::Pipeline & pipeline, const std::string & inputSEGFile
return EXIT_FAILURE;
}

/*
using ImageToVectorImageFilterType = itk::ComposeImageFilter<ScalarImageType>;
auto imageToVectorImageFilter = ImageToVectorImageFilterType::New();
imageToVectorImageFilter->SetInput(0, image0);
imageToVectorImageFilter->SetInput(1, image1);
imageToVectorImageFilter->SetInput(2, image2);
imageToVectorImageFilter->Update();
VectorImageType::Pointer vectorImage = imageToVectorImageFilter->GetOutput();
*/

itk::SmartPointer<ScalarImageType> itkImage = converter.begin();
if (itkImage)
using ImageToVectorImageFilterType = itk::ComposeImageFilter<ScalarImageType>;
auto imageToVectorImageFilter = ImageToVectorImageFilterType::New();
int inputNumber = 0;
for (auto itkImage = converter.begin(); itkImage != nullptr; itkImage = converter.next())
{
// outputImage.Set(itkImage);
return EXIT_SUCCESS;
imageToVectorImageFilter->SetInput(inputNumber++, itkImage);
}
imageToVectorImageFilter->Update();
std::cout << "SDJ total scalar images: " << inputNumber << std::endl;

VectorImageType::Pointer vectorImage = imageToVectorImageFilter->GetOutput();
itk::Index<3> idx0;
idx0.Fill(0);
std::cout << "vectorImage->GetPixel(0) = " << vectorImage->GetPixel(idx0) << std::endl;
if (vectorImage)
{
outputImage.Set(vectorImage);
outputMetaInfoJSON.Get() << metaInfo.c_str();
return EXIT_SUCCESS;
}
}
catch (int e)
Expand All @@ -108,13 +114,16 @@ int main(int argc, char * argv[])
itk::wasm::OutputImage<VectorImageType> outputImage;
pipeline.add_option("outputImage", outputImage, "dicom segmentation object as an image")->required()->type_name("OUTPUT_IMAGE");

itk::wasm::OutputTextStream outputMetaInfoJSON;
pipeline.add_option("output-meta-info-json", outputMetaInfoJSON, "Output overlay information")->type_name("OUTPUT_JSON");

bool mergeSegments{false};
pipeline.add_flag("--merge-segments", mergeSegments, "Merge segments into a single image");

ITK_WASM_PARSE(pipeline);

// Pipeline code goes here
runPipeline(pipeline, dicomFileName, outputImage, mergeSegments);
runPipeline(pipeline, dicomFileName, outputImage, outputMetaInfoJSON, mergeSegments);

return EXIT_SUCCESS;
}
Expand Down
66 changes: 43 additions & 23 deletions packages/dicom/dcmtk/write-segmentation.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
* limitations under the License.
*
*=========================================================================*/
// CLP includes
// #include "dcmqi/segimage2itkimageCLP.h"
// #include "itkSmartPointer.h"

// DCMQI includes
#include "dcmqi/Itk2DicomConverter.h"
Expand All @@ -29,34 +26,57 @@
#include "dcmtk/oflog/configrt.h"

#include "itkPipeline.h"
#include "itkOutputImage.h"
#include "itkVectorImage.h"

typedef dcmqi::Helper helper;
constexpr unsigned int Dimension = 3;
using PixelType = short;
using ScalarImageType = itk::Image<PixelType, Dimension>;
using VectorImageType = itk::VectorImage<PixelType, Dimension>;
int runPipeline(itk::wasm::Pipeline & pipeline, itk::wasm::InputImage<ImageType> inputImage, const std::string & outputDICOMFilename)
{
return EXIT_FAILURE;
}
#include "itkInputImage.h"
#include "itkOutputBinaryStream.h"
#include "itkSupportInputImageTypes.h"

int main(int argc, char * argv[])
template <typename TImage>
int writeSegmentation(itk::wasm::Pipeline &pipeline, const TImage * inputImage)
{
itk::wasm::Pipeline pipeline("write-segmentation", "Write segmentation image as DICOM object", argc, argv);
using ImageType = TImage;
constexpr unsigned int Dimension = ImageType::ImageDimension;
using PixelType = typename ImageType::PixelType;

pipeline.get_option("input-image")->required()->type_name("INPUT_IMAGE");

std::string dicomFileName;
pipeline.add_option("dicom-file", dicomFileName, "Input DICOM file")->required()->check(CLI::ExistingFile)->type_name("INPUT_BINARY_FILE");
std::string inputRefDicomSeries = 0;
pipeline.add_option("input-ref-dicom-series", inputRefDicomSeries, "input reference dicom series over which the segmentation was created")->required();

itk::wasm::OutputImage<ImageType> outputImage;
pipeline.add_option("outputImage", outputImage, "dicom segmentation object as an image")->required()->type_name("OUTPUT_IMAGE");
// itk::wasm::OutputBinaryStream outputDicomFile;
// pipeline.add_option("output-dicom-file", outputDicomFile, "written dicom segfile")->required()->type_name("OUTPUT_BINARY_STREAM");
std::string outputDicomFile;
pipeline.add_option("output-dicom-file", outputDicomFile, "written dicom segfile")->required()->type_name("OUTPUT_BINARY_FILE");

ITK_WASM_PARSE(pipeline);

// Pipeline code goes here
runPipeline(pipeline, dicomFileName, outputImage);

return EXIT_SUCCESS;
}


template <typename TImage>
class PipelineFunctor
{
public:
int operator()(itk::wasm::Pipeline &pipeline)
{
using ImageType = TImage;

itk::wasm::InputImage<ImageType> inputImage;
pipeline.add_option("input-image", inputImage, "input segmentation image to write")->type_name("INPUT_IMAGE");

ITK_WASM_PRE_PARSE(pipeline);

typename ImageType::ConstPointer inputImageRef = inputImage.Get();
return writeSegmentation<ImageType>(pipeline, inputImageRef);
}
};

int main(int argc, char * argv[])
{
itk::wasm::Pipeline pipeline("write-segmentation", "Write DICOM segmentation object", argc, argv);

return itk::wasm::SupportInputImageTypes<PipelineFunctor,
int16_t>
::Dimensions<2U, 3U>("input-image", pipeline);
}

0 comments on commit 7309b67

Please sign in to comment.