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)
62 typedef long long int64_t;
63 typedef unsigned short uint16_t;
71 template <
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;
322 friend std::ostream &operator<< <>(std::ostream &s,
const vpImage<Type> &I);
329 void performLut(
const Type(&lut)[256],
unsigned int nbThreads = 1);
335 void resize(
unsigned int h,
unsigned int w);
337 void resize(
unsigned int h,
unsigned int w,
const Type &val);
349 swap(first.npixels, second.npixels);
350 swap(first.width, second.width);
351 swap(first.height, second.height);
352 swap(first.row, second.row);
358 unsigned int npixels;
365 #include <visp3/core/vpImage_operators.h>
366 #include <visp3/core/vpImage_lut.h>
367 #include <visp3/core/vpImage_getters.h>
375 std::fill(bitmap, bitmap + npixels, value);
383 if (h != this->height) {
384 if (row !=
nullptr) {
390 if ((h != this->height) || (w != this->width)) {
391 if (bitmap !=
nullptr) {
402 npixels = width * height;
404 if (bitmap ==
nullptr) {
405 bitmap =
new Type[npixels];
408 if (bitmap ==
nullptr) {
411 if (row ==
nullptr) {
412 row =
new Type *[height];
414 if (row ==
nullptr) {
418 for (
unsigned int i = 0; i < height; ++i) {
419 row[i] = bitmap + (i * width);
426 template <
class Type>
void vpImage<Type>::init(Type *
const array,
unsigned int h,
unsigned int w,
bool copyData)
428 if (h != this->height) {
429 if (row !=
nullptr) {
436 if ((copyData && ((h != this->height) || (w != this->width))) || (!copyData)) {
437 if (bitmap !=
nullptr) {
445 hasOwnership = copyData;
449 npixels = width * height;
452 if (bitmap ==
nullptr) {
453 bitmap =
new Type[npixels];
456 if (bitmap ==
nullptr) {
461 memcpy(
static_cast<void *
>(bitmap),
static_cast<void *
>(array),
static_cast<size_t>(npixels *
sizeof(Type)));
468 if (row ==
nullptr) {
469 row =
new Type *[height];
471 if (row ==
nullptr) {
475 for (
unsigned int i = 0; i < height; ++i) {
476 row[i] = bitmap + (i * width);
483 template <
class Type>
485 : bitmap(nullptr), display(nullptr), npixels(0), width(0), height(0), row(nullptr), hasOwnership(true)
494 template <
class Type>
496 : bitmap(nullptr), display(nullptr), npixels(0), width(0), height(0), row(nullptr), hasOwnership(true)
504 template <
class Type>
506 : bitmap(nullptr), display(nullptr), npixels(0), width(0), height(0), row(nullptr), hasOwnership(true)
508 init(array, h, w, copyData);
514 template <
class Type>
515 vpImage<Type>::vpImage() : bitmap(nullptr), display(nullptr), npixels(0), width(0), height(0), row(nullptr), hasOwnership(true)
569 if (bitmap !=
nullptr) {
576 if (row !=
nullptr) {
593 template <
class Type>
595 : bitmap(nullptr), display(nullptr), npixels(0), width(0), height(0), row(nullptr), hasOwnership(true)
599 memcpy(
static_cast<void *
>(
bitmap),
static_cast<void *
>(I.
bitmap), I.npixels *
sizeof(Type));
603 #if ((__cplusplus >= 201103L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L)))
607 template <class Type>
609 : bitmap(I.bitmap), display(I.display), npixels(I.npixels), width(I.width), height(I.height), row(I.row),
610 hasOwnership(I.hasOwnership)
618 I.hasOwnership =
false;
635 int itl =
static_cast<int>(topLeft.
get_i());
636 int jtl =
static_cast<int>(topLeft.
get_j());
642 int dest_w =
static_cast<int>(this->getWidth());
643 int dest_h =
static_cast<int>(this->getHeight());
644 int src_w =
static_cast<int>(src.
getWidth());
645 int src_h =
static_cast<int>(src.
getHeight());
646 int wsize =
static_cast<int>(src.
getWidth());
647 int hsize =
static_cast<int>(src.
getHeight());
649 if ((itl >= dest_h) || (jtl >= dest_w)) {
667 if ((src_w - src_jbegin) >(dest_w - dest_jbegin)) {
668 wsize = dest_w - dest_jbegin;
671 wsize = src_w - src_jbegin;
674 if ((src_h - src_ibegin) > (dest_h - dest_ibegin)) {
675 hsize = dest_h - dest_ibegin;
678 hsize = src_h - src_ibegin;
681 for (
int i = 0; i < hsize; ++i) {
682 Type *srcBitmap = src.
bitmap + (((src_ibegin + i) * src_w) + src_jbegin);
683 Type *destBitmap = this->bitmap + (((dest_ibegin + i) * dest_w) + dest_jbegin);
685 memcpy(
static_cast<void *
>(destBitmap),
static_cast<void *
>(srcBitmap),
static_cast<size_t>(wsize) *
sizeof(Type));
721 unsigned int h = height / 2;
722 unsigned int w = width / 2;
724 for (
unsigned int i = 0; i < h; ++i) {
725 for (
unsigned int j = 0; j < w; ++j) {
726 res[i][j] = (*this)[i << 1][j << 1];
748 template <
class Type>
751 if ((v_scale == 1) && (h_scale == 1)) {
755 unsigned int h = height / v_scale;
756 unsigned int w = width / h_scale;
758 for (
unsigned int i = 0; i < h; ++i) {
759 for (
unsigned int j = 0; j < w; ++j) {
760 sampled[i][j] = (*this)[i * v_scale][j * h_scale];
789 unsigned int h = height / 4;
790 unsigned int w = width / 4;
791 const unsigned int magic_2 = 2;
793 for (
unsigned int i = 0; i < h; ++i) {
794 for (
unsigned int j = 0; j < w; ++j) {
795 res[i][j] = (*this)[i << magic_2][j << magic_2];
833 const unsigned int magic_2 = 2;
834 unsigned int h = height * magic_2;
835 unsigned int w = width * magic_2;
839 for (
unsigned int i = 0; i < h; ++i) {
840 for (
unsigned int j = 0; j < w; ++j) {
841 res[i][j] = (*this)[i >> 1][j >> 1];
854 for (
unsigned int i = 0; i < h; i += magic_2) {
855 for (
unsigned int j = 1; j < (w - 1); j += magic_2) {
856 res[i][j] =
static_cast<Type
>(0.5 * ((*this)[i >> 1][j >> 1] + (*this)[i >> 1][(j >> 1) + 1]));
861 for (
unsigned int i = 1; i < (h - 1); i += magic_2) {
862 for (
unsigned int j = 0; j < w; j += magic_2) {
863 res[i][j] =
static_cast<Type
>(0.5 * ((*this)[i >> 1][j >> 1] + (*this)[(i >> 1) + 1][j >> 1]));
868 for (
unsigned int i = 1; i < (h - 1); i += magic_2) {
869 for (
unsigned int j = 1; j < (w - 1); j += magic_2) {
870 res[i][j] =
static_cast<Type
>(0.25 * ((*this)[i >> 1][j >> 1] + (*this)[i >> 1][(j >> 1) + 1] +
871 (*
this)[(i >> 1) + 1][j >> 1] + (*
this)[(i >> 1) + 1][(j >> 1) + 1]));
913 if ((this->getHeight() != C.
getHeight()) || (this->getWidth() != C.
getWidth())) {
914 C.
resize(this->getHeight(), this->getWidth());
918 std::cout << me << std::endl;
922 if ((this->getWidth() != B.
getWidth()) || (this->getHeight() != B.
getHeight())) {
926 unsigned int this_width = this->getWidth();
927 unsigned int this_height = this->getHeight();
928 for (
unsigned int i = 0; i < (this_width * this_height); ++i) {
953 std::cout << me << std::endl;
961 unsigned int a_width = A.
getWidth();
963 for (
unsigned int i = 0; i < (a_width * a_height); ++i) {
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
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
vpImage< Type > & operator=(vpImage< Type > other)
Copy operator.
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.
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.
Type * operator[](unsigned int i)
operator[] allows operation like I[i] = x.
void resize(unsigned int h, unsigned int w, const Type &val)
resize the image : Image initialization
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)
vpImage(unsigned int height, unsigned int width, Type value)
constructor set the size of the image and init all the pixel
void performLut(const Type(&lut)[256], unsigned int nbThreads=1)
friend std::ostream & operator<<(std::ostream &s, const vpImage< Type > &I)
const Type * operator[](int i) const
bool operator==(const vpImage< Type > &I) const
void insert(const vpImage< Type > &src, const vpImagePoint &topLeft)
void sub(const vpImage< Type > &A, const vpImage< Type > &B, vpImage< Type > &C) const
Type getValue(unsigned int i, unsigned int j) const
vpImage< Type > operator-(const vpImage< Type > &B) const
void init(unsigned int height, unsigned int width, Type value)
Set the size of the image and initialize all the elements to 'value'.
unsigned int getSize() const
vpImage(const vpImage< Type > &img)
copy constructor
friend void swap(vpImage< Type > &first, vpImage< Type > &second)
unsigned int getCols() const
Type * bitmap
points toward the bitmap
const Type * operator[](unsigned int i) const
operator[] allows operation like x = I[i]
double getStdev(const vpImage< bool > *p_mask=nullptr, unsigned int *nbValidPoints=nullptr) const
Return the standard deviation of the bitmap.
void sub(const vpImage< Type > &B, vpImage< Type > &C) const
vpImage(Type *const array, unsigned int height, unsigned int width, bool copyData=false)
constructor from an image stored as a continuous array in memory
void init(Type *const array, unsigned int height, unsigned int width, bool copyData=false)
Initialization from an image stored as a continuous array in memory.
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.
void init(unsigned int h, unsigned int w, Type value)
vpImage(unsigned int height, unsigned int width)
constructor set the size of the image
void operator()(unsigned int i, unsigned int j, const Type &v)