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;
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);
333 void performLut(
const Type(&lut)[256],
unsigned int nbThreads = 1);
339 void resize(
unsigned int h,
unsigned int w);
341 void resize(
unsigned int h,
unsigned int w,
const Type &val);
353 swap(first.npixels, second.npixels);
354 swap(first.width, second.width);
355 swap(first.height, second.height);
356 swap(first.row, second.row);
362 unsigned int npixels;
369 #include <visp3/core/vpImage_operators.h>
370 #include <visp3/core/vpImage_lut.h>
371 #include <visp3/core/vpImage_getters.h>
379 std::fill(bitmap, bitmap + npixels, value);
387 if (h != this->height) {
388 if (row !=
nullptr) {
394 if ((h != this->height) || (w != this->width)) {
395 if (bitmap !=
nullptr) {
406 npixels = width * height;
408 if (bitmap ==
nullptr) {
409 bitmap =
new Type[npixels];
412 if (bitmap ==
nullptr) {
415 if (row ==
nullptr) {
416 row =
new Type *[height];
418 if (row ==
nullptr) {
422 for (
unsigned int i = 0; i < height; ++i) {
423 row[i] = bitmap + (i * width);
430 template <
class Type>
void vpImage<Type>::init(Type *
const array,
unsigned int h,
unsigned int w,
bool copyData)
432 if (h != this->height) {
433 if (row !=
nullptr) {
440 if ((copyData && ((h != this->height) || (w != this->width))) || (!copyData)) {
441 if (bitmap !=
nullptr) {
449 hasOwnership = copyData;
453 npixels = width * height;
456 if (bitmap ==
nullptr) {
457 bitmap =
new Type[npixels];
460 if (bitmap ==
nullptr) {
465 memcpy(
static_cast<void *
>(bitmap),
static_cast<void *
>(array),
static_cast<size_t>(npixels *
sizeof(Type)));
472 if (row ==
nullptr) {
473 row =
new Type *[height];
475 if (row ==
nullptr) {
479 for (
unsigned int i = 0; i < height; ++i) {
480 row[i] = bitmap + (i * width);
487 template <
class Type>
489 : bitmap(nullptr), display(nullptr), npixels(0), width(0), height(0), row(nullptr), hasOwnership(true)
498 template <
class Type>
500 : bitmap(nullptr), display(nullptr), npixels(0), width(0), height(0), row(nullptr), hasOwnership(true)
508 template <
class Type>
510 : bitmap(nullptr), display(nullptr), npixels(0), width(0), height(0), row(nullptr), hasOwnership(true)
512 init(array, h, w, copyData);
518 template <
class Type>
519 vpImage<Type>::vpImage() : bitmap(nullptr), display(nullptr), npixels(0), width(0), height(0), row(nullptr), hasOwnership(true)
573 if (bitmap !=
nullptr) {
580 if (row !=
nullptr) {
597 template <
class Type>
599 : bitmap(nullptr), display(nullptr), npixels(0), width(0), height(0), row(nullptr), hasOwnership(true)
603 memcpy(
static_cast<void *
>(
bitmap),
static_cast<void *
>(I.
bitmap), I.npixels *
sizeof(Type));
607 #if ((__cplusplus >= 201103L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L)))
611 template <class Type>
613 : bitmap(I.bitmap), display(I.display), npixels(I.npixels), width(I.width), height(I.height), row(I.row),
614 hasOwnership(I.hasOwnership)
622 I.hasOwnership =
false;
639 int itl =
static_cast<int>(topLeft.
get_i());
640 int jtl =
static_cast<int>(topLeft.
get_j());
646 int dest_w =
static_cast<int>(this->getWidth());
647 int dest_h =
static_cast<int>(this->getHeight());
648 int src_w =
static_cast<int>(src.
getWidth());
649 int src_h =
static_cast<int>(src.
getHeight());
650 int wsize =
static_cast<int>(src.
getWidth());
651 int hsize =
static_cast<int>(src.
getHeight());
653 if ((itl >= dest_h) || (jtl >= dest_w)) {
671 if ((src_w - src_jbegin) >(dest_w - dest_jbegin)) {
672 wsize = dest_w - dest_jbegin;
675 wsize = src_w - src_jbegin;
678 if ((src_h - src_ibegin) > (dest_h - dest_ibegin)) {
679 hsize = dest_h - dest_ibegin;
682 hsize = src_h - src_ibegin;
685 for (
int i = 0; i < hsize; ++i) {
686 Type *srcBitmap = src.
bitmap + (((src_ibegin + i) * src_w) + src_jbegin);
687 Type *destBitmap = this->bitmap + (((dest_ibegin + i) * dest_w) + dest_jbegin);
689 memcpy(
static_cast<void *
>(destBitmap),
static_cast<void *
>(srcBitmap),
static_cast<size_t>(wsize) *
sizeof(Type));
725 unsigned int h = height / 2;
726 unsigned int w = width / 2;
728 for (
unsigned int i = 0; i < h; ++i) {
729 for (
unsigned int j = 0; j < w; ++j) {
730 res[i][j] = (*this)[i << 1][j << 1];
752 template <
class Type>
755 if ((v_scale == 1) && (h_scale == 1)) {
759 unsigned int h = height / v_scale;
760 unsigned int w = width / h_scale;
762 for (
unsigned int i = 0; i < h; ++i) {
763 for (
unsigned int j = 0; j < w; ++j) {
764 sampled[i][j] = (*this)[i * v_scale][j * h_scale];
793 unsigned int h = height / 4;
794 unsigned int w = width / 4;
795 const unsigned int magic_2 = 2;
797 for (
unsigned int i = 0; i < h; ++i) {
798 for (
unsigned int j = 0; j < w; ++j) {
799 res[i][j] = (*this)[i << magic_2][j << magic_2];
837 const unsigned int magic_2 = 2;
838 unsigned int h = height * magic_2;
839 unsigned int w = width * magic_2;
843 for (
unsigned int i = 0; i < h; ++i) {
844 for (
unsigned int j = 0; j < w; ++j) {
845 res[i][j] = (*this)[i >> 1][j >> 1];
858 for (
unsigned int i = 0; i < h; i += magic_2) {
859 for (
unsigned int j = 1; j < (w - 1); j += magic_2) {
860 res[i][j] =
static_cast<Type
>(0.5 * ((*this)[i >> 1][j >> 1] + (*this)[i >> 1][(j >> 1) + 1]));
865 for (
unsigned int i = 1; i < (h - 1); i += magic_2) {
866 for (
unsigned int j = 0; j < w; j += magic_2) {
867 res[i][j] =
static_cast<Type
>(0.5 * ((*this)[i >> 1][j >> 1] + (*this)[(i >> 1) + 1][j >> 1]));
872 for (
unsigned int i = 1; i < (h - 1); i += magic_2) {
873 for (
unsigned int j = 1; j < (w - 1); j += magic_2) {
874 res[i][j] =
static_cast<Type
>(0.25 * ((*this)[i >> 1][j >> 1] + (*this)[i >> 1][(j >> 1) + 1] +
875 (*
this)[(i >> 1) + 1][j >> 1] + (*
this)[(i >> 1) + 1][(j >> 1) + 1]));
917 if ((this->getHeight() != C.
getHeight()) || (this->getWidth() != C.
getWidth())) {
918 C.
resize(this->getHeight(), this->getWidth());
922 std::cout << me << std::endl;
926 if ((this->getWidth() != B.
getWidth()) || (this->getHeight() != B.
getHeight())) {
930 unsigned int this_width = this->getWidth();
931 unsigned int this_height = this->getHeight();
932 for (
unsigned int i = 0; i < (this_width * this_height); ++i) {
957 std::cout << me << std::endl;
965 unsigned int a_width = A.
getWidth();
967 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
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.
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)