Xmipp  v3.23.11-Nereus
Public Member Functions | Public Attributes | Protected Attributes | Friends | List of all members
ImageGeneric Class Reference

#include <xmipp_image_generic.h>

Collaboration diagram for ImageGeneric:
Collaboration graph
[legend]

Public Member Functions

 ImageGeneric ()
 
 ImageGeneric (DataType _datatype)
 
 ImageGeneric (const FileName &filename)
 
 ImageGeneric (const ImageGeneric &img)
 
 ~ImageGeneric ()
 
void init ()
 
void clear ()
 
void copy (const ImageGeneric &img)
 
void clearHeader ()
 
void initGeometry (const size_t n=0)
 
MDRowgetGeometry (const size_t n=0)
 
void getDimensions (size_t &Xdim, size_t &Ydim, size_t &Zdim, size_t &Ndim) const
 
void getDimensions (size_t &Xdim, size_t &Ydim, size_t &Zdim) const
 
void getDimensions (ArrayDim &aDim) const
 
size_t getSize () const
 
void getEulerAngles (double &rot, double &tilt, double &psi, size_t n=0)
 
double tilt (const size_t n=0) const
 
void resize (int Xdim, int Ydim, int Zdim, size_t Ndim, bool copy=true)
 
void setDatatype (DataType _datatype)
 
void setDatatype (const FileName &name, ImageInfo &imgInf)
 
void setDatatype (const FileName &name)
 
void setDataMode (DataMode mode)
 
DataType getDatatype () const
 
void getInfo (ImageInfo &imgInfo) const
 
int getDatatypeDepth () const
 
bool isMapped ()
 
int read (const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false)
 
int readApplyGeo (const FileName &name, const MDRow &row, const ApplyGeoParams &params=DefaultApplyGeoParams)
 
int readApplyGeo (const FileName &name, const MetaData &md, size_t objId, const ApplyGeoParams &params=DefaultApplyGeoParams)
 
int readApplyGeo (const MetaData &md, size_t objId, const ApplyGeoParams &params=DefaultApplyGeoParams)
 
void applyGeo (const MetaData &md, size_t objId, const ApplyGeoParams &params=DefaultApplyGeoParams)
 
void mirrorY (void)
 
int readMapped (const FileName &name, size_t select_img=ALL_IMAGES, int mode=WRITE_READONLY)
 
int readOrReadMapped (const FileName &name, size_t select_img=ALL_IMAGES, int mode=WRITE_READONLY)
 
int readPreview (const FileName &name, size_t Xdim, size_t Ydim=0, int select_slice=CENTRAL_SLICE, size_t select_img=FIRST_IMAGE)
 
int readOrReadPreview (const FileName &name, size_t Xdim, size_t Ydim=0, int select_slice=CENTRAL_SLICE, size_t select_img=FIRST_IMAGE, bool mapData=false, bool wrap=true)
 
void getPreview (ImageGeneric &imgOut, int Xdim, int Ydim=-1, int select_slice=CENTRAL_SLICE, size_t select_img=FIRST_IMAGE)
 
int readPreviewFourier (const FileName &name, size_t Xdim, size_t Ydim=0, int select_slice=CENTRAL_SLICE, size_t select_img=FIRST_IMAGE)
 
int readPreviewSmooth (const FileName &name, size_t Xdim, size_t Ydim=0, int select_slice=CENTRAL_SLICE, size_t select_img=FIRST_IMAGE)
 
void write (const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
 
void mapFile2Write (int Xdim, int Ydim, int Zdim, const FileName &_filename, bool createTempFile=false, size_t select_img=APPEND_IMAGE, bool isStack=false, int mode=WRITE_OVERWRITE, int _swapWrite=0)
 
void movePointerTo (int select_slice=ALL_SLICES, size_t select_img=ALL_IMAGES)
 
MultidimArrayGenericoperator() ()
 
const MultidimArrayGenericoperator() () const
 
ImageGenericoperator= (const ImageGeneric &img)
 
bool operator== (const ImageGeneric &i1) const
 
void convert2Datatype (DataType datatype, CastWriteMode castMode=CW_CONVERT)
 
void reslice (AxisView view)
 
void reslice (AxisView view, ImageGeneric &out)
 
bool equal (const ImageGeneric &i1, double accuracy=XMIPP_EQUAL_ACCURACY) const
 
double getPixel (unsigned long n, int k, int i, int j) const
 
double getPixel (int i, int j) const
 
void setPixel (unsigned long n, int k, int i, int j, double value) const
 
void setPixel (int i, int j, double value) const
 
void initConstant (double value) const
 
void initRandom (double op1, double op2, RandomMode mode=RND_UNIFORM) const
 
void print () const
 
void toString (String &s) const
 
void add (const ImageGeneric &img)
 
void subtract (const ImageGeneric &img)
 
void multiply (const double value)
 
void multiply (const ImageGeneric &img)
 
void divide (const ImageGeneric &img)
 
void divide (const double value)
 

Public Attributes

ImageBaseimage
 
DataType datatype
 
MultidimArrayGenericdata
 

Protected Attributes

bool swap
 

Friends

std::ostream & operator<< (std::ostream &o, const ImageGeneric &I)
 

Detailed Description

ImageGeneric class to handle images with independence of data type

Definition at line 47 of file xmipp_image_generic.h.

Constructor & Destructor Documentation

◆ ImageGeneric() [1/4]

ImageGeneric::ImageGeneric ( )
inline

Empty constructor.

No internal image class is declared.

Definition at line 65 of file xmipp_image_generic.h.

66  {
67  init();
68  }

◆ ImageGeneric() [2/4]

ImageGeneric::ImageGeneric ( DataType  _datatype)

Constructor passing the data type of the image.

Defines the data type of the image and then declares the internal image class.

Definition at line 41 of file xmipp_image_generic.cpp.

42 {
43  init();
44  setDatatype(_datatype);
45 }
void setDatatype(DataType _datatype)

◆ ImageGeneric() [3/4]

ImageGeneric::ImageGeneric ( const FileName filename)

Constructor for reading the image

This constructor will be useful for perfom construction and read in a single step.

Definition at line 47 of file xmipp_image_generic.cpp.

48 {
49  init();
50  read(filename);
51 }
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false)

