Skip to content

Commit

Permalink
Merge pull request #404 from clEsperanto/add-parametric-map
Browse files Browse the repository at this point in the history
add parametric maps
  • Loading branch information
StRigaud authored Nov 29, 2024
2 parents 5a01215 + 25271bf commit 6a86a6b
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 2 deletions.
69 changes: 69 additions & 0 deletions clic/include/tier4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,75 @@ extension_ratio_map_func(const Device::Pointer & device, const Array::Pointer &
-> Array::Pointer;


/**
* @name minimum_intensity_map
* @brief Takes an image and a corresponding label map, determines the minimum
* intensity per label and replaces every label with the that number.
*
* This results in a parametric image expressing minimum object intensity.
*
* @param device Device to perform the operation on. [const Device::Pointer &]
* @param src intensity image [const Array::Pointer &]
* @param labels label image [const Array::Pointer &]
* @param dst Parametric image computed[Array::Pointer ( = None )]
* @return Array::Pointer
*
* @note 'label measurement', 'map', 'in assistant', 'combine'
* @see https://clij.github.io/clij2-docs/reference_minimumIntensityMap
*/
auto
minimum_intensity_map_func(const Device::Pointer & device,
const Array::Pointer & src,
const Array::Pointer & labels,
Array::Pointer dst) -> Array::Pointer;


/**
* @name maximum_intensity_map
* @brief Takes an image and a corresponding label map, determines the maximum
* intensity per label and replaces every label with the that number.
*
* This results in a parametric image expressing maximum object intensity.
*
* @param device Device to perform the operation on. [const Device::Pointer &]
* @param src intensity image [const Array::Pointer &]
* @param labels label image [const Array::Pointer &]
* @param dst Parametric image computed[Array::Pointer ( = None )]
* @return Array::Pointer
*
* @note 'label measurement', 'map', 'in assistant', 'combine'
* @see https://clij.github.io/clij2-docs/reference_maximumIntensityMap
*/
auto
maximum_intensity_map_func(const Device::Pointer & device,
const Array::Pointer & src,
const Array::Pointer & labels,
Array::Pointer dst) -> Array::Pointer;


/**
* @name standard_deviation_intensity_map
* @brief Takes an image and a corresponding label map, determines the standard deviation
* intensity per label and replaces every label with the that number.
*
* This results in a parametric image expressing std object intensity.
*
* @param device Device to perform the operation on. [const Device::Pointer &]
* @param src intensity image [const Array::Pointer &]
* @param labels label image [const Array::Pointer &]
* @param dst Parametric image computed[Array::Pointer ( = None )]
* @return Array::Pointer
*
* @note 'label measurement', 'map', 'in assistant', 'combine'
* @see https://clij.github.io/clij2-docs/reference_standardDeviationIntensityMap
*/
auto
standard_deviation_intensity_map_func(const Device::Pointer & device,
const Array::Pointer & src,
const Array::Pointer & labels,
Array::Pointer dst) -> Array::Pointer;


} // namespace cle::tier4

#endif // __INCLUDE_TIER4_HPP
64 changes: 62 additions & 2 deletions clic/src/tier4/parametrics_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ auto
pixel_count_map_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer
{
tier0::create_like(src, dst, dType::FLOAT);
auto props = tier3::statistics_of_background_and_labelled_pixels_func(device, nullptr, src);
auto props = tier3::statistics_of_background_and_labelled_pixels_func(device, src, src);

auto values = cle::Array::create(props["area"].size(), 1, 1, 1, dType::FLOAT, mType::BUFFER, device);
values->writeFrom(props["area"].data());
Expand All @@ -36,7 +36,7 @@ extension_ratio_map_func(const Device::Pointer & device, const Array::Pointer &
-> Array::Pointer
{
tier0::create_like(src, dst, dType::FLOAT);
auto props = tier3::statistics_of_background_and_labelled_pixels_func(device, nullptr, src);
auto props = tier3::statistics_of_background_and_labelled_pixels_func(device, src, src);
auto vector = props["mean_max_distance_to_centroid_ratio"];
auto values = Array::create(vector.size(), 1, 1, 1, dType::FLOAT, mType::BUFFER, device);
values->writeFrom(vector.data());
Expand All @@ -60,5 +60,65 @@ mean_intensity_map_func(const Device::Pointer & device,
return tier1::replace_values_func(device, labels, values, dst);
}

auto
minimum_intensity_map_func(const Device::Pointer & device,
const Array::Pointer & src,
const Array::Pointer & labels,
Array::Pointer dst) -> Array::Pointer
{
tier0::create_like(src, dst, dType::FLOAT);
auto props = tier3::statistics_of_background_and_labelled_pixels_func(device, src, labels);

auto values = cle::Array::create(props["min_intensity"].size(), 1, 1, 1, dType::FLOAT, mType::BUFFER, device);
values->writeFrom(props["min_intensity"].data());

tier1::set_column_func(device, values, 0, 0);
return tier1::replace_values_func(device, labels, values, dst);
}

auto
maximum_intensity_map_func(const Device::Pointer & device,
const Array::Pointer & src,
const Array::Pointer & labels,
Array::Pointer dst) -> Array::Pointer
{
tier0::create_like(src, dst, dType::FLOAT);
auto props = tier3::statistics_of_background_and_labelled_pixels_func(device, src, labels);

auto values = cle::Array::create(props["max_intensity"].size(), 1, 1, 1, dType::FLOAT, mType::BUFFER, device);
values->writeFrom(props["max_intensity"].data());

tier1::set_column_func(device, values, 0, 0);
return tier1::replace_values_func(device, labels, values, dst);
}

auto
standard_deviation_intensity_map_func(const Device::Pointer & device,
const Array::Pointer & src,
const Array::Pointer & labels,
Array::Pointer dst) -> Array::Pointer
{
tier0::create_like(src, dst, dType::FLOAT);
auto props = tier3::statistics_of_background_and_labelled_pixels_func(device, src, labels);

auto values = cle::Array::create(props["std_intensity"].size(), 1, 1, 1, dType::FLOAT, mType::BUFFER, device);
values->writeFrom(props["std_intensity"].data());

tier1::set_column_func(device, values, 0, 0);
return tier1::replace_values_func(device, labels, values, dst);
}


auto
touching_neighbor_count_map_func(const Device::Pointer & device, const Array::Pointer & labels, Array::Pointer dst)
-> Array::Pointer
{
tier0::create_like(labels, dst, dType::FLOAT);
auto touch_matrix = tier3::generate_touch_matrix_func(device, labels, nullptr);
tier1::set_column_func(device, touch_matrix, 0, 0);
auto nb_touching_neighbors = tier2::count_touching_neighbors_func(device, touch_matrix, nullptr, true);
return tier1::replace_values_func(device, labels, nb_touching_neighbors, dst);
}


} // namespace cle::tier4

0 comments on commit 6a86a6b

Please sign in to comment.