Skip to content

Commit

Permalink
swap grayscale and resample execution order
Browse files Browse the repository at this point in the history
  • Loading branch information
nyoungbq authored and imikejackson committed Oct 16, 2024
1 parent 0c503b2 commit 271412f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ operations can be seen in Figures 1, 2 and 3

The optional resampling parameter has two options that affect the output image and size of the resulting geometry.

- Scaling Factor (1) - This is the scaling option that previously existed with the filter. It functions by providing a float value that becomes a XYZ scaling factor vector that is applied to each image before it is inserted into the final geometry. This means that the number of pixels in the resulting output image will be resampled to `{X * (ScalingFactor / 100.0), Y * (ScalingFactor / 100.0), Number of Images In Stack} (XYZ)`.
- Scaling Factor (1) - This is the scaling option that previously existed with the filter. It functions by providing a float value that becomes a XYZ scaling factor vector that is applied to each image before it is inserted into the final geometry. This means that the number of pixels in the resulting output image will be resampled to `{X * (ScalingFactor / 100.0), Y * (ScalingFactor / 100.0), Number of Images In Stack} (XYZ)`. This means that a value of 100 (Like 100%) will *NOT* perform any resampling. A value of 50 will produce a final output image that has half as many pixels along the X and Y Axis. A value of 200 will have twice as many voxels along the X and Y Axis.
- Exact XY Dimensions (2) - This is provided to allow for precision resampling along the Z Axis. The number of pixels in the resulting output image will be resampled to `{User Supplied X, User Supplied Y, Number of Images In Stack} (XYZ)`.

Both options are different ways to parameterize the resampling functionality. The main difference should be that `Scaling Factor (1)` is implicity uniform in its resampling across the X and Y dimensions, but the same is not true for `Exact XY Dimensions (2)`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,48 +193,6 @@ Result<> ReadImageStack(DataStructure& dataStructure, const DataPath& imageGeomP
}
}

// ======================= Convert to GrayScale Section ===================
bool validInputForGrayScaleConversion = importedDataStructure.getDataRefAs<IDataArray>(imageDataPath).getDataType() == DataType::uint8;
if(convertToGrayscale && validInputForGrayScaleConversion && nullptr != grayScaleFilter.get())
{
// This same filter was used to preflight so as long as nothing changes on disk this really should work....
Arguments colorToGrayscaleArgs;
colorToGrayscaleArgs.insertOrAssign("conversion_algorithm", std::make_any<ChoicesParameter::ValueType>(0));
colorToGrayscaleArgs.insertOrAssign("color_weights", std::make_any<VectorFloat32Parameter::ValueType>(luminosityValues));
colorToGrayscaleArgs.insertOrAssign("input_data_array_paths", std::make_any<std::vector<DataPath>>(std::vector<DataPath>{imageDataPath}));
colorToGrayscaleArgs.insertOrAssign("output_array_prefix", std::make_any<std::string>("gray"));

// Run grayscale filter and process results and messages
auto result = grayScaleFilter->execute(importedDataStructure, colorToGrayscaleArgs).result;
if(result.invalid())
{
return result;
}

// deletion of non-grayscale array
DataObject::IdType id;
{ // scoped for safety since this reference will be nonexistent in a moment
auto& oldArray = importedDataStructure.getDataRefAs<IDataArray>(imageDataPath);
id = oldArray.getId();
}
importedDataStructure.removeData(id);

// rename grayscale array to reflect original
{
auto& gray = importedDataStructure.getDataRefAs<IDataArray>(imageDataPath.replaceName("gray" + imageDataPath.getTargetName()));
if(!gray.canRename(imageDataPath.getTargetName()))
{
return MakeErrorResult(-64543, fmt::format("Unable to rename the internal grayscale array to {}", imageDataPath.getTargetName()));
}
gray.rename(imageDataPath.getTargetName());
}
}
else if(convertToGrayscale && !validInputForGrayScaleConversion)
{
outputResult.warnings().emplace_back(Warning{
-74320, fmt::format("The array ({}) resulting from reading the input image file is not a UInt8Array. The input image will not be converted to grayscale.", imageDataPath.getTargetName())});
}

// ======================= Resample Image Geometry Section ===================
switch(resample)
{
Expand Down Expand Up @@ -283,6 +241,48 @@ Result<> ReadImageStack(DataStructure& dataStructure, const DataPath& imageGeomP
}
}

// ======================= Convert to GrayScale Section ===================
bool validInputForGrayScaleConversion = importedDataStructure.getDataRefAs<IDataArray>(imageDataPath).getDataType() == DataType::uint8;
if(convertToGrayscale && validInputForGrayScaleConversion && nullptr != grayScaleFilter.get())
{
// This same filter was used to preflight so as long as nothing changes on disk this really should work....
Arguments colorToGrayscaleArgs;
colorToGrayscaleArgs.insertOrAssign("conversion_algorithm", std::make_any<ChoicesParameter::ValueType>(0));
colorToGrayscaleArgs.insertOrAssign("color_weights", std::make_any<VectorFloat32Parameter::ValueType>(luminosityValues));
colorToGrayscaleArgs.insertOrAssign("input_data_array_paths", std::make_any<std::vector<DataPath>>(std::vector<DataPath>{imageDataPath}));
colorToGrayscaleArgs.insertOrAssign("output_array_prefix", std::make_any<std::string>("gray"));

// Run grayscale filter and process results and messages
auto result = grayScaleFilter->execute(importedDataStructure, colorToGrayscaleArgs).result;
if(result.invalid())
{
return result;
}

// deletion of non-grayscale array
DataObject::IdType id;
{ // scoped for safety since this reference will be nonexistent in a moment
auto& oldArray = importedDataStructure.getDataRefAs<IDataArray>(imageDataPath);
id = oldArray.getId();
}
importedDataStructure.removeData(id);

// rename grayscale array to reflect original
{
auto& gray = importedDataStructure.getDataRefAs<IDataArray>(imageDataPath.replaceName("gray" + imageDataPath.getTargetName()));
if(!gray.canRename(imageDataPath.getTargetName()))
{
return MakeErrorResult(-64543, fmt::format("Unable to rename the internal grayscale array to {}", imageDataPath.getTargetName()));
}
gray.rename(imageDataPath.getTargetName());
}
}
else if(convertToGrayscale && !validInputForGrayScaleConversion)
{
outputResult.warnings().emplace_back(Warning{
-74320, fmt::format("The array ({}) resulting from reading the input image file is not a UInt8Array. The input image will not be converted to grayscale.", imageDataPath.getTargetName())});
}

// Check the ImageGeometry of the imported Image matches the destination
const auto& importedImageGeom = importedDataStructure.getDataRefAs<ImageGeom>(imageGeomPath);
SizeVec3 importedDims = importedImageGeom.getDimensions();
Expand Down

0 comments on commit 271412f

Please sign in to comment.