◆ ImageGeneric() [4/4]

ImageGeneric::ImageGeneric ( const ImageGeneric img)

Copy Constructor

Definition at line 53 of file xmipp_image_generic.cpp.

54 {
55  init();
56  copy(img);
57 }
void copy(const ImageGeneric &img)

◆ ~ImageGeneric()

ImageGeneric::~ImageGeneric ( )

Destructor.

Definition at line 59 of file xmipp_image_generic.cpp.

60 {
61  delete image;
62  delete data;
63 }
ImageBase * image
MultidimArrayGeneric * data

Member Function Documentation

◆ add()

void ImageGeneric::add ( const ImageGeneric img)

Addition of the passed image to the internal's

Definition at line 543 of file xmipp_image_generic.cpp.

544 {
545  if (datatype != img.datatype)
546  REPORT_ERROR(ERR_TYPE_INCORRECT, "Images have different datatypes");
547 
548 #define ADD(type) MultidimArray<type> & kk = *((MultidimArray<type>*) data->im);\
549  MultidimArray<type> & pp = *((MultidimArray<type>*) img.data->im);\
550  kk += pp;
551 
553 #undef ADD
554 
555 }
#define ADD(type)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Incorrect type received.
Definition: xmipp_error.h:190
#define SWITCHDATATYPE(datatype, OP)

◆ applyGeo()

void ImageGeneric::applyGeo ( const MetaData md,
size_t  objId,
const ApplyGeoParams params = DefaultApplyGeoParams 
)

Apply geometry in referring metadata to the image

Definition at line 407 of file xmipp_image_generic.cpp.

409 {
410  image->applyGeo(md, objId, params);
411 }
void applyGeo(const MetaData &md, size_t objId, const ApplyGeoParams &params=DefaultApplyGeoParams)
ImageBase * image

◆ clear()

void ImageGeneric::clear ( )

Clear the parameters and initialize them.

Definition at line 72 of file xmipp_image_generic.cpp.

73 {
74  if (image != NULL)
75  {
76  image->clear();
77  delete image;
78  delete data;
79  init();
80  }
81 }
virtual void clear()=0
ImageBase * image
MultidimArrayGeneric * data

◆ clearHeader()

void ImageGeneric::clearHeader ( )
inline

Clear the image header

Definition at line 101 of file xmipp_image_generic.h.

102  {
103  image->clearHeader();
104  }
ImageBase * image

◆ convert2Datatype()

void ImageGeneric::convert2Datatype ( DataType  datatype,
CastWriteMode  castMode = CW_CONVERT 
)

Convert the datatype of the object and cast the image

Definition at line 414 of file xmipp_image_generic.cpp.

415 {
416  if (_datatype == datatype || _datatype == DT_Unknown)
417  return;
418 
419  ArrayDim aDim;
420  data->getDimensions(aDim);
421 
422  ImageBase * newImage;
423  MultidimArrayGeneric * newMAG;
424 
425 #define CONVERTTYPE(type) Image<type> *imT = new Image<type>; \
426  newImage = imT;\
427  newMAG = new MultidimArrayGeneric((MultidimArrayBase*) &(imT->data), _datatype);\
428  MultidimArray<type>* pMAG;\
429  newMAG->getMultidimArrayPointer(pMAG);\
430  if (castMode == CW_CAST)\
431  data->getImage(*pMAG);\
432  else\
433  {\
434  pMAG->resize(aDim);\
435  double min, max;\
436  data->computeDoubleMinMax(min, max);\
437  ((Image<double>*) image)->getCastConvertPageFromT(0, (char*)pMAG->data, _datatype, aDim.nzyxdim, min, max, castMode);\
438  }\
439 
440  SWITCHDATATYPE(_datatype, CONVERTTYPE)
441 
442 #undef CONVERTTYPE
443 
444  /* aDimFile must be set in order to movePointerTo can be used.
445  * If movePointerTo has been used before convert2Datatype, then
446  * only the pointed image/slice is converted, and the images/slices left
447  * are lost. This is why we set the new dimensions to the new ImageGeneric Object*/
448  newImage->setADimFile(aDim);
449 
450  clear();
451  datatype = _datatype;
452  image = newImage;
453  data = newMAG;
454 }
void setADimFile(ArrayDim aDim)
Image base class.
ImageBase * image
#define CONVERTTYPE(type)
void getDimensions(size_t &Xdim, size_t &Ydim, size_t &Zdim, size_t &Ndim) const
MultidimArrayGeneric * data
#define SWITCHDATATYPE(datatype, OP)

◆ copy()

void ImageGeneric::copy ( const ImageGeneric img)

Copy data from other ImageGeneric

Definition at line 83 of file xmipp_image_generic.cpp.

84 {
85  if (img.datatype != DT_Unknown)
86  {
87  setDatatype(img.datatype);
88 #define COPY(type) (*(Image<type>*)image) = (*(Image<type>*)img.image);
89 
91 #undef COPY
92 
93  }
94 
95 }
void setDatatype(DataType _datatype)
#define COPY(type)
#define SWITCHDATATYPE(datatype, OP)

◆ divide() [1/2]

void ImageGeneric::divide ( const ImageGeneric img)

Division of the internal image by another image

Definition at line 594 of file xmipp_image_generic.cpp.

