diff --git a/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/Algorithms/ITKImportFijiMontage.cpp b/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/Algorithms/ITKImportFijiMontage.cpp index 2b5d62daf7..27fa38d188 100644 --- a/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/Algorithms/ITKImportFijiMontage.cpp +++ b/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/Algorithms/ITKImportFijiMontage.cpp @@ -1,6 +1,5 @@ #include "ITKImportFijiMontage.hpp" -#include "ITKImageProcessing/Common/ITKArrayHelper.hpp" #include "ITKImageProcessing/Common/ReadImageUtils.hpp" #include "ITKImageProcessing/Filters/ITKImageReaderFilter.hpp" @@ -201,7 +200,7 @@ class IOHandler // Ensure that we are dealing with in-core memory ONLY const IDataArray* inputArrayPtr = m_DataStructure.getDataAs(imageDataPath); - if(inputArrayPtr->getDataFormat() != "") + if(!inputArrayPtr->getDataFormat().empty()) { return MakeErrorResult(-9999, fmt::format("Input Array '{}' utilizes out-of-core data. This is not supported within ITK filters.", imageDataPath.toString())); } @@ -213,8 +212,17 @@ class IOHandler image->setSpacing(FloatVec3(1.0f, 1.0f, 1.0f)); // Use ITKUtils to read the image into the DataStructure - Result<> imageReaderResult = - cxItkImageReaderFilter::ReadImageExecute(bound.Filepath.string(), m_DataStructure, imageDataPath, bound.Filepath.string()); + Result<> imageReaderResult; + if(m_InputValues->changeDataType) + { + imageReaderResult = cxItkImageReaderFilter::ReadImageExecute(bound.Filepath.string(), m_DataStructure, bound.Filepath.string(), + imageDataPath, m_InputValues->destType); + } + else + { + imageReaderResult = + cxItkImageReaderFilter::ReadImageExecute(bound.Filepath.string(), m_DataStructure, imageDataPath, bound.Filepath.string()); + } if(imageReaderResult.invalid()) { for(const auto& error : imageReaderResult.errors()) diff --git a/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/Algorithms/ITKImportFijiMontage.hpp b/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/Algorithms/ITKImportFijiMontage.hpp index 0a6ea33d17..9bb63d8491 100644 --- a/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/Algorithms/ITKImportFijiMontage.hpp +++ b/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/Algorithms/ITKImportFijiMontage.hpp @@ -18,6 +18,8 @@ struct ITKIMAGEPROCESSING_EXPORT ITKImportFijiMontageInputValues bool changeOrigin = false; bool convertToGrayScale = false; bool parentDataGroup = false; + bool changeDataType = false; + DataType destType = DataType::uint8; fs::path inputFilePath = {}; IGeometry::LengthUnit lengthUnit = IGeometry::LengthUnit::Micrometer; std::vector origin = {}; diff --git a/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/ITKImageReaderFilter.cpp b/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/ITKImageReaderFilter.cpp index f5ca3c511c..aeee4a7ba2 100644 --- a/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/ITKImageReaderFilter.cpp +++ b/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/ITKImageReaderFilter.cpp @@ -116,7 +116,7 @@ IFilter::PreflightResult ITKImageReaderFilter::preflightImpl(const DataStructure auto origin = filterArgs.value(k_Origin_Key); auto spacing = filterArgs.value(k_Spacing_Key); auto pChangeDataType = filterArgs.value(k_ChangeDataType_Key); - auto choiceType = filterArgs.value(k_ImageDataType_Key); + auto pChoiceType = filterArgs.value(k_ImageDataType_Key); std::string fileNameString = fileName.string(); @@ -128,7 +128,7 @@ IFilter::PreflightResult ITKImageReaderFilter::preflightImpl(const DataStructure imageReaderOptions.Origin = FloatVec3(static_cast(origin[0]), static_cast(origin[1]), static_cast(origin[2])); imageReaderOptions.Spacing = FloatVec3(static_cast(spacing[0]), static_cast(spacing[1]), static_cast(spacing[2])); imageReaderOptions.ChangeDataType = pChangeDataType; - imageReaderOptions.ImageDataType = ITK::detail::ConvertChoiceToDataType(choiceType); + imageReaderOptions.ImageDataType = ITK::detail::ConvertChoiceToDataType(pChoiceType); Result result = cxItkImageReaderFilter::ReadImagePreflight(fileNameString, imageGeomPath, cellDataName, imageDataArrayName, imageReaderOptions); diff --git a/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/ITKImportFijiMontageFilter.cpp b/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/ITKImportFijiMontageFilter.cpp index 09c3967cc6..7a995cae4d 100644 --- a/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/ITKImportFijiMontageFilter.cpp +++ b/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/ITKImportFijiMontageFilter.cpp @@ -2,6 +2,7 @@ #include "Algorithms/ITKImportFijiMontage.hpp" +#include "ITKImageProcessing/Common/ITKArrayHelper.hpp" #include "ITKImageProcessing/Filters/ITKImageReaderFilter.hpp" #include "simplnx/Core/Application.hpp" @@ -84,6 +85,9 @@ Parameters ITKImportFijiMontageFilter::parameters() const std::make_unique(k_ConvertToGrayScale_Key, "Convert To GrayScale", "The filter will show an error if the images are already in grayscale format", false)); params.insert(std::make_unique(k_ColorWeights_Key, "Color Weighting", "The luminosity values for the conversion", std::vector{0.2125f, 0.7154f, 0.0721f}, std::vector(3))); + params.insertLinkableParameter(std::make_unique(k_ChangeDataType_Key, "Set Image Data Type", "Set the final created image data type.", false)); + params.insert(std::make_unique(k_ImageDataType_Key, "Output Data Type", "Numeric Type of data to create", 0ULL, + ChoicesParameter::Choices{"uint8", "uint16", "uint32"})); // Sequence Dependent DO NOT REORDER params.insertLinkableParameter(std::make_unique(k_ParentDataGroup_Key, "Parent Imported Images Under a DataGroup", "Create a new DataGroup to hold the imported images", true)); params.insertSeparator(Parameters::Separator{"Output Data Object(s)"}); @@ -93,6 +97,7 @@ Parameters ITKImportFijiMontageFilter::parameters() const params.insert(std::make_unique(k_ImageDataArrayName_Key, "Image DataArray Name", "The name of the import image data", "Image")); // Associate the Linkable Parameter(s) to the children parameters that they control + params.linkParameters(k_ChangeDataType_Key, k_ImageDataType_Key, true); params.linkParameters(k_ChangeOrigin_Key, k_Origin_Key, true); params.linkParameters(k_ConvertToGrayScale_Key, k_ColorWeights_Key, true); params.linkParameters(k_ParentDataGroup_Key, k_DataGroupName_Key, true); @@ -120,6 +125,8 @@ IFilter::PreflightResult ITKImportFijiMontageFilter::preflightImpl(const DataStr auto pDataContainerPathValue = filterArgs.value(k_DataContainerPath_Key); auto pCellAttributeMatrixNameValue = filterArgs.value(k_CellAttributeMatrixName_Key); auto pImageDataArrayNameValue = filterArgs.value(k_ImageDataArrayName_Key); + auto pChangeDataType = filterArgs.value(k_ChangeDataType_Key); + auto pChoiceType = filterArgs.value(k_ImageDataType_Key); PreflightResult preflightResult; nx::core::Result resultOutputActions = {}; @@ -132,6 +139,8 @@ IFilter::PreflightResult ITKImportFijiMontageFilter::preflightImpl(const DataStr inputValues.inputFilePath = pInputFileValue; inputValues.origin = pOriginValue; inputValues.imagePrefix = pDataContainerPathValue; + inputValues.changeDataType = pChangeDataType; + inputValues.destType = ITK::detail::ConvertChoiceToDataType(pChoiceType); // Read from the file if the input file has changed or the input file's time stamp is out of date. if(pInputFileValue != s_HeaderCache[m_InstanceId].inputFile || s_HeaderCache[m_InstanceId].timeStamp < fs::last_write_time(pInputFileValue) || s_HeaderCache[m_InstanceId].valuesChanged(inputValues)) @@ -175,6 +184,8 @@ IFilter::PreflightResult ITKImportFijiMontageFilter::preflightImpl(const DataStr imageImportArgs.insertOrAssign(ITKImageReaderFilter::k_ImageGeometryPath_Key, std::make_any(imageDataProxy.getParent().getParent())); imageImportArgs.insertOrAssign(ITKImageReaderFilter::k_CellDataName_Key, std::make_any(imageDataProxy.getParent().getTargetName())); imageImportArgs.insertOrAssign(ITKImageReaderFilter::k_ImageDataArrayPath_Key, std::make_any(imageDataProxy.getTargetName())); + imageImportArgs.insertOrAssign(ITKImageReaderFilter::k_ChangeDataType_Key, std::make_any(pChangeDataType)); + imageImportArgs.insertOrAssign(ITKImageReaderFilter::k_ImageDataType_Key, std::make_any(pChoiceType)); auto result = imageImportFilter.preflight(dataStructure, imageImportArgs, messageHandler, shouldCancel); if(result.outputActions.invalid()) @@ -230,6 +241,8 @@ Result<> ITKImportFijiMontageFilter::executeImpl(DataStructure& dataStructure, c inputValues.imagePrefix = filterArgs.value(k_DataContainerPath_Key); inputValues.cellAMName = filterArgs.value(k_CellAttributeMatrixName_Key); inputValues.imageDataArrayName = filterArgs.value(k_ImageDataArrayName_Key); + inputValues.changeDataType = filterArgs.value(k_ChangeDataType_Key); + inputValues.destType = ITK::detail::ConvertChoiceToDataType(filterArgs.value(k_ImageDataType_Key)); ITKImportFijiMontage(dataStructure, messageHandler, shouldCancel, &inputValues, s_HeaderCache.find(m_InstanceId)->second)(); diff --git a/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/ITKImportFijiMontageFilter.hpp b/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/ITKImportFijiMontageFilter.hpp index b356cdd365..31d89f64ad 100644 --- a/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/ITKImportFijiMontageFilter.hpp +++ b/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/ITKImportFijiMontageFilter.hpp @@ -34,6 +34,8 @@ class ITKIMAGEPROCESSING_EXPORT ITKImportFijiMontageFilter : public IFilter static inline constexpr StringLiteral k_LengthUnit_Key = "length_unit_index"; static inline constexpr StringLiteral k_ChangeOrigin_Key = "change_origin"; static inline constexpr StringLiteral k_Origin_Key = "origin"; + static inline constexpr StringLiteral k_ChangeDataType_Key = "change_image_data_type"; + static inline constexpr StringLiteral k_ImageDataType_Key = "image_data_type_index"; static inline constexpr StringLiteral k_ParentDataGroup_Key = "parent_data_group"; static inline constexpr StringLiteral k_ConvertToGrayScale_Key = "convert_to_gray_scale"; static inline constexpr StringLiteral k_ColorWeights_Key = "color_weights";