image icon indicating copy to clipboard operation
image copied to clipboard

Feature: methods for getting a pixel using signed coordinates

Open rostyq opened this issue 2 years ago • 2 comments

This PR adds two methods, each with default implementation to GenericImageView trait: checked_get_pixel and saturating_get_pixel. Both allow to get a pixel from an image view using signed coordinates. That can be convenient for different computer vision algorithms like object detection or tracking.

I license past and future contributions under the dual MIT/Apache-2.0 license, allowing licensees to choose either at their option.

rostyq avatar Feb 01 '23 16:02 rostyq

This could be simplified using the max() and min() methods. For instance, x.max(0).min(width - 1) as u32

Also worth double checking that zero-sized images are either prohibited by GenericImage or properly handled by this patch

fintelia avatar Feb 01 '23 17:02 fintelia

When designing image types (e.g. https://github.com/strasdat/Sophus/blob/23.04-beta/cpp/sophus/image/image_view.h#L125), I came to the same conclusion that signed integer pixel coordinates are beneficial. For instance, it is quite useful/common to ask whether a 3d point almost projects into a camera's field of view - hence talking about a pixel coordinate of e.g. (-5, -10) can indeed by meaningful.

strasdat avatar Feb 03 '23 21:02 strasdat