# HG changeset patch # User Markus Mützel # Date 1629993270 -7200 # Node ID cb17f5f87a0ff0c366bc22be214e338c7554a476 # Parent c3ad8279a50661ccc6a21efb7d5e9139f0c1d6d9 of-image: Cleanup patch. * src/of-image-1-namespace.patch: Remove unnecessary hunk from patch. diff -r c3ad8279a506 -r cb17f5f87a0f src/of-image-1-namespace.patch --- a/src/of-image-1-namespace.patch Tue Sep 14 19:08:40 2021 +0200 +++ b/src/of-image-1-namespace.patch Thu Aug 26 17:54:30 2021 +0200 @@ -113,184 +113,6 @@ const dim_vector& padded_size, T& im, const P& val) { -diff -uNr a/src/connectivity.h.orig b/src/connectivity.h.orig ---- a/src/connectivity.h.orig 1969-12-31 19:00:00.000000000 -0500 -+++ b/src/connectivity.h.orig 2021-08-20 03:41:55.317910045 -0400 -@@ -0,0 +1,174 @@ -+// Copyright (C) 2014 Carnë Draug -+// -+// This program is free software; you can redistribute it and/or -+// modify it under the terms of the GNU General Public License as -+// published by the Free Software Foundation; either version 3 of the -+// License, or (at your option) any later version. -+// -+// This program is distributed in the hope that it will be useful, but -+// WITHOUT ANY WARRANTY; without even the implied warranty of -+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -+// General Public License for more details. -+// -+// You should have received a copy of the GNU General Public License -+// along with this program; if not, see -+// . -+ -+#ifndef OCTAVE_IMAGE_CONNDEF -+#define OCTAVE_IMAGE_CONNDEF -+ -+#include -+#include -+#include -+ -+#include -+#include -+#include -+#include -+#include // octave_Inf -+ -+#include -+ -+namespace octave_image -+{ -+ class connectivity -+ { -+ public: -+ connectivity () = default; -+ -+ //! Will throw if val is bad -+ explicit connectivity (const boolNDArray& mask_arg); -+ explicit connectivity (const unsigned int conn); -+ connectivity (const octave_idx_type& ndims, const std::string& type); -+ -+ boolNDArray mask; -+ -+ // For a matrix of size `size', what are the offsets for all of its -+ // connected elements (will have negative and positive values). -+ Array neighbourhood (const dim_vector& size) const; -+ Array deleted_neighbourhood (const dim_vector& size) const; -+ Array positive_neighbourhood (const dim_vector& size) const; -+ Array negative_neighbourhood (const dim_vector& size) const; -+ -+ template -+ T create_padded (const T& image, const P& val) const; -+ -+ template -+ void unpad (T& image) const; -+ -+ //! Return a logical mask of elements that are part of the padding. -+ static boolNDArray padding_mask (const dim_vector& size, -+ const dim_vector& padded_size); -+ -+ //! Set the padding elements to a specific value. -+ template -+ static void set_padding (const dim_vector& size, -+ const dim_vector& padded_size, -+ T& im, const P& val); -+ -+ template -+ static P min_value (void); -+ -+ static Array padding_lengths (const dim_vector& size, -+ const dim_vector& padded_size); -+ -+ private: -+ //! Like Array::ndims() but will return 1 dimension for ColumnVector -+ static octave_idx_type ndims (const dim_vector& d); -+ template -+ static octave_idx_type ndims (const Array& a); -+ }; -+ -+ class invalid_connectivity : public std::invalid_argument -+ { -+ public: -+ invalid_connectivity (const std::string& what_arg) -+ : std::invalid_argument (what_arg) { } -+ }; -+ -+ connectivity conndef (const octave_value& val); -+} -+ -+// Templated methods -+ -+template -+T -+octave_image::connectivity::create_padded (const T& image, const P& val) const -+{ -+ const octave_idx_type pad_ndims = std::min (mask.ndims (), image.ndims ()); -+ -+ Array idx (dim_vector (image.ndims (), 1), 0); -+ dim_vector padded_size = image.dims (); -+ for (octave_idx_type i = 0; i < pad_ndims; i++) -+ { -+ padded_size(i) += 2; -+ idx(i) = 1; -+ } -+ -+ T padded (padded_size, val); -+ -+ // padded(2:end-1, 2:end-1, ..., 2:end-1) = BW -+ padded.insert (image, idx); -+ return padded; -+} -+ -+template -+void -+octave_image::connectivity::unpad (T& image) const -+{ -+ const octave_idx_type pad_ndims = std::min (mask.ndims (), image.ndims ()); -+ const dim_vector padded_size = image.dims (); -+ -+ Array inner_slice (dim_vector (image.ndims (), 1)); -+ for (octave_idx_type i = 0; i < pad_ndims ; i++) -+ inner_slice(i) = idx_vector (1, padded_size(i) - 1); -+ for (octave_idx_type i = pad_ndims; i < image.ndims (); i++) -+ inner_slice(i) = idx_vector (0, padded_size(i)); -+ -+ image = image.index (inner_slice); -+ return; -+} -+ -+template -+P -+octave_image::connectivity::min_value (void) -+{ -+ if (typeid (P) == typeid (bool)) -+ return false; -+ else -+ return P(-octave_Inf); -+} -+ -+template -+void -+octave_image::connectivity::set_padding (const dim_vector& size, -+ const dim_vector& padded_size, -+ T& im, const P& val) -+{ -+ P* im_v = im.fortran_vec (); -+ -+ const Array lengths = padding_lengths (size, padded_size); -+ const octave_idx_type* lengths_v = lengths.fortran_vec (); -+ -+ const octave_idx_type* strides_v = size.to_jit (); -+ const octave_idx_type row_stride = strides_v[0]; -+ -+ std::function fill; -+ fill = [&] (const octave_idx_type dim) -> void -+ { -+ for (octave_idx_type i = 0; i < lengths_v[dim]; i++, im_v++) -+ *im_v = val; -+ -+ if (dim == 0) -+ im_v += row_stride; -+ else -+ for (octave_idx_type i = 0; i < strides_v[dim]; i++) -+ fill (dim -1); -+ -+ for (octave_idx_type i = 0; i < lengths_v[dim]; i++, im_v++) -+ *im_v = val; -+ }; -+ fill (im.ndims () -1); -+} -+ -+#endif diff -uNr a/src/imerode.cc b/src/imerode.cc --- a/src/imerode.cc 2020-02-02 08:20:08.000000000 -0500 +++ b/src/imerode.cc 2021-08-20 03:42:06.186092277 -0400