diff --git a/changelogs/diplib_next.md b/changelogs/diplib_next.md index e2f4ab1b..939cd232 100644 --- a/changelogs/diplib_next.md +++ b/changelogs/diplib_next.md @@ -74,6 +74,8 @@ date: 2020-00-00 the data over when the input was binary. In that case it now creates a new uint8 image that points to the same data segment of the binary image, as intended. +- `dip::EdgeObjectsRemove()` produced an empty output image when the input and output images were the same object. + ### Updated dependencies ### Build changes diff --git a/src/regions/label_manipulation.cpp b/src/regions/label_manipulation.cpp index 698ab152..c8ac13b3 100644 --- a/src/regions/label_manipulation.cpp +++ b/src/regions/label_manipulation.cpp @@ -243,11 +243,15 @@ void EdgeObjectsRemove( Image const& in, Image& out, dip::uint connectivity ) { DIP_THROW_IF( !in.IsScalar(), E::IMAGE_NOT_SCALAR ); if( in.DataType().IsBinary() ) { DIP_START_STACK_TRACE + Image tmp_in = in.QuickCopy(); + if( out.Aliases( tmp_in )) { // make sure we don't overwrite in + DIP_STACK_TRACE_THIS( out.Strip() ); + } // Propagate with empty seed mask, iteration until done and treating outside the image as object - BinaryPropagation( Image(), in, out, static_cast< dip::sint >( connectivity ), 0, S::OBJECT ); + BinaryPropagation( Image(), tmp_in, out, static_cast< dip::sint >( connectivity ), 0, S::OBJECT ); // The out-image now contains the edge objects // Remove them by toggling these bits in the in-image and writing the result in out - out ^= in; + out ^= tmp_in; DIP_END_STACK_TRACE } else if( in.DataType().IsUInt() ) { DIP_START_STACK_TRACE