595 {
596 
597 #define DIVIDEIMG(type) MultidimArray<type> & kk = *((MultidimArray<type>*) data->im);\
598  MultidimArray<type> & pp = *((MultidimArray<type>*) img.data->im);\
599  kk /= pp;
600 
602 #undef DIVIDEIMG
603 
604 }
#define DIVIDEIMG(type)
#define SWITCHDATATYPE(datatype, OP)

◆ divide() [2/2]

void ImageGeneric::divide ( const double  value)

Division if the internal image by a constant

Definition at line 606 of file xmipp_image_generic.cpp.

607 {
608 
609 #define DIVIDE(type) MultidimArray<type> & kk = *((MultidimArray<type>*) data->im);\
610  kk /= value;
611 
613 #undef DIVIDE
614 
615 }
#define DIVIDE(type)
#define SWITCHDATATYPE(datatype, OP)

◆ equal()

bool ImageGeneric::equal ( const ImageGeneric i1,
double  accuracy = XMIPP_EQUAL_ACCURACY 
) const
inline

equal for doubles

Definition at line 354 of file xmipp_image_generic.h.

355  {
356  return data->equal(MULTIDIM_ARRAY_GENERIC(i1),accuracy);
357  }
bool equal(const MultidimArrayGeneric &op, double accuracy=XMIPP_EQUAL_ACCURACY) const
#define MULTIDIM_ARRAY_GENERIC(v)
MultidimArrayGeneric * data

◆ getDatatype()

DataType ImageGeneric::getDatatype ( ) const
inline

Get the data type

Definition at line 170 of file xmipp_image_generic.h.

171  {
172  return datatype;
173  }

◆ getDatatypeDepth()

int ImageGeneric::getDatatypeDepth ( ) const
inline

Get the data type

Definition at line 181 of file xmipp_image_generic.h.

182  {
183  switch (datatype)
184  {
185  case DT_Float:
186  case DT_UInt:
187  return 32;
188  case DT_Int:
189  return 31;
190  case DT_Short:
191  return 15;
192  case DT_UShort:
193  case DT_HalfFloat:
194  return 16;
195  case DT_SChar:
196  return 7;
197  case DT_UHalfByte:
198  case DT_UChar:
199  return 8;
200  default:
201  REPORT_ERROR(ERR_TYPE_INCORRECT,"Do not know how to handle this type at this point");
202  }
203  }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Incorrect type received.
Definition: xmipp_error.h:190

◆ getDimensions() [1/3]

void ImageGeneric::getDimensions ( size_t &  Xdim,
size_t &  Ydim,
size_t &  Zdim,
size_t &  Ndim 
) const

Get Image dimensions

Definition at line 103 of file xmipp_image_generic.cpp.

104 {
105  image->getDimensions(xdim, ydim, Zdim, Ndim);
106 }
ImageBase * image
void getDimensions(size_t &Xdim, size_t &Ydim, size_t &Zdim, size_t &Ndim) const

◆ getDimensions() [2/3]

void ImageGeneric::getDimensions ( size_t &  Xdim,
size_t &  Ydim,
size_t &  Zdim 
) const

Definition at line 97 of file xmipp_image_generic.cpp.

98 {
99  size_t Ndim;
100  image->getDimensions(xdim, ydim, Zdim, Ndim);
101 }
ImageBase * image
void getDimensions(size_t &Xdim, size_t &Ydim, size_t &Zdim, size_t &Ndim) const

◆ getDimensions() [3/3]

void ImageGeneric::getDimensions ( ArrayDim aDim) const

Definition at line 108 of file xmipp_image_generic.cpp.

109 {
110  image->getDimensions(aDim);
111 }
ImageBase * image
void getDimensions(size_t &Xdim, size_t &Ydim, size_t &Zdim, size_t &Ndim) const

◆ getEulerAngles()

void ImageGeneric::getEulerAngles ( double &  rot,
double &  tilt,
double &  psi,
size_t  n = 0 
)
inline

Get Euler angles from image header

Definition at line 131 of file xmipp_image_generic.h.

133  {
134  image->getEulerAngles(rot, tilt, psi, n);
135  }
void getEulerAngles(double &rot, double &tilt, double &psi, const size_t n=0) const
ImageBase * image
double psi(const double x)
int * n
double tilt(const size_t n=0) const

◆ getGeometry()

MDRow& ImageGeneric::getGeometry ( const size_t  n = 0)
inline

Return geometry row

Definition at line 111 of file xmipp_image_generic.h.

112  {
113  return *(image->MD[n]);
114  }
std::vector< std::unique_ptr< MDRow > > MD
ImageBase * image
int * n

◆ getInfo()

void ImageGeneric::getInfo ( ImageInfo imgInfo) const

Get basic information from already read image file

Definition at line 113 of file xmipp_image_generic.cpp.

114 {
115  image->getInfo(imgInfo);
116 }
void getInfo(ImageInfo &imgInfo) const
ImageBase * image

◆ getPixel() [1/2]

double ImageGeneric::getPixel ( unsigned long  n,
int  k,
int  i,
int  j 
) const
inline

Get pixel value

Definition at line 360 of file xmipp_image_generic.h.

361  {
362  double ret;
363 #define GETVALUE(type) ret = NZYX_ELEM(*(MultidimArray<type>*)data->im,n,k,i,j);
365 #undef GETVALUE
366  return ret;
367  }
#define GETVALUE(type)
#define SWITCHDATATYPE(datatype, OP)

◆ getPixel() [2/2]

double ImageGeneric::getPixel ( int  i,
int  j 
) const
inline

Get pixel value

Definition at line 371 of file xmipp_image_generic.h.

372  {
373  double ret;
374 #define GETVALUE(type) ret = (double) A2D_ELEM(*(MultidimArray<type>*)data->im,i,j);
376 #undef GETVALUE
377  return ret;
378  }
#define GETVALUE(type)
#define SWITCHDATATYPE(datatype, OP)

