NumCpp
2.14.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
wrap2d.hpp
Go to the documentation of this file.
1
28
#pragma once
29
30
#include "
NumCpp/Core/Internal/StaticAsserts.hpp
"
31
#include "
NumCpp/Core/Shape.hpp
"
32
#include "
NumCpp/Core/Slice.hpp
"
33
#include "
NumCpp/Core/Types.hpp
"
34
#include "
NumCpp/Filter/Boundaries/Boundaries2d/fillCorners.hpp
"
35
#include "
NumCpp/NdArray.hpp
"
36
37
namespace
nc::filter::boundary
38
{
39
//============================================================================
40
// Method Description:
47
template
<
typename
dtype>
48
NdArray<dtype>
wrap2d
(
const
NdArray<dtype>
&
inImage
,
uint32
inBoundarySize
)
49
{
50
STATIC_ASSERT_ARITHMETIC
(
dtype
);
51
52
const
Shape
inShape
=
inImage
.shape();
53
Shape
outShape
(
inShape
);
54
outShape
.rows +=
inBoundarySize
* 2;
55
outShape
.cols +=
inBoundarySize
* 2;
56
57
NdArray<dtype>
outArray
(
outShape
);
58
outArray
.put(
Slice
(
inBoundarySize
,
inBoundarySize
+
inShape
.rows),
59
Slice
(
inBoundarySize
,
inBoundarySize
+
inShape
.cols),
60
inImage
);
61
62
// bottom
63
outArray
.put(
Slice
(0,
inBoundarySize
),
64
Slice
(
inBoundarySize
,
inBoundarySize
+
inShape
.cols),
65
inImage
(
Slice
(
inShape
.rows -
inBoundarySize
,
inShape
.rows),
Slice
(0,
inShape
.cols)));
66
67
// top
68
outArray
.put(
Slice
(
inShape
.rows +
inBoundarySize
,
outShape
.rows),
69
Slice
(
inBoundarySize
,
inBoundarySize
+
inShape
.cols),
70
inImage
(
Slice
(0,
inBoundarySize
),
Slice
(0,
inShape
.cols)));
71
72
// left
73
outArray
.put(
Slice
(
inBoundarySize
,
inBoundarySize
+
inShape
.rows),
74
Slice
(0,
inBoundarySize
),
75
inImage
(
Slice
(0,
inShape
.rows),
Slice
(
inShape
.cols -
inBoundarySize
,
inShape
.cols)));
76
77
// right
78
outArray
.put(
Slice
(
inBoundarySize
,
inBoundarySize
+
inShape
.rows),
79
Slice
(
inShape
.cols +
inBoundarySize
,
outShape
.cols),
80
inImage
(
Slice
(0,
inShape
.rows),
Slice
(0,
inBoundarySize
)));
81
82
// now fill in the corners
83
NdArray<dtype>
lowerLeft
=
outArray
(
Slice
(
inBoundarySize
, 2 *
inBoundarySize
),
Slice
(0,
inBoundarySize
));
84
NdArray<dtype>
lowerRight
=
85
outArray
(
Slice
(
inBoundarySize
, 2 *
inBoundarySize
),
Slice
(
outShape
.cols -
inBoundarySize
,
outShape
.cols));
86
87
const
uint32
upperRowStart
=
outShape
.rows - 2 *
inBoundarySize
;
88
NdArray<dtype>
upperLeft
=
89
outArray
(
Slice
(
upperRowStart
,
upperRowStart
+
inBoundarySize
),
Slice
(0,
inBoundarySize
));
90
NdArray<dtype>
upperRight
=
outArray
(
Slice
(
upperRowStart
,
upperRowStart
+
inBoundarySize
),
91
Slice
(
outShape
.cols -
inBoundarySize
,
outShape
.cols));
92
93
outArray
.put(
Slice
(0,
inBoundarySize
),
Slice
(0,
inBoundarySize
),
upperLeft
);
94
outArray
.put(
Slice
(0,
inBoundarySize
),
Slice
(
outShape
.cols -
inBoundarySize
,
outShape
.cols),
upperRight
);
95
outArray
.put(
Slice
(
outShape
.rows -
inBoundarySize
,
outShape
.rows),
Slice
(0,
inBoundarySize
),
lowerLeft
);
96
outArray
.put(
Slice
(
outShape
.rows -
inBoundarySize
,
outShape
.rows),
97
Slice
(
outShape
.cols -
inBoundarySize
,
outShape
.cols),
98
lowerRight
);
99
100
return
outArray
;
101
}
102
}
// namespace nc::filter::boundary
Shape.hpp
NdArray.hpp
Slice.hpp
StaticAsserts.hpp
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition
StaticAsserts.hpp:39
Types.hpp
nc::NdArray
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition
NdArrayCore.hpp:139
nc::Shape
A Shape Class for NdArrays.
Definition
Core/shape.hpp:41
nc::Slice
A Class for slicing into NdArrays.
Definition
Slice.hpp:45
fillCorners.hpp
nc::filter::boundary
Definition
addBoundary1d.hpp:44
nc::filter::boundary::wrap2d
NdArray< dtype > wrap2d(const NdArray< dtype > &inImage, uint32 inBoundarySize)
Definition
wrap2d.hpp:48
nc::arange
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition
arange.hpp:59
nc::uint32
std::uint32_t uint32
Definition
Types.hpp:40
include
NumCpp
Filter
Boundaries
Boundaries2d
wrap2d.hpp
Generated by
1.9.8