18 #ifndef NDARRAY_IMAGE_H 19 #define NDARRAY_IMAGE_H 29 template <
class T,
class Alloc = std::allocator<T>>
41 template <index_t Channels = dynamic, index_t XStr
ide = Channels>
44 class Alloc = std::allocator<T>>
46 template <
class T, index_t Channels = dynamic, index_t XStr
ide = Channels>
48 template <
class T, index_t Channels = dynamic, index_t XStr
ide = Channels>
53 template <
class Shape,
class Fn>
62 fn(std::tuple<index_t, index_t, index_t>(x, y, c));
68 template <index_t Channels, index_t XStr
ide>
78 template <
class Ptr,
class Fn>
79 static void for_each_value(
const shape_type& s, Ptr base, Fn&& fn) {
85 template <index_t Channels>
97 template <
class Ptr,
class Fn>
98 static void for_each_value(
const shape_type& s, Ptr base, Fn&& fn) {
99 const index_t channels = s.c().extent();
100 if (channels == s.
x().stride()) {
101 dense_shape<2> opt_s({s.
x().min() * channels, s.
x().extent() * channels}, s.y());
102 for_each_value_in_order(opt_s, base, fn);
104 for_each_value_in_order(s, base, fn);
114 template <
class T,
class Alloc = std::allocator<T>>
121 enum class crop_origin {
131 template <
class Shape>
133 crop_origin origin = crop_origin::crop) {
134 s.x().set_extent(x1 - x0);
135 s.y().set_extent(y1 - y0);
137 case crop_origin::zero:
141 case crop_origin::crop:
152 template <
class T,
class Shape>
154 index_t y1, crop_origin origin = crop_origin::crop) {
155 x0 = internal::max(x0, im.
x().min());
156 y0 = internal::max(y0, im.y().min());
157 x1 = internal::min(x1, im.
x().max() + 1);
158 y1 = internal::min(y1, im.y().max() + 1);
161 T* base = im.
base() !=
nullptr ? &im(x0, y0, c0) :
nullptr;
162 if (origin == crop_origin::crop) {
163 base = internal::pointer_add(base, -cropped_shape(x0, y0, c0));
167 template <
class T,
class Shape>
169 index_t y1, crop_origin origin = crop_origin::crop) {
170 return crop(im.
ref(), x0, y0, x1, y1, origin);
172 template <
class T,
class Shape>
174 crop_origin origin = crop_origin::crop) {
175 return crop(im.
ref(), x0, y0, x1, y1, origin);
180 template <
class T,
class Shape>
182 return im(im.
x(), im.y(), channel);
184 template <
class T,
class Shape,
class Alloc>
188 template <
class T,
class Shape,
class Alloc>
195 #endif // NDARRAY_IMAGE_H NDARRAY_HOST_DEVICE Shape & shape()
Definition: array.h:2105
constexpr index_t dynamic
Definition: array.h:99
index_of_rank< rank()> index_type
Definition: array.h:1076
static NDARRAY_HOST_DEVICE void for_each_value(const Shape &shape, Ptr base, Fn &&fn)
Definition: array.h:1882
NDARRAY_HOST_DEVICE pointer base() const
Definition: array.h:2096
Shape crop_image_shape(Shape s, index_t x0, index_t y0, index_t x1, index_t y1, crop_origin origin=crop_origin::crop)
Definition: image.h:132
NDARRAY_HOST_DEVICE auto & x()
Definition: array.h:1274
Main header for array library.
auto slice_channel(const array_ref< T, Shape > &im, index_t channel)
Definition: image.h:181
array_ref< T, Shape > crop(const array_ref< T, Shape > &im, index_t x0, index_t y0, index_t x1, index_t y1, crop_origin origin=crop_origin::crop)
Definition: image.h:153
NDARRAY_HOST_DEVICE auto & x()
Definition: array.h:2132
void for_each_image_index(const Shape &s, Fn &&fn)
Definition: image.h:54
std::ptrdiff_t index_t
Definition: array.h:87
static NDARRAY_HOST_DEVICE void for_each_index(const Shape &shape, Fn &&fn)
Definition: array.h:1874
array_ref< T, Shape > ref()
Definition: array.h:2675
decltype(internal::make_default_dense_shape< Rank >()) dense_shape
Definition: array.h:1606