◆ getPreview()

void ImageGeneric::getPreview ( ImageGeneric imgOut,
int  Xdim,
int  Ydim = -1,
int  select_slice = CENTRAL_SLICE,
size_t  select_img = FIRST_IMAGE 
)

Returns an image with a lower resolution as a preview image. If Zdim parameter is not passed, then all slices are rescaled. If Ydim is not passed, then Ydim is rescaled same factor as Xdim.

Definition at line 303 of file xmipp_image_generic.cpp.

304 {
305  imgOut.setDatatype(getDatatype());
306  image->getPreview(imgOut.image, xdim, ydim, select_slice, select_img);
307 }
DataType getDatatype() const
ImageBase * image
void setDatatype(DataType _datatype)
virtual void getPreview(ImageBase *imgOut, size_t Xdim, size_t Ydim=0, int select_slice=CENTRAL_SLICE, size_t select_img=FIRST_IMAGE)=0

◆ getSize()

size_t ImageGeneric::getSize ( ) const
inline

Get number of elements in image

Definition at line 124 of file xmipp_image_generic.h.

125  {
126  return NZYXSIZE(*(data->im));
127  }
#define NZYXSIZE(v)
MultidimArrayGeneric * data

◆ init()

void ImageGeneric::init ( void  )

Initialize the parameters.

Definition at line 65 of file xmipp_image_generic.cpp.

66 {
67  image = NULL;
68  data = NULL;
70 }
ImageBase * image
MultidimArrayGeneric * data

◆ initConstant()

void ImageGeneric::initConstant ( double  value) const
inline

Init constant

Definition at line 403 of file xmipp_image_generic.h.

404  {
405 #define INITCONS(type) (*(MultidimArray<type>*)(data->im)).initConstant((type) value);
407 #undef INITCONS
408 
409  }
#define CHECK_IMG(op)
#define INITCONS(type)
#define SWITCHDATATYPE(datatype, OP)

◆ initGeometry()

void ImageGeneric::initGeometry ( const size_t  n = 0)

Init geometry transformation with defaults values

Definition at line 36 of file xmipp_image_generic.cpp.

37 {
39 }
std::vector< std::unique_ptr< MDRow > > MD
static void emptifyHeader(MDRow &)
ImageBase * image
int * n

◆ initRandom()

void ImageGeneric::initRandom ( double  op1,
double  op2,
RandomMode  mode = RND_UNIFORM 
) const
inline

Init random

Definition at line 413 of file xmipp_image_generic.h.

414  {
415 #define INITRND(type) (*(MultidimArray<type>*)(data->im)).initRandom(op1, op2, mode);
417 #undef INITRND
418 
419  }
#define CHECK_IMG(op)
#define INITRND(type)
#define SWITCHDATATYPE(datatype, OP)

◆ isMapped()

bool ImageGeneric::isMapped ( )
inline

Check if image is mapped on file

Definition at line 207 of file xmipp_image_generic.h.

208  {
209  return image->isMapped();
210  }
ImageBase * image

◆ mapFile2Write()

void ImageGeneric::mapFile2Write ( int  Xdim,
int  Ydim,
int  Zdim,
const FileName _filename,
bool  createTempFile = false,
size_t  select_img = APPEND_IMAGE,
bool  isStack = false,
int  mode = WRITE_OVERWRITE,
int  _swapWrite = 0 
)

Definition at line 360 of file xmipp_image_generic.cpp.

362 {
363  image->setDataMode(HEADER); // Use this to ask rw* which datatype to use
364  if (swapWrite > 0)
365  image->swapOnWrite();
366  image->mapFile2Write(xdim,ydim,Zdim,_filename,createTempFile, select_img, isStack, mode);
367 
368  DataType writeDT = image->datatype();
369 
370  if ( writeDT != datatype)
371  {
372  setDatatype(writeDT);
373 
374  image->mapFile2Write(xdim,ydim,Zdim,_filename,createTempFile, select_img, isStack, mode);
375  }
376 }
void swapOnWrite()
DataType
void mode
void setDataMode(DataMode mode)
ImageBase * image
void setDatatype(DataType _datatype)
DataType datatype() const
void mapFile2Write(size_t Xdim, size_t Ydim, size_t Zdim, const FileName &_filename, bool createTempFile=false, size_t select_img=APPEND_IMAGE, bool isStack=false, int mode=WRITE_OVERWRITE)

◆ mirrorY()

void ImageGeneric::mirrorY ( void  )

Definition at line 392 of file xmipp_image_generic.cpp.

393 {
394  return image->mirrorY();
395 }
virtual void mirrorY()=0
ImageBase * image

◆ movePointerTo()

void ImageGeneric::movePointerTo ( int  select_slice = ALL_SLICES,
size_t  select_img = ALL_IMAGES 
)
inline

It changes the behavior of the internal multidimarray so it points to a specific slice/image from a stack, volume or stack of volumes. No information is deallocated from memory, so it is also possible to repoint to the whole stack,volume... (passing select_slice = ALL_SLICES and selec_img = ALL_IMAGES).

The options for select_slice are:

  • a slice number,
  • CENTRAL_SLICE, to automatically select the central slice of the volume,
  • ALL_SLICES, to recover the whole volume.

The options for selec_img are:

  • a image number of the stack,
  • ALL_IMAGES, to recover the whole stack.

If a specific slice number is selected, then a specific image from the stack must be also selected. Otherwise, FIRST_IMAGE is proposed.

If Image Object is read using readPreview method, movePointerTo only works when rescaling the image in X-Y plane only, but all slices must be read.

Definition at line 312 of file xmipp_image_generic.h.

