42#include <visp3/core/vpConfig.h>
43#include <visp3/core/vpEndian.h>
44#include <visp3/core/vpException.h>
45#include <visp3/core/vpImageException.h>
46#include <visp3/core/vpImagePoint.h>
47#include <visp3/core/vpRGBa.h>
48#include <visp3/core/vpRGBf.h>
50#if defined(VISP_HAVE_THREADS)
61#if defined(_MSC_VER) && (_MSC_VER < 1700)
62typedef long long int64_t;
63typedef unsigned short uint16_t;
71template <
class Type>
class vpImage;
142#if ((__cplusplus >= 201103L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L)))
144 vpImage(vpImage<Type> &&img);
147 vpImage(
unsigned int height,
unsigned int width);
149 vpImage(
unsigned int height,
unsigned int width, Type value);
151 vpImage(Type *
const array,
unsigned int height,
unsigned int width,
bool copyData =
false);
171 inline unsigned int getCols()
const {
return width; }
181 inline unsigned int getHeight()
const {
return height; }
191 void getMinMaxValue(Type &min, Type &max,
bool onlyFiniteVal =
true)
const;
212 inline unsigned int getRows()
const {
return height; }
221 inline unsigned int getSize()
const {
return width * height; }
224 double getStdev(
const double &mean,
const vpImage<bool> *p_mask =
nullptr,
unsigned int *nbValidPoints =
nullptr)
const;
226 double getSum(
const vpImage<bool> *p_mask =
nullptr,
unsigned int *nbValidPoints =
nullptr)
const;
229 Type
getValue(
unsigned int i,
unsigned int j)
const;
231 Type
getValue(
double i,
double j)
const;
242 inline unsigned int getWidth()
const {
return width; }
248 void init(
unsigned int height,
unsigned int width);
250 void init(
unsigned int height,
unsigned int width, Type value);
252 void init(Type *
const array,
unsigned int height,
unsigned int width,
bool copyData =
false);
263 inline const Type *
operator[](
unsigned int i)
const {
return row[i]; }
264 inline const Type *
operator[](
int i)
const {
return row[i]; }
272 inline Type
operator()(
unsigned int i,
unsigned int j)
const {
return bitmap[(i * width) + j]; }
278 inline void operator()(
unsigned int i,
unsigned int j,
const Type &v) {
bitmap[(i * width) + j] = v; }
292 unsigned int i =
static_cast<unsigned int>(ip.
get_i());
293 unsigned int j =
static_cast<unsigned int>(ip.
get_j());
295 return bitmap[(i * width) + j];
308 unsigned int i =
static_cast<unsigned int>(ip.
get_i());
309 unsigned int j =
static_cast<unsigned int>(ip.
get_j());
311 bitmap[(i * width) + j] = v;
318#if ((__cplusplus >= 201103L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L)))
320 vpImage<Type> &operator=(vpImage<Type> &&other);
326 friend std::ostream &operator<< <>(std::ostream &s,
const vpImage<Type> &I);
335 void performLut(
const Type(&lut)[256],
unsigned int nbThreads = 1);
341 void resize(
unsigned int h,
unsigned int w);
343 void resize(
unsigned int h,
unsigned int w,
const Type &val);
355 swap(first.npixels, second.npixels);
356 swap(first.width, second.width);
357 swap(first.height, second.height);
358 swap(first.row, second.row);
364 unsigned int npixels;
371#include <visp3/core/vpImage_operators.h>
372#include <visp3/core/vpImage_lut.h>
373#include <visp3/core/vpImage_getters.h>
389 if (h != this->height) {
390 if (row !=
nullptr) {
396 if ((h != this->height) || (w != this->width)) {
408 npixels = width * height;
411 bitmap =
new Type[npixels];
417 if (row ==
nullptr) {
418 row =
new Type *[height];
420 if (row ==
nullptr) {
424 for (
unsigned int i = 0; i < height; ++i) {
425 row[i] =
bitmap + (i * width);
432template <
class Type>
void vpImage<Type>::init(Type *
const array,
unsigned int h,
unsigned int w,
bool copyData)
434 if (h != this->height) {
435 if (row !=
nullptr) {
442 if ((copyData && ((h != this->height) || (w != this->width))) || (!copyData)) {
451 hasOwnership = copyData;
455 npixels = width * height;
459 bitmap =
new Type[npixels];
467 memcpy(
static_cast<void *
>(
bitmap),
static_cast<void *
>(array),
static_cast<size_t>(npixels *
sizeof(Type)));
474 if (row ==
nullptr) {
475 row =
new Type *[height];
477 if (row ==
nullptr) {
481 for (
unsigned int i = 0; i < height; ++i) {
482 row[i] =
bitmap + (i * width);
491 :
bitmap(nullptr),
display(nullptr), npixels(0), width(0), height(0), row(nullptr), hasOwnership(true)
502 :
bitmap(nullptr),
display(nullptr), npixels(0), width(0), height(0), row(nullptr), hasOwnership(true)
512 :
bitmap(nullptr),
display(nullptr), npixels(0), width(0), height(0), row(nullptr), hasOwnership(true)
514 init(array, h, w, copyData);
582 if (row !=
nullptr) {
601 :
bitmap(nullptr),
display(nullptr), npixels(0), width(0), height(0), row(nullptr), hasOwnership(true)
603 resize(I.getHeight(), I.getWidth());
605 memcpy(
static_cast<void *
>(
bitmap),
static_cast<void *
>(I.bitmap), I.npixels *
sizeof(Type));
609#if ((__cplusplus >= 201103L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L)))
616 hasOwnership(I.hasOwnership)
624 I.hasOwnership =
false;
641 int itl =
static_cast<int>(topLeft.
get_i());
642 int jtl =
static_cast<int>(topLeft.
get_j());
648 int dest_w =
static_cast<int>(this->
getWidth());
649 int dest_h =
static_cast<int>(this->
getHeight());
650 int src_w =
static_cast<int>(src.
getWidth());
651 int src_h =
static_cast<int>(src.
getHeight());
652 int wsize =
static_cast<int>(src.
getWidth());
653 int hsize =
static_cast<int>(src.
getHeight());
655 if ((itl >= dest_h) || (jtl >= dest_w)) {
673 if ((src_w - src_jbegin) >(dest_w - dest_jbegin)) {
674 wsize = dest_w - dest_jbegin;
677 wsize = src_w - src_jbegin;
680 if ((src_h - src_ibegin) > (dest_h - dest_ibegin)) {
681 hsize = dest_h - dest_ibegin;
684 hsize = src_h - src_ibegin;
687 for (
int i = 0; i < hsize; ++i) {
688 Type *srcBitmap = src.
bitmap + (((src_ibegin + i) * src_w) + src_jbegin);
689 Type *destBitmap = this->bitmap + (((dest_ibegin + i) * dest_w) + dest_jbegin);
691 memcpy(
static_cast<void *
>(destBitmap),
static_cast<void *
>(srcBitmap),
static_cast<size_t>(wsize) *
sizeof(Type));
727 unsigned int h = height / 2;
728 unsigned int w = width / 2;
730 for (
unsigned int i = 0; i < h; ++i) {
731 for (
unsigned int j = 0; j < w; ++j) {
732 res[i][j] = (*this)[i << 1][j << 1];
757 if ((v_scale == 1) && (h_scale == 1)) {
761 unsigned int h = height / v_scale;
762 unsigned int w = width / h_scale;
764 for (
unsigned int i = 0; i < h; ++i) {
765 for (
unsigned int j = 0; j < w; ++j) {
766 sampled[i][j] = (*this)[i * v_scale][j * h_scale];
795 unsigned int h = height / 4;
796 unsigned int w = width / 4;
797 const unsigned int magic_2 = 2;
799 for (
unsigned int i = 0; i < h; ++i) {
800 for (
unsigned int j = 0; j < w; ++j) {
801 res[i][j] = (*this)[i << magic_2][j << magic_2];
839 const unsigned int magic_2 = 2;
840 unsigned int h = height * magic_2;
841 unsigned int w = width * magic_2;
845 for (
unsigned int i = 0; i < h; ++i) {
846 for (
unsigned int j = 0; j < w; ++j) {
847 res[i][j] = (*this)[i >> 1][j >> 1];
860 for (
unsigned int i = 0; i < h; i += magic_2) {
861 for (
unsigned int j = 1; j < (w - 1); j += magic_2) {
862 res[i][j] =
static_cast<Type
>(0.5 * ((*this)[i >> 1][j >> 1] + (*this)[i >> 1][(j >> 1) + 1]));
867 for (
unsigned int i = 1; i < (h - 1); i += magic_2) {
868 for (
unsigned int j = 0; j < w; j += magic_2) {
869 res[i][j] =
static_cast<Type
>(0.5 * ((*this)[i >> 1][j >> 1] + (*this)[(i >> 1) + 1][j >> 1]));
874 for (
unsigned int i = 1; i < (h - 1); i += magic_2) {
875 for (
unsigned int j = 1; j < (w - 1); j += magic_2) {
876 res[i][j] =
static_cast<Type
>(0.25 * ((*this)[i >> 1][j >> 1] + (*this)[i >> 1][(j >> 1) + 1] +
877 (*this)[(i >> 1) + 1][j >> 1] + (*this)[(i >> 1) + 1][(j >> 1) + 1]));
924 std::cout << me << std::endl;
932 unsigned int this_width = this->
getWidth();
933 unsigned int this_height = this->
getHeight();
934 for (
unsigned int i = 0; i < (this_width * this_height); ++i) {
959 std::cout << me << std::endl;
967 unsigned int a_width = A.
getWidth();
969 for (
unsigned int i = 0; i < (a_width * a_height); ++i) {
Class that defines generic functionalities for display.
error that can be emitted by ViSP classes.
@ memoryAllocationError
Memory allocation error.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition of the vpImage class member functions.
Type operator()(const vpImagePoint &ip) const
void destroy()
Destructor : Memory de-allocation.
void subsample(unsigned int v_scale, unsigned int h_scale, vpImage< Type > &sampled) const
void halfSizeImage(vpImage< Type > &res) const
double getSum(const vpImage< bool > *p_mask=nullptr, unsigned int *nbValidPoints=nullptr) const
Compute the sum of image intensities.
Type getMinValue(bool onlyFiniteVal=true) const
Return the minimum value within the bitmap.
vpImage< Type > & operator=(const vpImage< Type > &other)
Copy operator.
const Type * operator[](int i) const
void quarterSizeImage(vpImage< Type > &res) const
void getMinMaxLoc(vpImagePoint *minLoc, vpImagePoint *maxLoc, Type *minVal=nullptr, Type *maxVal=nullptr) const
Get the position of the minimum and/or the maximum pixel value within the bitmap and the correspondin...
void init(unsigned int height, unsigned int width)
Set the size of the image.
unsigned int getWidth() const
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
unsigned int getNumberOfPixel() const
void doubleSizeImage(vpImage< Type > &res)
friend std::ostream & operator<<(std::ostream &s, const vpImage< Type > &I)
void performLut(const Type(&lut)[256], unsigned int nbThreads=1)
bool operator==(const vpImage< Type > &I) const
void insert(const vpImage< Type > &src, const vpImagePoint &topLeft)
Type getValue(unsigned int i, unsigned int j) const
Type * operator[](unsigned int i)
operator[] allows operation like I[i] = x.
vpImage< Type > operator-(const vpImage< Type > &B) const
unsigned int getSize() const
friend void swap(vpImage< Type > &first, vpImage< Type > &second)
unsigned int getCols() const
Type * bitmap
points toward the bitmap
double getStdev(const vpImage< bool > *p_mask=nullptr, unsigned int *nbValidPoints=nullptr) const
Return the standard deviation of the bitmap.
const Type * operator[](unsigned int i) const
operator[] allows operation like x = I[i]
void sub(const vpImage< Type > &B, vpImage< Type > &C) const
Type getMaxValue(bool onlyFiniteVal=true) const
Return the maximum value within the bitmap.
virtual ~vpImage()
destructor
unsigned int getHeight() const
unsigned int getRows() const
void getMinMaxValue(Type &min, Type &max, bool onlyFiniteVal=true) const
Look for the minimum and the maximum value within the bitmap.
void operator()(const vpImagePoint &ip, const Type &v)
Type operator()(unsigned int i, unsigned int j) const
bool operator!=(const vpImage< Type > &I) const
double getMeanValue(const vpImage< bool > *p_mask=nullptr, unsigned int *nbValidPoints=nullptr) const
Return the mean value of the bitmap.
friend class vpImageConvert
void operator()(unsigned int i, unsigned int j, const Type &v)