Skip to content

Commit

Permalink
feat: add int and bool support to grey dilate and erosion
Browse files Browse the repository at this point in the history
  • Loading branch information
william-silversmith committed Dec 31, 2023
1 parent 802fdf7 commit 5e3d16b
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions fastmorph/fastmorphops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ py::array multilabel_erode(const py::array &labels, const uint64_t threads) {

// assumes fortran order
py::array grey_dilate(const py::array &labels, const uint64_t threads) {
int width = labels.dtype().itemsize();
py::dtype dt = labels.dtype();
int width = dt.itemsize();

const uint64_t sx = labels.shape()[0];
const uint64_t sy = labels.shape()[1];
Expand All @@ -134,17 +135,36 @@ py::array grey_dilate(const py::array &labels, const uint64_t threads) {
);\
return to_numpy(reinterpret_cast<int_t*>(output_ptr), sx, sy, sz);

if (width == 1) {
GREY_DILATE_HELPER(uint8_t)
}
else if (width == 2) {
GREY_DILATE_HELPER(uint16_t)
if (dt.kind() == 'i') {
if (width == 1) {
GREY_DILATE_HELPER(int8_t)
}
else if (width == 2) {
GREY_DILATE_HELPER(int16_t)
}
else if (width == 4) {
GREY_DILATE_HELPER(int32_t)
}
else {
GREY_DILATE_HELPER(int64_t)
}
}
else if (width == 4) {
GREY_DILATE_HELPER(uint32_t)
else if (dt.kind() == 'b') {
GREY_DILATE_HELPER(uint8_t)
}
else {
GREY_DILATE_HELPER(uint64_t)
if (width == 1) {
GREY_DILATE_HELPER(uint8_t)
}
else if (width == 2) {
GREY_DILATE_HELPER(uint16_t)
}
else if (width == 4) {
GREY_DILATE_HELPER(uint32_t)
}
else {
GREY_DILATE_HELPER(uint64_t)
}
}
#undef GREY_DILATE_HELPER
}
Expand Down Expand Up @@ -186,6 +206,9 @@ py::array grey_erode(const py::array &labels, const uint64_t threads) {
GREY_ERODE_HELPER(int64_t)
}
}
else if (dt.kind() == 'b') {
GREY_ERODE_HELPER(uint8_t)
}
else {
if (width == 1) {
GREY_ERODE_HELPER(uint8_t)
Expand Down

0 comments on commit 5e3d16b

Please sign in to comment.