313  {
314  image->movePointerTo(select_slice, select_img);
315  }
ImageBase * image
virtual void movePointerTo(int select_slice=ALL_SLICES, size_t select_img=ALL_IMAGES)=0

◆ multiply() [1/2]

void ImageGeneric::multiply ( const double  value)

Multiplication of the internal image by a constant

Definition at line 583 of file xmipp_image_generic.cpp.

584 {
585 
586 #define MULTIPLY(type) MultidimArray<type> & kk = *((MultidimArray<type>*) data->im);\
587  kk *= value;
588 
590 #undef MULTIPLY
591 
592 }
#define MULTIPLY(type)
#define SWITCHDATATYPE(datatype, OP)

◆ multiply() [2/2]

void ImageGeneric::multiply ( const ImageGeneric img)

Multiplication of the internal image by another image

Definition at line 571 of file xmipp_image_generic.cpp.

572 {
573 
574 #define MULTIPLYIMG(type) MultidimArray<type> & kk = *((MultidimArray<type>*) data->im);\
575  MultidimArray<type> & pp = *((MultidimArray<type>*) img.data->im);\
576  kk *= pp;
577 
579 #undef MULTIPLYIMG
580 
581 }
#define MULTIPLYIMG(type)
#define SWITCHDATATYPE(datatype, OP)

◆ operator()() [1/2]

MultidimArrayGeneric& ImageGeneric::operator() ( )
inline

Definition at line 320 of file xmipp_image_generic.h.

321  {
322  return *data;
323  }
MultidimArrayGeneric * data

◆ operator()() [2/2]

const MultidimArrayGeneric& ImageGeneric::operator() ( ) const
inline

Definition at line 325 of file xmipp_image_generic.h.

326  {
327  return *data;
328  }
MultidimArrayGeneric * data

◆ operator=()

ImageGeneric & ImageGeneric::operator= ( const ImageGeneric img)

assign operator

Definition at line 515 of file xmipp_image_generic.cpp.

516 {
517  copy(img);
518  return *this;
519 }
void copy(const ImageGeneric &img)

◆ operator==()

bool ImageGeneric::operator== ( const ImageGeneric i1) const

equal operator

Definition at line 521 of file xmipp_image_generic.cpp.

522 {
523  return(*(this->data) == *(i1.data));
524 }
MultidimArrayGeneric * data

◆ print()

void ImageGeneric::print ( ) const

Print image information

Definition at line 526 of file xmipp_image_generic.cpp.

527 {
528  String s;
529  toString(s);
530  std::cout << s <<std::endl;
531 }
void toString(String &s) const
std::string String
Definition: xmipp_strings.h:34

◆ read()

int ImageGeneric::read ( const FileName name,
DataMode  datamode = DATA,
size_t  select_img = ALL_IMAGES,
bool  mapData = false 
)

Read image from file.

Definition at line 229 of file xmipp_image_generic.cpp.

231 {
232  SET_DATATYPE(name);
233  return image->read(name, datamode, select_img, mapData && !imgInf.swap);
234 }
#define SET_DATATYPE(name)
ImageBase * image
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)

◆ readApplyGeo() [1/3]

int ImageGeneric::readApplyGeo ( const FileName name,
const MDRow row,
const ApplyGeoParams params = DefaultApplyGeoParams 
)

Read image from file with a header applied.

Definition at line 378 of file xmipp_image_generic.cpp.

380 {
381  setDatatype(name);
382  return image->readApplyGeo(name, row, params);
383 }
int readApplyGeo(const FileName &name, const MDRow &row, const ApplyGeoParams &params=DefaultApplyGeoParams)
ImageBase * image
void setDatatype(DataType _datatype)

◆ readApplyGeo() [2/3]

int ImageGeneric::readApplyGeo ( const FileName name,
const MetaData md,
size_t  objId,
const ApplyGeoParams params = DefaultApplyGeoParams 
)

Read image from file.

Definition at line 385 of file xmipp_image_generic.cpp.

387 {
388  setDatatype(name);
389  return image->readApplyGeo(name, md, objId, params);
390 }
int readApplyGeo(const FileName &name, const MDRow &row, const ApplyGeoParams &params=DefaultApplyGeoParams)
ImageBase * image
void setDatatype(DataType _datatype)

◆ readApplyGeo() [3/3]

int ImageGeneric::readApplyGeo ( const MetaData md,
size_t  objId,
const ApplyGeoParams params = DefaultApplyGeoParams 
)

Read an image from metadata, filename is taken from MDL_IMAGE

Definition at line 397 of file xmipp_image_generic.cpp.

399 {
400  FileName name;
401  md.getValue(MDL_IMAGE, name, objId/*md.firstObject()*/);
402  setDatatype(name);
403  return image->readApplyGeo(name, md, objId, params);
404 }
virtual bool getValue(MDObject &mdValueOut, size_t id) const =0
int readApplyGeo(const FileName &name, const MDRow &row, const ApplyGeoParams &params=DefaultApplyGeoParams)
ImageBase * image
void setDatatype(DataType _datatype)
Name of an image (std::string)

◆ readMapped()

int ImageGeneric::readMapped ( const FileName name,
size_t  select_img = ALL_IMAGES,
int  mode = WRITE_READONLY 
)

Read image mapped from file.

Definition at line 236 of file xmipp_image_generic.cpp.

237 {
238  SET_DATATYPE(name);
239  return image->read(name, DATA, select_img, !imgInf.swap, mode);
240 }
#define SET_DATATYPE(name)
void mode
ImageBase * image
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)

◆ readOrReadMapped()

int ImageGeneric::readOrReadMapped ( const FileName name,
size_t  select_img = ALL_IMAGES,
int  mode = WRITE_READONLY 
)

Definition at line 242 of file xmipp_image_generic.cpp.

