Skip to content

Commit

Permalink
Merge pull request #386 from clEsperanto/morphological-operator
Browse files Browse the repository at this point in the history
Morphological operator
  • Loading branch information
StRigaud authored Nov 11, 2024
2 parents 3c05293 + 1c4204c commit e9899cd
Show file tree
Hide file tree
Showing 79 changed files with 1,242 additions and 1,512 deletions.
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
ci:
autoupdate_schedule: monthly
autofix_commit_msg: "style(pre-commit.ci): auto fixes"
autoupdate_commit_msg: "ci(pre-commit.ci): auto update"

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.20)

project(CLIc VERSION 0.14.2)

set(kernel_version_tag "3.0.2" CACHE STRING "clEsperanto kernel version tag")
set(kernel_version_tag "update-morphology-ops" CACHE STRING "clEsperanto kernel version tag")
set(eigen_lib_version_tag "3.4.0" CACHE STRING "Eigen library version tag")

# if not set, set the default build type to Release
Expand Down
310 changes: 215 additions & 95 deletions clic/include/tier1.hpp

Large diffs are not rendered by default.

270 changes: 177 additions & 93 deletions clic/include/tier2.hpp

Large diffs are not rendered by default.

28 changes: 0 additions & 28 deletions clic/src/tier1/dilate.cpp

This file was deleted.

23 changes: 0 additions & 23 deletions clic/src/tier1/dilate_box.cpp

This file was deleted.

23 changes: 0 additions & 23 deletions clic/src/tier1/dilate_sphere.cpp

This file was deleted.

82 changes: 82 additions & 0 deletions clic/src/tier1/dilation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include "tier0.hpp"
#include "tier1.hpp"

#include "utils.hpp"

#include "cle_dilate_box.h"
#include "cle_dilate_sphere.h"
#include "cle_dilation.h"

namespace cle::tier1
{

auto
dilation_func(const Device::Pointer & device,
const Array::Pointer & src,
const Array::Pointer & footprint,
Array::Pointer dst) -> Array::Pointer
{
tier0::create_like(src, dst);
if (src->dimension() != footprint->dimension())
{
throw std::runtime_error(
"Error: input and structuring element in dilation operator must have the same dimensionality.");
}
KernelInfo kernel = { "dilation", kernel::dilation };
const ParameterList params = { { "src", src }, { "footprint", footprint }, { "dst", dst } };
const RangeArray range = { dst->width(), dst->height(), dst->depth() };
execute(device, kernel, params, range);
return dst;
}

auto
binary_dilate_func(const Device::Pointer & device,
const Array::Pointer & src,
Array::Pointer dst,
float radius_x,
float radius_y,
float radius_z,
std::string connectivity) -> Array::Pointer
{
tier0::create_like(src, dst);
auto r_x = radius2kernelsize(radius_x);
auto r_y = radius2kernelsize(radius_y);
auto r_z = radius2kernelsize(radius_z);
KernelInfo kernel = { "dilate_box", kernel::dilate_box };
if (connectivity == "sphere")
{
kernel = { "dilate_sphere", kernel::dilate_sphere };
}
const ParameterList params = {
{ "src", src }, { "dst", dst }, { "scalar0", r_x }, { "scalar1", r_y }, { "scalar2", r_z }
};
const RangeArray range = { dst->width(), dst->height(), dst->depth() };
execute(device, kernel, params, range);
return dst;
}

auto
dilate_box_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer
{
return binary_dilate_func(device, src, dst, 1, 1, 1, "box");
}

auto
dilate_sphere_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer
{
return binary_dilate_func(device, src, dst, 1, 1, 1, "sphere");
}

auto
grayscale_dilate_func(const Device::Pointer & device,
const Array::Pointer & src,
Array::Pointer dst,
float radius_x,
float radius_y,
float radius_z,
std::string connectivity) -> Array::Pointer
{
return tier1::maximum_filter_func(device, src, dst, radius_x, radius_y, radius_z, connectivity);
}

} // namespace cle::tier1
30 changes: 0 additions & 30 deletions clic/src/tier1/erode.cpp

This file was deleted.

25 changes: 0 additions & 25 deletions clic/src/tier1/erode_box.cpp

This file was deleted.

23 changes: 0 additions & 23 deletions clic/src/tier1/erode_sphere.cpp

This file was deleted.

82 changes: 82 additions & 0 deletions clic/src/tier1/erosion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include "tier0.hpp"
#include "tier1.hpp"

#include "utils.hpp"

#include "cle_erode_box.h"
#include "cle_erode_sphere.h"
#include "cle_erosion.h"

namespace cle::tier1
{

auto
erosion_func(const Device::Pointer & device,
const Array::Pointer & src,
const Array::Pointer & footprint,
Array::Pointer dst) -> Array::Pointer
{
tier0::create_like(src, dst);
if (src->dimension() != footprint->dimension())
{
throw std::runtime_error(
"Error: input and structuring element in erosion operator must have the same dimensionality.");
}
KernelInfo kernel = { "erosion", kernel::erosion };
const ParameterList params = { { "src", src }, { "footprint", footprint }, { "dst", dst } };
const RangeArray range = { dst->width(), dst->height(), dst->depth() };
execute(device, kernel, params, range);
return dst;
}

auto
binary_erode_func(const Device::Pointer & device,
const Array::Pointer & src,
Array::Pointer dst,
float radius_x,
float radius_y,
float radius_z,
std::string connectivity) -> Array::Pointer
{
tier0::create_like(src, dst);
auto r_x = radius2kernelsize(radius_x);
auto r_y = radius2kernelsize(radius_y);
auto r_z = radius2kernelsize(radius_z);
KernelInfo kernel = { "erode_box", kernel::erode_box };
if (connectivity == "sphere")
{
kernel = { "erode_sphere", kernel::erode_sphere };
}
const ParameterList params = {
{ "src", src }, { "dst", dst }, { "scalar0", r_x }, { "scalar1", r_y }, { "scalar2", r_z }
};
const RangeArray range = { dst->width(), dst->height(), dst->depth() };
execute(device, kernel, params, range);
return dst;
}

auto
grayscale_erode_func(const Device::Pointer & device,
const Array::Pointer & src,
Array::Pointer dst,
float radius_x,
float radius_y,
float radius_z,
std::string connectivity) -> Array::Pointer
{
return tier1::minimum_filter_func(device, src, dst, radius_x, radius_y, radius_z, connectivity);
}

auto
erode_sphere_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer
{
return binary_erode_func(device, src, dst, 1, 1, 1, "sphere");
}

auto
erode_box_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer
{
return binary_erode_func(device, src, dst, 1, 1, 1, "box");
}

} // namespace cle::tier1
23 changes: 0 additions & 23 deletions clic/src/tier1/gradient_x.cpp

This file was deleted.

22 changes: 0 additions & 22 deletions clic/src/tier1/gradient_y.cpp

This file was deleted.

Loading

0 comments on commit e9899cd

Please sign in to comment.