Go to the documentation of this file.
33 size_t dst_pitch_bytes,
35 size_t src_pitch_bytes,
37 uint8_t size_of_pixel);
60 template <
class TPixel>
105 details::pitchedCopy(
106 (uint8_t*)this->
ptr(),
108 (uint8_t
const*)
view.ptr(),
109 view.layout().pitchBytes(),
123 [[nodiscard]]
auto mut(
int u,
int v)
const -> TPixel& {
127 [[nodiscard]]
auto mut(Eigen::Vector2i uv)
const -> TPixel& {
128 return mut(uv[0], uv[1]);
134 template <
class TUnaryOperation>
135 void mutate(TUnaryOperation
const& unary_op)
const {
141 for (; p != end_of_row; ++p) {
152 template <
class TUVOperation>
159 for (
int u = 0; p != end_of_row; ++p, ++u) {
170 template <
class TOtherPixel,
class TUnaryOperation>
178 TOtherPixel
const* p =
view.rowPtr(v);
179 TOtherPixel
const* end_of_row = p +
view.layout().width();
181 for (; p != end_of_row; ++p, ++mut_p) {
182 *mut_p = unary_op(*p);
192 template <
class TLhsPixel,
class TRhsPixel,
class TBinaryOperation>
196 TBinaryOperation
const& binary_op)
const {
203 TLhsPixel
const* lhs_p = lhs.
rowPtr(v);
204 TRhsPixel
const* rhs_p = rhs.
rowPtr(v);
207 mut_p[u] = binary_op(lhs_p[u], rhs_p[u]);
215 void fill(TPixel
const& val)
const {
216 mutate([&](TPixel
const& ) {
return val; });
220 [[nodiscard]]
auto ptrMut() const -> TPixel* {
233 ImageLayout::makeFromSizeAndPitch<TPixel>(
241 template <
class TPixel>
242 auto checkedPixelAccessMut(
243 MutImageView<TPixel>
const& view,
246 std::string
const& file,
248 std::string
const&
str) -> TPixel& {
249 if (!view.colInBounds(u) || !view.rowInBounds(v)) {
252 "pixel `{},{}` not in image with size {} x {}",
255 view.imageSize().width,
256 view.imageSize().height);
258 ::fmt::print(stderr,
"{}",
str);
262 return view.mut(u, v);
268 #define SOPHUS_PIXEL_MUT(img, u, v, ...) \
269 ::sophus::details::checkedPixelAccessMut( \
270 img, u, v, __FILE__, __LINE__, SOPHUS_FORMAT(__VA_ARGS__))
auto mut(Eigen::Vector2i uv) const -> TPixel &
Definition: mut_image_view.h:127
auto rowPtrMut(int v) const -> TPixel *
Returns v-th row pointer of mutable pixel.
Definition: mut_image_view.h:115
auto height() const -> int
Definition: layout.h:55
#define SOPHUS_ASSERT(...)
Definition: common.h:40
auto isEmpty() const -> bool
Returns true if view is empty.
Definition: image_view.h:71
void transformFrom(ImageView< TOtherPixel > view, TUnaryOperation const &unary_op) const
Transforms view using unary operation and assigns result to this.
Definition: mut_image_view.h:171
auto pitchBytes() const -> size_t
Definition: layout.h:57
auto ptrMut() const -> TPixel *
Returns pointer of mutable data to first pixel.
Definition: mut_image_view.h:220
str
Definition: event_service.py:547
void generate(TUVOperation const &uv_op) const
For each pixel in this with coordinates (u,v), populates with the user provided function,...
Definition: mut_image_view.h:153
Layout of the image: width, height and pitch in bytes.
Definition: layout.h:23
Image MutImage, owning images types.
Definition: num_diff.h:20
auto ptr() const -> TPixel const *
Returns pointer to first pixel.
Definition: image_view.h:140
A view of an (immutable) image, which does not own the data.
Definition: image_view.h:55
auto rowInBounds(int v) const -> bool
Returns true if v is in [0, height).
Definition: image_view.h:104
auto width() const -> int
Definition: layout.h:54
auto layout() const -> ImageLayout const &
Returns ImageLayout. It is {{0,0}, 0} is view is empty.
Definition: image_view.h:86
auto imageSize() const -> sophus::ImageSize const &
Returns ImageSize. It is {0,0} if view is empty.
Definition: image_view.h:80
void transformFrom(ImageView< TLhsPixel > lhs, ImageView< TRhsPixel > rhs, TBinaryOperation const &binary_op) const
Transforms two views using binary operation and assigns result to this.
Definition: mut_image_view.h:193
auto view() const -> ImageView< TPixel >
Returns ImageView(*this).
Definition: mut_image_view.h:87
static auto unsafeConstCast(ImageView< TPixel > view) -> MutImageView
Creates mutable view from view.
Definition: mut_image_view.h:79
MutImageView(ImageLayout layout, TPixel *ptr) noexcept
Creates view from layout and pointer to first pixel.
Definition: mut_image_view.h:67
auto colInBounds(int u) const -> bool
Returns true if u is in [0, width).
Definition: image_view.h:99
#define SOPHUS_ASSERT_EQ(...)
Definition: common.h:41
MutImageView(sophus::ImageSize image_size, TPixel *ptr) noexcept
Creates view from image size and pointer to first pixel. The image is assumed to be contiguous and th...
Definition: mut_image_view.h:72
#define SOPHUS_ASSERT_LE(...)
Definition: common.h:44
void copyDataFrom(ImageView< TPixel > view) const
Copies data from view into this.
Definition: mut_image_view.h:98
auto pitchBytes() const -> size_t
Definition: image_view.h:91
auto mut(int u, int v) const -> TPixel &
Mutable accessor to pixel u, v.
Definition: mut_image_view.h:123
ImageLayout layout_
Definition: image_view.h:241
auto rowPtr(int v) const -> TPixel const *
Returns v-th row pointer.
Definition: image_view.h:111
View of a mutable image, which does not own the data.
Definition: mut_image_view.h:61
auto mutSubview(Eigen::Vector2i uv, sophus::ImageSize size) const -> MutImageView
Returns mutable subview.
Definition: mut_image_view.h:225
MutImageView()=default
Default constructor creates an empty image.
Image size, hence its width and height.
Definition: image_size.h:21
void fill(TPixel const &val) const
Populates every pixel of this with val.
Definition: mut_image_view.h:215
void mutate(TUnaryOperation const &unary_op) const
Mutates each pixel of this with given unary operation.
Definition: mut_image_view.h:135