243 {
244  try
245  {
246  return read(name, DATA, select_img, false);
247  }
248  catch (XmippError &xe)
249  {
250  if (xe.__errno == ERR_MEM_NOTENOUGH)
251  {
252  reportWarning("ImageBase::readOrReadMapped: Not enough memory to allocate. \n"
253  " Proceeding to map image from file.");
254  return readMapped(name, select_img, mode);
255  }
256  else
257  throw xe;
258  }
259 }
void reportWarning(const String &what)
There is not enough memory for allocation.
Definition: xmipp_error.h:166
void mode
ErrorType __errno
Definition: xmipp_error.h:227
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false)
int readMapped(const FileName &name, size_t select_img=ALL_IMAGES, int mode=WRITE_READONLY)

◆ readOrReadPreview()

int ImageGeneric::readOrReadPreview ( const FileName name,
size_t  Xdim,
size_t  Ydim = 0,
int  select_slice = CENTRAL_SLICE,
size_t  select_img = FIRST_IMAGE,
bool  mapData = false,
bool  wrap = true 
)

This function allows to read the original image or a preview of it also allowing to select either a specific image from the stack or a slice from a volume.

In the case of reading images in its real dimensions it is also possible to image map from file.

Definition at line 291 of file xmipp_image_generic.cpp.

293 {
294  SET_DATATYPE(name);
295  double scale = getScale(imgInf, xdim, ydim);
296  //std::cerr << "DEBUG_JM: readOrReadPreview, scale: " << scale << std::endl;
297 
298  if (scale < 0.1)
299  return readPreviewSmooth(name, xdim, ydim, select_slice, select_img);
300  return image->readOrReadPreview(name, xdim, ydim, select_slice, select_img, !imgInf.swap && mapData);
301 }
int readPreviewSmooth(const FileName &name, size_t Xdim, size_t Ydim=0, int select_slice=CENTRAL_SLICE, size_t select_img=FIRST_IMAGE)
#define SET_DATATYPE(name)
int readOrReadPreview(const FileName &name, size_t Xdim, size_t Ydim, int select_slice=CENTRAL_SLICE, size_t select_img=FIRST_IMAGE, bool mapData=false)
double getScale(ImageInfo imgInf, size_t &xdim, size_t &ydim)
ImageBase * image

◆ readPreview()

int ImageGeneric::readPreview ( const FileName name,
size_t  Xdim,
size_t  Ydim = 0,
int  select_slice = CENTRAL_SLICE,
size_t  select_img = FIRST_IMAGE 
)

Definition at line 280 of file xmipp_image_generic.cpp.

281 {
282  SET_DATATYPE(name);
283  double scale = getScale(imgInf, xdim, ydim);
284  //std::cerr << "DEBUG_JM: readPreview, scale: " << scale << std::endl;
285 
286  if (scale < 0.1)
287  return readPreviewSmooth(name, xdim, ydim, select_slice, select_img);
288  return image->readPreview(name, xdim, ydim, select_slice, select_img);
289 }
int readPreviewSmooth(const FileName &name, size_t Xdim, size_t Ydim=0, int select_slice=CENTRAL_SLICE, size_t select_img=FIRST_IMAGE)
virtual int readPreview(const FileName &name, size_t Xdim, size_t Ydim=0, int select_slice=CENTRAL_SLICE, size_t select_img=FIRST_IMAGE)=0
#define SET_DATATYPE(name)
double getScale(ImageInfo imgInf, size_t &xdim, size_t &ydim)
ImageBase * image

◆ readPreviewFourier()

int ImageGeneric::readPreviewFourier ( const FileName name,
size_t  Xdim,
size_t  Ydim = 0,
int  select_slice = CENTRAL_SLICE,
size_t  select_img = FIRST_IMAGE 
)

Definition at line 310 of file xmipp_image_generic.cpp.

311 {
312  ImageGeneric ig;
313  int result = ig.read(name, DATA, select_img);
314  ImageInfo ii;
315  ig.getInfo(ii);
316  setDatatype(ii.datatype);
317  switch (select_slice)
318  {
319  case CENTRAL_SLICE:
320  case ALL_SLICES:
321  select_slice = (int)((float)ii.adim.zdim / 2.0);
322  break;
323  default:
324  select_slice--;
325  break;
326  }
327 
328  getScale(ii, xdim, ydim);
329 
330  ig().getSlice(select_slice, data);
331 
332 
333  data->setXmippOrigin();
334  selfScaleToSizeFourier((int)ydim, (int)xdim, *data, 1);
335  return result;
336 }
size_t zdim
void getInfo(ImageInfo &imgInfo) const
double getScale(ImageInfo imgInf, size_t &xdim, size_t &ydim)
void selfScaleToSizeFourier(int Zdim, int Ydim, int Xdim, MultidimArray< double > &mda, int nThreads)
Definition: xmipp_fftw.cpp:723
ArrayDim adim
#define CENTRAL_SLICE
void setDatatype(DataType _datatype)
DataType datatype
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false)
MultidimArrayGeneric * data
#define ALL_SLICES

◆ readPreviewSmooth()

int ImageGeneric::readPreviewSmooth ( const FileName name,
size_t  Xdim,
size_t  Ydim = 0,
int  select_slice = CENTRAL_SLICE,
size_t  select_img = FIRST_IMAGE 
)

Definition at line 338 of file xmipp_image_generic.cpp.

339 {
340  //std::cerr << "DEBUG_JM: readPreviewSmooth" << std::endl;
341  ImageGeneric ig;
342  int result = ig.read(name, DATA, select_img);
344  ImageInfo ii;
345  ig.getInfo(ii);
346 
347  getScale(ii, xdim, ydim);
348 
350  resize(xdim, ydim, 1, 1, false);
351 
352  byte *inputArray = (byte*) MULTIDIM_ARRAY_GENERIC(ig).getArrayPointer();
353  byte *outputArray = (byte*) MULTIDIM_ARRAY_GENERIC(*this).getArrayPointer();
354 
355  SmoothResize(inputArray, outputArray, ii.adim.xdim, ii.adim.ydim, xdim, ydim);
356  return result;
357 }
void resize(int Xdim, int Ydim, int Zdim, size_t Ndim, bool copy=true)
size_t xdim
void SmoothResize(byte *picSrc8, byte *destpic8, size_t swide, size_t shigh, size_t dwide, size_t dhigh)
Definition: xvsmooth.cpp:93
void getInfo(ImageInfo &imgInfo) const
double getScale(ImageInfo imgInf, size_t &xdim, size_t &ydim)
ArrayDim adim
void convert2Datatype(DataType datatype, CastWriteMode castMode=CW_CONVERT)
#define MULTIDIM_ARRAY_GENERIC(v)
void setDatatype(DataType _datatype)
unsigned char byte
Definition: xvsmooth.cpp:73
size_t ydim
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false)

◆ resize()

void ImageGeneric::resize ( int  Xdim,
int  Ydim,
int  Zdim,
size_t  Ndim,
bool  copy = true 
)
inline

Resizes image dimensions

Definition at line 146 of file xmipp_image_generic.h.

147  {
148  image->setDimensions(Xdim, Ydim, Zdim, Ndim);
149  data->resize(Ndim, Zdim, Ydim, Xdim, copy);
150  }
void copy(const ImageGeneric &img)
void resize(size_t Ndim, int Zdim, int Ydim, int Xdim, bool copy=true)
virtual void setDimensions(int Xdim, int Ydim, int Zdim, size_t Ndim)=0
ImageBase * image
MultidimArrayGeneric * data

◆ reslice() [1/2]

void ImageGeneric::reslice ( AxisView  view)

Definition at line 502 of file xmipp_image_generic.cpp.

503 {
504  ImageGeneric imgOut;
505  reslice(face, imgOut);
506  clear();
507  datatype = imgOut.getDatatype();
508  image = imgOut.image;
509  data = imgOut.data;
510  imgOut.image = NULL;
511  imgOut.data = NULL;
512 }
DataType getDatatype() const
ImageBase * image
void reslice(AxisView view)
MultidimArrayGeneric * data

◆ reslice() [2/2]

void ImageGeneric::reslice ( AxisView  view,
ImageGeneric out 
)

Definition at line 457 of file xmipp_image_generic.cpp.

458 {
459  ArrayDim aDim, aDimOut;
460  data->getDimensions(aDim);
461 
462  char axis;
463  bool reverse;
464 
465  aDimOut = aDim;
466 
467  if (face == VIEW_Y_NEG || face == VIEW_Y_POS)
468  {
469  axis = 'Y';
470  aDimOut.ydim = aDim.zdim;
471  aDimOut.zdim = aDim.ydim;
472  reverse = (face == VIEW_Y_NEG);
473  }
474  else if (face == VIEW_X_NEG || face == VIEW_X_POS)
475  {
476  axis = 'X';
477  aDimOut.xdim = aDim.zdim;
478  aDimOut.zdim = aDim.xdim;
479  reverse = (face == VIEW_X_NEG);
480  }
481  else
482  REPORT_ERROR(ERR_VALUE_INCORRECT, formatString("reslice: not supported view %d", (int)face));
483 
484  DataType dtype = getDatatype();
485  imgOut.setDatatype(dtype);
486  imgOut().resize(aDimOut, false);
487  imgOut.image->setADimFile(aDimOut);
488 
489  MultidimArrayGeneric imTemp;
490 
491  int index;
492 
493  for (size_t k = 0; k < aDimOut.zdim; k++)
494  {
495  imTemp.aliasSlice(MULTIDIM_ARRAY_GENERIC(imgOut), k);
496  index = k + (aDimOut.zdim - 1 - 2*k) * (int)reverse;
497  MULTIDIM_ARRAY_GENERIC(*this).getSlice(index, &imTemp, axis, !reverse);
498  }
499 
500 }
size_t xdim
void aliasSlice(MultidimArrayGeneric &mdim, int select_slice)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
DataType getDatatype() const
char axis
size_t zdim
viol index
DataType
#define MULTIDIM_ARRAY_GENERIC(v)
String formatString(const char *format,...)
size_t ydim
void getDimensions(size_t &Xdim, size_t &Ydim, size_t &Zdim, size_t &Ndim) const
Incorrect value received.
Definition: xmipp_error.h:195
MultidimArrayGeneric * data

◆ setDataMode()

void ImageGeneric::setDataMode ( DataMode  mode)
inline

Set image dataMode

Definition at line 163 of file xmipp_image_generic.h.

164  {
166  }
void mode
void setDataMode(DataMode mode)
ImageBase * image

◆ setDatatype() [1/3]

void ImageGeneric::setDatatype ( DataType  _datatype)

Set the data type for the generic image

Definition at line 118 of file xmipp_image_generic.cpp.

119 {
120  if (imgType == datatype)
121  return;
122 
123  clear();
124  datatype = imgType;
125  switch (datatype)
126  {
127  case DT_Float:
128  {
129  Image<float> *imT = new Image<float>;
130  image = imT;
132  }
133  break;
134  case DT_Double:
135  {
136  Image<double> *imT = new Image<double>;
137  image = imT;
139  }
140  break;
141  case DT_UInt:
142  {
144  image = imT;
146  }
147  break;
148  case DT_Int:
149  {
150  Image<int> *imT = new Image<int>;
151  image = imT;
153  }
154  break;
155  case DT_UShort:
156  {
158  image = imT;
160  }
161  break;
162  case DT_Short:
163  {
164  Image<short> *imT = new Image<short>;
165  image = imT;
167  }
168  break;
169  case DT_UHalfByte:
170  case DT_UChar:
171  {
173  image = imT;
175  }
176  break;
177  case DT_SChar:
178  {
179  Image<char> *imT = new Image<char>;
180  image = imT;
182  }
183  break;
184  case DT_ULong:
185  {
187  image = imT;
189  }
190  break;
191  case DT_Long:
192  {
193  Image<long> *imT = new Image<long>;
194  image = imT;
196  }
197  break;
198  case DT_HalfFloat:
199  {
201  image = imT;
203  }
204  break;
205  case DT_Unknown:
206  REPORT_ERROR(ERR_IMG_UNKNOWN,"Datatype of the image file is unknown.");
207  break;
208  default:
209  REPORT_ERROR(ERR_NOT_IMPLEMENTED, "Datatype not implemented.");
210  break;
211  }
212 }
Case or algorithm not implemented yet.
Definition: xmipp_error.h:177
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Unknown image type.
Definition: xmipp_error.h:130
MultidimArray< T > data
Definition: xmipp_image.h:55
ImageBase * image
MultidimArrayGeneric * data

◆ setDatatype() [2/3]

void ImageGeneric::setDatatype ( const FileName name,
ImageInfo imgInf 
)

Set the data type according to the image file, checking if file size is correct.

Definition at line 214 of file xmipp_image_generic.cpp.

215 {
216  getImageInfo(name, imgInf);
217  checkImageFileSize(name, imgInf, true);
218  setDatatype(imgInf.datatype);
219 
220 }
void getImageInfo(const MetaData &md, size_t &Xdim, size_t &Ydim, size_t &Zdim, size_t &Ndim, DataType &datatype, MDLabel image_label)
void setDatatype(DataType _datatype)
DataType datatype
bool checkImageFileSize(const FileName &name, const ImageInfo &imgInfo, bool error)

◆ setDatatype() [3/3]

void ImageGeneric::setDatatype ( const FileName name)

Definition at line 224 of file xmipp_image_generic.cpp.

225 {
226  SET_DATATYPE(name);
227 }
#define SET_DATATYPE(name)

◆ setPixel() [1/2]

void ImageGeneric::setPixel ( unsigned long  n,
int  k,
int  i,
int  j,
double  value 
) const
inline

Set pixel value

Definition at line 382 of file xmipp_image_generic.h.

383  {
384 #define SETVALUE(type) NZYX_ELEM(*(MultidimArray<type>*)data->im,n,k,i,j) = (type) value;
386 #undef SETVALUE
387 
388  }
#define SETVALUE(type)
#define SWITCHDATATYPE(datatype, OP)

◆ setPixel() [2/2]

void ImageGeneric::setPixel ( int  i,
int  j,
double  value 
) const
inline

Set pixel value

Definition at line 392 of file xmipp_image_generic.h.

393  {
394 
395 #define SETVALUE(type) A2D_ELEM(*(MultidimArray<type>*)data->im,i,j) = (type) value;
397 #undef SETVALUE
398 
399  }
#define CHECK_IMG(op)
#define SETVALUE(type)
#define SWITCHDATATYPE(datatype, OP)

◆ subtract()

void ImageGeneric::subtract ( const ImageGeneric img)

Subtraction of the passed image to the internal's

Definition at line 557 of file xmipp_image_generic.cpp.

558 {
559  if (datatype != img.datatype)
560  REPORT_ERROR(ERR_TYPE_INCORRECT, "Images have different datatypes");
561 
562 #define MINUS(type) MultidimArray<type> & kk = *((MultidimArray<type>*) data->im);\
563  MultidimArray<type> & pp = *((MultidimArray<type>*) img.data->im);\
564  kk -= pp;
565 
567 #undef MINUS
568 
569 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define MINUS(type)
Incorrect type received.
Definition: xmipp_error.h:190
#define SWITCHDATATYPE(datatype, OP)

◆ tilt()

double ImageGeneric::tilt ( const size_t  n = 0) const
inline

Get Tilt angle from image header

Definition at line 139 of file xmipp_image_generic.h.

140  {
141  return image->tilt(n);
142  }
double tilt(const size_t n=0) const
ImageBase * image
int * n

◆ toString()

void ImageGeneric::toString ( String s) const

Add to string the image information

Definition at line 533 of file xmipp_image_generic.cpp.

534 {
535  std::stringstream ss;
536  if (image == NULL)
537  ss << "Xmipp::ImageGeneric: Uninitialized image";
538  else
539  ss << *image;
540  s = ss.str();
541 }
ImageBase * image

◆ write()

void ImageGeneric::write ( const FileName name = "",
size_t  select_img = ALL_IMAGES,
bool  isStack = false,
int  mode = WRITE_OVERWRITE,
CastWriteMode  castMode = CW_CAST,
int  _swapWrite = 0 
)
inline

Write image to file.

Definition at line 278 of file xmipp_image_generic.h.

280  {
281  image->write(name,select_img,isStack,mode,castMode,_swapWrite);
282  }
void write(const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
void mode
ImageBase * image

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  o,
const ImageGeneric I 
)
friend

Definition at line 429 of file xmipp_image_generic.h.

430  {
431  o << I.image;
432  return o;
433  }
ImageBase * image

Member Data Documentation

◆ data

MultidimArrayGeneric* ImageGeneric::data

Definition at line 53 of file xmipp_image_generic.h.

◆ datatype

DataType ImageGeneric::datatype

Definition at line 52 of file xmipp_image_generic.h.

◆ image

ImageBase* ImageGeneric::image

Definition at line 51 of file xmipp_image_generic.h.

◆ swap

bool ImageGeneric::swap
protected

Definition at line 57 of file xmipp_image_generic.h.


The documentation for this class was generated from the following files: