Xmipp  v3.23.11-Nereus
Public Member Functions | Public Attributes | Protected Member Functions | Friends | List of all members
Image< T > Class Template Reference

#include <image_operate.h>

Inheritance diagram for Image< T >:
Inheritance graph
[legend]
Collaboration diagram for Image< T >:
Collaboration graph
[legend]

Public Member Functions

 Image ()
 
 Image (int Xdim, int Ydim, int Zdim, int Ndim, const FileName &_filename)
 
 Image (int Xdim, int Ydim, int Zdim=1, int Ndim=1, bool _mmapOn=false)
 
 Image (const Image< T > &im)
 
 Image (const MultidimArray< T > &im)
 
virtual ~Image ()
 
void clear ()
 
void clearData ()
 
bool isComplexT () const
 
void getInverseAxisOrder (const std::array< int, 4 > &order, std::array< int, 4 > &result)
 
void transposeAxisSizes (const std::array< size_t, 4 > &sizes, const std::array< int, 4 > &order, std::array< size_t, 4 > &result)
 
void transposeInPlace (MultidimArray< T > &multidimArray, const std::array< int, 4 > &order)
 
void castPage2T (char *page, T *ptrDest, DataType datatype, size_t pageSize)
 
void castPage2Datatype (T *srcPtr, char *page, DataType datatype, size_t pageSize) const
 
void castConvertPage2Datatype (T *srcPtr, char *page, DataType datatype, size_t pageSize, double min0, double max0, CastWriteMode castMode=CW_CONVERT) const
 
void setPage2T (size_t offset, char *page, DataType datatype, size_t pageSize)
 
void getPageFromT (size_t offset, char *page, DataType datatype, size_t pageSize)
 
void getCastConvertPageFromT (size_t offset, char *page, DataType datatype, size_t pageSize, double min0, double max0, CastWriteMode castMode=CW_CONVERT) const
 
bool checkMmapT (DataType datatype) override
 
void mirrorY (void)
 
void mirrorX (void)
 
void selfApplyGeometry (int SplineDegree, bool wrap=xmipp_transformation::WRAP, bool only_apply_shifts=false)
 
int readPreview (const FileName &name, size_t Xdim, size_t Ydim=0, int select_slice=CENTRAL_SLICE, size_t select_img=FIRST_IMAGE)
 
void getPreview (ImageBase *imgBOut, size_t Xdim, size_t Ydim=0, int select_slice=CENTRAL_SLICE, size_t select_img=FIRST_IMAGE)
 
void movePointerTo (int select_slice=ALL_SLICES, size_t select_img=ALL_IMAGES)
 
void writePageAsDatatype (FILE *fimg, DataType datatype, size_t datasize_n)
 
Image< T > & operator= (const Image< T > &op1)
 
MultidimArray< T > & operator() ()
 
const MultidimArray< T > & operator() () const
 
T & operator() (int i, int j) const
 
bool operator== (const Image< T > &i1) const
 
T & operator() (int k, int i, int j) const
 
size_t getSize () const
 
void getTransformationMatrix (Matrix2D< double > &A, bool only_apply_shifts=false, const size_t n=0)
 
void sumWithFile (const FileName &fn)
 
template<>
void castPage2T (char *page, std::complex< double > *ptrDest, DataType datatype, size_t pageSize)
 
template<>
void castPage2Datatype (std::complex< double > *srcPtr, char *page, DataType datatype, size_t pageSize) const
 
template<>
void castConvertPage2Datatype (std::complex< double > *srcPtr, char *page, DataType datatype, size_t pageSize, double min0, double max0, CastWriteMode castMode) const
 
template<>
void castPage2T (char *page, std::complex< double > *ptrDest, DataType datatype, size_t pageSize)
 
template<>
void castPage2Datatype (std::complex< double > *srcPtr, char *page, DataType datatype, size_t pageSize) const
 
template<>
void castConvertPage2Datatype (std::complex< double > *srcPtr, char *page, DataType datatype, size_t pageSize, double min0, double max0, CastWriteMode castMode) const
 
- Public Member Functions inherited from ImageBase
void init ()
 
void copy (const ImageBase &other)
 
void clearHeader ()
 
bool isComplex () const
 
virtual ~ImageBase ()
 
bool isImage (const FileName &name)
 
bool isMapped ()
 
bool isRealImage (const FileName &name)
 
bool isComplexImage (const FileName &name)
 
void rename (const FileName &name)
 
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)
 
int read (const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
 
int readBatch (const FileName &name, size_t start_img, size_t batch_size, DataMode datamode=DATA, bool mapData=false, int mode=WRITE_READONLY)
 
int readRange (const FileName &name, size_t start_img, size_t end_img, DataMode datamode=DATA, bool mapData=false, int mode=WRITE_READONLY)
 
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 setGeo (const MDRow &row, size_t n=0)
 
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 readOrReadPreview (const FileName &name, size_t Xdim, size_t Ydim, int select_slice=CENTRAL_SLICE, size_t select_img=FIRST_IMAGE, bool mapData=false)
 
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 swapPage (char *page, size_t pageNrElements, DataType datatype, int swap=1)
 
void swapOnWrite ()
 
const FileNamename () const
 
void getDimensions (size_t &Xdim, size_t &Ydim, size_t &Zdim, size_t &Ndim) const
 
void getDimensions (ArrayDim &aDim)
 
ArrayDim getDimensions ()
 
void getInfo (ImageInfo &imgInfo) const
 
void getInfo (const FileName &name, ImageInfo &imgInfo)
 
void getOffsetAndSwap (size_t &_offset, int &_swap) const
 
int getSwap () const
 
MDRowgetGeometry (const size_t n=0)
 
void initGeometry (const size_t n=0)
 
bool individualContainsLabel (MDLabel label) const
 
bool mainContainsLabel (MDLabel label) const
 
double rot (const size_t n=0) const
 
double tilt (const size_t n=0) const
 
double psi (const size_t n=0) const
 
double Xoff (const size_t n=0) const
 
double Yoff (const size_t n=0) const
 
double Zoff (const size_t n=0) const
 
double weight (const size_t n=0) const
 
double scale (const size_t n=0) const
 
bool flip (const size_t n=0) const
 
DataType datatype () const
 
double samplingRateX () const
 
void setADimFile (ArrayDim aDim)
 
void setName (const FileName &_filename)
 
void setDataMode (DataMode mode)
 
void setEulerAngles (double rot, double tilt, double psi, const size_t n=0)
 
void getEulerAngles (double &rot, double &tilt, double &psi, const size_t n=0) const
 
void setRot (double rot, const size_t n=0)
 
void setTilt (double tilt, const size_t n=0)
 
void setPsi (double psi, const size_t n=0)
 
void setShifts (double xoff, double yoff, double zoff=0., const size_t n=0)
 
void getShifts (double &xoff, double &yoff, double &zoff, const size_t n=0) const
 
void setXoff (double xoff, const size_t n=0)
 
void setYoff (double yoff, const size_t n=0)
 
void setZoff (double zoff, const size_t n=0)
 
void setScale (double scale, const size_t n=0)
 
void getScale (double &scale, const size_t n=0)
 
void setFlip (bool flip, const size_t n=0)
 
void setWeight (double weight, const size_t n=0)
 

Public Attributes

MultidimArray< T > data
 
- Public Attributes inherited from ImageBase
MultidimArrayBasemdaBase
 
std::vector< std::unique_ptr< MDRow > > MD
 
MDRowVec MDMainHeader
 

Protected Member Functions

void applyGeo (const MDRow &row, bool only_apply_shifts=false, bool wrap=xmipp_transformation::WRAP) override
 
void setDimensions (int Xdim, int Ydim, int Zdim, size_t Ndim)
 
- Protected Member Functions inherited from ImageBase
int readDM3 (size_t img_select, bool isStack=false)
 
int writeDM3 (size_t img_select, bool isStack=false, int mode=WRITE_OVERWRITE)
 
int readDM4 (size_t img_select, bool isStack=false)
 
int writeDM4 (size_t img_select, bool isStack=false, int mode=WRITE_OVERWRITE)
 
int readIMAGIC (size_t img_select)
 
int writeIMAGIC (size_t img_select=ALL_IMAGES, int mode=WRITE_OVERWRITE, const String &bitDepth="", CastWriteMode castMode=CW_CAST)
 
int readMRC (size_t select_img, bool isStack=false)
 
int readMRC (size_t start_img, size_t batch_size, bool isStack=false)
 
int writeMRC (size_t select_img, bool isStack=false, int mode=WRITE_OVERWRITE, const String &bitDepth="", CastWriteMode castMode=CW_CAST)
 
int readINF (size_t img_select, bool isStack=false)
 
int writeINF (size_t img_select, bool isStack=false, int mode=WRITE_OVERWRITE, String bitDepth="", CastWriteMode castMode=CW_CAST)
 
DataType datatypeRAW (String strDT)
 
int readRAW (size_t select_img, bool isStack=false)
 
int readSPIDER (size_t select_img)
 
int readSPIDER (size_t start_img, size_t batch_size)
 
int writeSPIDER (size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE)
 
int readSPE (size_t select_img, bool isStack=false)
 
int writeSPE (size_t select_img, bool isStack=false, int mode=WRITE_OVERWRITE)
 
int readTIA (int img_select, bool isStack=false)
 
int writeTIA (int img_select, bool isStack=false, int mode=WRITE_OVERWRITE)
 
int readJPEG (size_t select_img)
 
int writeJPEG (size_t select_img, bool isStack=false, int mode=WRITE_OVERWRITE, String bitDepth="", CastWriteMode castMode=CW_CONVERT)
 
void castTiffTile2T (size_t offset, char *tif_buf, unsigned int x, unsigned int y, unsigned int imageWidth, unsigned int imageLength, unsigned int tileWidth, unsigned int tileLength, unsigned short samplesPerPixel, DataType datatype)
 
void castTiffLine2T (size_t offset, char *tif_buf, unsigned int y, unsigned int imageWidth, unsigned int imageLength, unsigned short samplesPerPixel, DataType datatype)
 
DataType datatypeTIFF (TIFFDirHead dHead)
 
int readTIFF (size_t select_img, bool isStack=false)
 
int writeTIFF (size_t select_img, bool isStack=false, int mode=WRITE_OVERWRITE, String bitDepth="", CastWriteMode castMode=CW_CAST)
 
int readEM (size_t select_img, bool isStack=false)
 
int writeEM (size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE)
 
int readPIF (size_t select_img)
 
int writePIF (size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE)
 
DataType datatypeH5 (hid_t dataset)
 
hid_t H5Datatype (DataType datatype)
 
int readHDF5 (size_t select_img)
 
int writeHDF5 (size_t select_img, bool isStack=false, int mode=WRITE_OVERWRITE, String bitDepth="", CastWriteMode castMode=CW_CAST)
 
int readEER (size_t select_img)
 
ImageFHandleropenFile (const FileName &name, int mode=WRITE_READONLY) const
 
More...
 
void closeFile (ImageFHandler *hFile=NULL) const
 
int _read (const FileName &name, ImageFHandler *hFile, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false)
 
int _readBatch (const FileName &name, ImageFHandler *hFile, size_t start_img, size_t batch_size, DataMode datamode=DATA, bool mapData=false)
 
void _write (const FileName &name, ImageFHandler *hFile, size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST)
 
void setDatatype (DataType datatype)
 

Friends

class ImageCollection
 
template<typename TT >
class Image
 

Additional Inherited Members

- Protected Attributes inherited from ImageBase
FileName filename
 
FileName tempFilename
 
FileName dataFName
 
FILE * fimg
 
FILE * fhed
 
TIFFtif
 
hid_t fhdf5
 
ImageFHandlerhFile
 
ArrayDim aDimFile
 
DataMode dataMode
 
size_t offset
 
int swap
 
int swapWrite
 
std::array< int, 4 > axisOrder
 
TransformType transform
 
size_t replaceNsize
 
bool _exists
 
bool mmapOnRead
 
bool mmapOnWrite
 
int mFd
 
size_t mappedSize
 
size_t mappedOffset
 
size_t virtualOffset
 
- Static Protected Attributes inherited from ImageBase
static constexpr std::array< int, 4 > defaultAxisOrder = {0,1,2,3}
 

Detailed Description

template<typename T>
class Image< T >

Template class for images. The image class is the general image handling class.

Definition at line 36 of file image_operate.h.

Constructor & Destructor Documentation

◆ Image() [1/5]

template<typename T>
Image< T >::Image ( )
inline

Empty constructor

An empty image is created.

Definition at line 66 of file xmipp_image.h.

67  {
69  init();
70  }
MultidimArray< T > data
Definition: xmipp_image.h:55
MultidimArrayBase * mdaBase

◆ Image() [2/5]

template<typename T>
Image< T >::Image ( int  Xdim,
int  Ydim,
int  Zdim,
int  Ndim,
const FileName _filename 
)
inline

Constructor with size and filename

An image file, which name and format are given by filename, is created with the given size. Then the image is mapped to this file.

Image I(64,64,1,1,"image.spi");

Definition at line 81 of file xmipp_image.h.

82  {
84  init();
85  mmapOnWrite = true;
86  data.setDimensions(Xdim, Ydim, Zdim, Ndim);
87  MD.resize(Ndim);
88  filename = _filename;
90  _write(_filename, hFile, ALL_IMAGES, false, WRITE_OVERWRITE);
91  closeFile(hFile);
92  }
ImageFHandler * openFile(const FileName &name, int mode=WRITE_READONLY) const
std::vector< std::unique_ptr< MDRow > > MD
ImageFHandler * hFile
void _write(const FileName &name, ImageFHandler *hFile, size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST)
void closeFile(ImageFHandler *hFile=NULL) const
MultidimArray< T > data
Definition: xmipp_image.h:55
#define ALL_IMAGES
FileName filename
MultidimArrayBase * mdaBase

◆ Image() [3/5]

template<typename T>
Image< T >::Image ( int  Xdim,
int  Ydim,
int  Zdim = 1,
int  Ndim = 1,
bool  _mmapOn = false 
)
inline

Constructor with size

A blank image (0.0 filled) is created with the given size. Pay attention to the dimension order: Y and then X. If _mmapOn is True then image is allocated in a temporary file.

Image I(64,64);

Definition at line 104 of file xmipp_image.h.

105  {
107  init();
108  data.setMmap(_mmapOn);
109  data.coreAllocate(Ndim, Zdim, Ydim, Xdim);
110  MD.resize(Ndim);
111  }
std::vector< std::unique_ptr< MDRow > > MD
MultidimArray< T > data
Definition: xmipp_image.h:55
MultidimArrayBase * mdaBase

◆ Image() [4/5]

template<typename T>
Image< T >::Image ( const Image< T > &  im)
inline

Definition at line 113 of file xmipp_image.h.

114  {
116  init();
117  *this = im;
118  }
MultidimArray< T > data
Definition: xmipp_image.h:55
MultidimArrayBase * mdaBase

◆ Image() [5/5]

template<typename T>
Image< T >::Image ( const MultidimArray< T > &  im)
inline

Constructor with MultidimArray alias

An image is created directly with its multidimarray aliased to im. This function is useful when debugging and you want to save multidimarrays.

Definition at line 125 of file xmipp_image.h.

126  {
128  init();
129  data.alias(im);
130  }
MultidimArray< T > data
Definition: xmipp_image.h:55
MultidimArrayBase * mdaBase

◆ ~Image()

template<typename T>
virtual Image< T >::~Image ( )
inlinevirtual

Destructor.

Definition at line 135 of file xmipp_image.h.

136  {
137  clearData();
138  }
void clearData()
Definition: xmipp_image.h:156

Member Function Documentation

◆ applyGeo()

template<typename T >
void Image< T >::applyGeo ( const MDRow row,
bool  only_apply_shifts = false,
bool  wrap = xmipp_transformation::WRAP 
)
overrideprotectedvirtual

Specific read functions for different file formatsApply geometry in referring metadata to the image

Implements ImageBase.

Definition at line 327 of file xmipp_image.cpp.

327  {
328  //This implementation does not handle stacks,
329  //read in a block
330  if (data.ndim != 1)
332  "Geometric transformation cannot be applied to stacks!!!");
333 
334  if (MD.size() == 0)
335  MD.push_back(std::unique_ptr<MDRowVec>(new MDRowVec(MDL::emptyHeaderVec())));
336  MDRow &rowAux = *MD[0];
337 
339  {
340  double aux;
341  //origins
342  if (row.getValue(MDL_ORIGIN_X, aux))
343  rowAux.setValue(MDL_ORIGIN_X, aux);
344  if (row.getValue(MDL_ORIGIN_Y, aux))
345  rowAux.setValue(MDL_ORIGIN_Y, aux);
346  if (row.getValue(MDL_ORIGIN_Z, aux))
347  rowAux.setValue(MDL_ORIGIN_Z, aux);
348  //shifts
349  if (row.getValue(MDL_SHIFT_X, aux))
350  rowAux.setValue(MDL_SHIFT_X, aux);
351  if (row.getValue(MDL_SHIFT_Y, aux))
352  rowAux.setValue(MDL_SHIFT_Y, aux);
353  if (row.getValue(MDL_SHIFT_Z, aux))
354  rowAux.setValue(MDL_SHIFT_Z, aux);
355  //rotations
356  if (row.getValue(MDL_ANGLE_ROT, aux))
357  rowAux.setValue(MDL_ANGLE_ROT, aux);
358  if (row.getValue(MDL_ANGLE_TILT, aux))
359  rowAux.setValue(MDL_ANGLE_TILT, aux);
360  if (row.getValue(MDL_ANGLE_PSI, aux))
361  rowAux.setValue(MDL_ANGLE_PSI, aux);
362  //scale
363  if (row.getValue(MDL_SCALE, aux))
364  rowAux.setValue(MDL_SCALE, aux);
365  //weight
366  if (row.getValue(MDL_WEIGHT, aux))
367  rowAux.setValue(MDL_WEIGHT, aux);
368  bool auxBool;
369  if (row.getValue(MDL_FLIP, auxBool))
370  rowAux.setValue(MDL_FLIP, auxBool);
371  }
372 
373  //apply geo has not been defined for volumes
374  //and only make sense when reading data
375  if (data.getDim() < 3 && dataMode >= DATA)
376  {
379  getTransformationMatrix(A, only_apply_shifts);
380  else
381  {
382  String matrixStr;
383  row.getValue(MDL_TRANSFORM_MATRIX, matrixStr);
384  string2TransformationMatrix(matrixStr, A, 3);
385  }
386 
387  if (!A.isIdentity())
388  {
389  MultidimArray<T> tmp = MULTIDIM_ARRAY(*this);
390  applyGeometry(xmipp_transformation::BSPLINE3, MULTIDIM_ARRAY(*this), tmp, A, xmipp_transformation::IS_NOT_INV,
391  wrap);
392  }
393  }
394 }
bool isIdentity() const
Definition: matrix2d.cpp:1323
Rotation angle of an image (double,degrees)
DataMode dataMode
void string2TransformationMatrix(const String &matrixStr, Matrix2D< double > &matrix, size_t dim)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Tilting angle of an image (double,degrees)
Shift for the image in the X axis (double)
void applyGeometry(int SplineDegree, MultidimArray< std::complex< double > > &V2, const MultidimArray< std::complex< double > > &V1, const Matrix2D< double > &A, bool inv, bool wrap, std::complex< double > outside, MultidimArray< double > *BcoeffsPtr)
std::vector< std::unique_ptr< MDRow > > MD
#define MULTIDIM_ARRAY(v)
Special label to be used when gathering MDs in MpiMetadataPrograms.
auxiliary label to be used as an index (long)
Incorrect MultidimArray size.
Definition: xmipp_error.h:174
MultidimArray< T > data
Definition: xmipp_image.h:55
T & getValue(MDLabel label)
Origin for the image in the Y axis (double)
Flip the image? (bool)
static MDRowVec emptyHeaderVec()
scaling factor for an image or volume (double)
void setValue(MDLabel label, const T &d, bool addLabel=true)
virtual bool containsLabel(MDLabel label) const =0
std::string String
Definition: xmipp_strings.h:34
transformation matrix in numpy string format or space separated (std::string)
Shift for the image in the Z axis (double)
void getTransformationMatrix(Matrix2D< double > &A, bool only_apply_shifts=false, const size_t n=0)
Origin for the image in the Z axis (double)
Shift for the image in the Y axis (double)
< Score 4 for volumes

◆ castConvertPage2Datatype() [1/3]

template<>
void Image< std::complex< double > >::castConvertPage2Datatype ( std::complex< double > *  srcPtr,
char *  page,
DataType  datatype,
size_t  pageSize,
double  min0,
double  max0,
CastWriteMode  castMode 
) const

Definition at line 227 of file xmipp_image.cpp.

229 {
230 
231  switch (datatype)
232  {
233  case DT_CFloat:
234  {
235  std::complex<float> * ptr = (std::complex<float> *) page;
236  for(size_t i=0; i<pageSize;i++)
237  ptr[i] = (std::complex<float>)srcPtr[i];
238  }
239  break;
240  default:
241  REPORT_ERROR(ERR_TYPE_INCORRECT,formatString("ERROR: cannot cast&convert type number %d to complex<double>",datatype));
242  break;
243  }
244 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define i
DataType datatype() const
String formatString(const char *format,...)
Incorrect type received.
Definition: xmipp_error.h:190

◆ castConvertPage2Datatype() [2/3]

template<typename T>
void Image< T >::castConvertPage2Datatype ( T *  srcPtr,
char *  page,
DataType  datatype,
size_t  pageSize,
double  min0,
double  max0,
CastWriteMode  castMode = CW_CONVERT 
) const
inline

Definition at line 544 of file xmipp_image.h.

547  {
548 
549  double minF, maxF;
550  double slope;
551  size_t n;
552  DataType myTypeId = myT();
553 
554  switch (datatype)
555  {
556  case DT_UHalfByte:
557  case DT_UChar:
558  {
559  if (castMode == CW_CONVERT && myTypeId == DT_SChar)
560  {
561  slope = 1;
562  min0 -= CHAR_MIN;
563  }
564  else if (castMode == CW_CAST)
565  {
566  minF = 0;
567  min0 = 0;
568  slope = 1;
569  }
570  else
571  {
572  minF = 0;
573  maxF = UCHAR_MAX;
574  if (max0 != min0)
575  slope = static_cast<double>(maxF - minF)
576  / static_cast<double>(max0 - min0);
577  else
578  slope = 0;
579  }
580  unsigned char * ptr = (unsigned char *) page;
581 
582  for (n = 0; n < pageSize; n++)
583  ptr[n] = static_cast<unsigned char>(minF
584  + (slope * static_cast<double>(srcPtr[n] - min0)));
585 
586  break;
587  }
588  case DT_SChar:
589  {
590  if (castMode == CW_CONVERT && myTypeId == DT_UChar)
591  {
592  slope = 1;
593  min0 += CHAR_MIN;
594  }
595  else if (castMode == CW_CAST)
596  {
597  minF = 0;
598  min0 = 0;
599  slope = 1;
600  }
601  else
602  {
603  minF = CHAR_MIN;
604  maxF = CHAR_MAX;
605  if (max0 != min0)
606  slope = static_cast<double>(maxF - minF)
607  / static_cast<double>(max0 - min0);
608  else
609  slope = 0;
610  }
611  char * ptr = (char *) page;
612 
613  for (n = 0; n < pageSize; n++)
614  ptr[n] = static_cast<char>(minF
615  + (slope * static_cast<double>(srcPtr[n] - min0)));
616 
617  break;
618  }
619  case DT_UShort:
620  {
621  if (castMode == CW_CONVERT
622  && (myTypeId == DT_SChar || myTypeId == DT_Short))
623  {
624  slope = 1;
625  min0 -= SHRT_MIN;
626  }
627  else if (castMode == CW_CONVERT && (myTypeId == DT_UChar))
628  {
629  slope = 1;
630  }
631  else if (castMode == CW_CAST)
632  {
633  minF = 0;
634  min0 = 0;
635  slope = 1;
636  }
637  else
638  {
639  minF = 0;
640  maxF = USHRT_MAX;
641  if (max0 != min0)
642  slope = static_cast<double>(maxF - minF)
643  / static_cast<double>(max0 - min0);
644  else
645  slope = 0;
646  }
647 
648  unsigned short * ptr = (unsigned short *) page;
649 
650  for (n = 0; n < pageSize; n++)
651  ptr[n] = static_cast<unsigned short>(minF
652  + (slope * static_cast<double>(srcPtr[n] - min0)));
653 
654  break;
655  }
656  case DT_Short:
657  {
658  if (castMode == CW_CONVERT
659  && (myTypeId == DT_UChar || myTypeId == DT_UShort))
660  {
661  slope = 1;
662  min0 += SHRT_MIN;
663  }
664  else if (castMode == CW_CONVERT && (myTypeId == DT_SChar))
665  {
666  slope = 1;
667  }
668  else if (castMode == CW_CAST)
669  {
670  minF = 0;
671  min0 = 0;
672  slope = 1;
673  }
674  else
675  {
676  minF = SHRT_MIN;
677  maxF = SHRT_MAX;
678  if (max0 != min0)
679  slope = static_cast<double>(maxF - minF)
680  / static_cast<double>(max0 - min0);
681  else
682  slope = 0;
683  }
684  short * ptr = (short *) page;
685 
686  for (n = 0; n < pageSize; n++)
687  ptr[n] = static_cast<short>(minF
688  + (slope * static_cast<double>(srcPtr[n] - min0)));
689 
690  break;
691  }
692  case DT_UInt:
693  {
694  if (castMode == CW_CONVERT
695  && (myTypeId == DT_SChar || myTypeId == DT_Short
696  || myTypeId == DT_Int))
697  {
698  slope = 1;
699  min0 -= INT_MIN;
700  }
701  else if (castMode == CW_CONVERT
702  && (myTypeId == DT_UShort || myTypeId == DT_UChar))
703  {
704  slope = 1;
705  }
706  else if (castMode == CW_CAST)
707  {
708  minF = 0;
709  min0 = 0;
710  slope = 1;
711  }
712  else
713  {
714  minF = 0;
715  maxF = UINT_MAX;
716  if (max0 != min0)
717  slope = static_cast<double>(maxF - minF)
718  / static_cast<double>(max0 - min0);
719  else
720  slope = 0;
721  }
722  unsigned int * ptr = (unsigned int *) page;
723 
724  for (n = 0; n < pageSize; n++)
725  ptr[n] = static_cast<unsigned int>(minF
726  + (slope * static_cast<double>(srcPtr[n] - min0)));
727  break;
728  }
729  case DT_Int:
730  {
731  if (castMode == CW_CONVERT
732  && (myTypeId == DT_UChar || myTypeId == DT_UShort
733  || myTypeId == DT_UInt))
734  {
735  slope = 1;
736  min0 += INT_MIN;
737  }
738  else if (castMode == CW_CONVERT
739  && (myTypeId == DT_Short || myTypeId == DT_SChar))
740  {
741  slope = 1;
742  }
743  else if (castMode == CW_CAST)
744  {
745  minF = 0;
746  min0 = 0;
747  slope = 1;
748  }
749  else
750  {
751  minF = INT_MIN;
752  maxF = INT_MAX;
753  if (max0 != min0)
754  slope = static_cast<double>(maxF - minF)
755  / static_cast<double>(max0 - min0);
756  else
757  slope = 0;
758  }
759  int * ptr = (int *) page;
760 
761  for (n = 0; n < pageSize; n++)
762  ptr[n] = static_cast<int>(minF
763  + (slope * static_cast<double>(srcPtr[n] - min0)));
764  break;
765  }
766  default:
767  castPage2Datatype(srcPtr, page, datatype, pageSize);
768  }
769 
770  }
void castPage2Datatype(T *srcPtr, char *page, DataType datatype, size_t pageSize) const
Definition: xmipp_image.h:426
DataType
DataType datatype() const
int * n

◆ castConvertPage2Datatype() [3/3]

template<>
void Image< std::complex< double > >::castConvertPage2Datatype ( std::complex< double > *  srcPtr,
char *  page,
DataType  datatype,
size_t  pageSize,
double  min0,
double  max0,
CastWriteMode  castMode 
) const

◆ castPage2Datatype() [1/3]

template<>
void Image< std::complex< double > >::castPage2Datatype ( std::complex< double > *  srcPtr,
char *  page,
DataType  datatype,
size_t  pageSize 
) const

Definition at line 181 of file xmipp_image.cpp.

185 {
186  switch (datatype)
187  {
188  case DT_CShort:
189  {
190  short * ptr = (short *) page;
191  double * srcPtrd = (double *)srcPtr;
192  for(size_t i=0; i<pageSize;i++)
193  {
194  *ptr=(short) *srcPtrd; ptr++; srcPtrd++;
195  *ptr=(short) *srcPtrd; ptr++; srcPtrd++;
196  }
197  }
198  break;
199  case DT_CInt:
200  {
201  int * ptr = (int *) page;
202  double * srcPtrd = (double *)srcPtr;
203  for(size_t i=0; i<pageSize;i++)
204  {
205  *ptr=(int) *srcPtrd; ptr++; srcPtrd++;
206  *ptr=(int) *srcPtrd; ptr++; srcPtrd++;
207  }
208  }
209  break;
210  case DT_CFloat:
211  {
212  std::complex<float> * ptr = (std::complex<float> *) page;
213  for(size_t i=0; i<pageSize;i++)
214  ptr[i] = (std::complex<float>)srcPtr[i];
215  }
216  break;
217  case DT_CDouble:
218  memcpy(page, srcPtr, pageSize*sizeof(std::complex<double>));
219  break;
220  default:
221  REPORT_ERROR(ERR_TYPE_INCORRECT,formatString("ERROR: cannot cast type number %d to complex<double>",datatype));
222  break;
223  }
224 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define i
DataType datatype() const
String formatString(const char *format,...)
Incorrect type received.
Definition: xmipp_error.h:190

◆ castPage2Datatype() [2/3]

template<typename T>
void Image< T >::castPage2Datatype ( T *  srcPtr,
char *  page,
DataType  datatype,
size_t  pageSize 
) const
inline

Cast page from T to datatype input pointer char *

Definition at line 426 of file xmipp_image.h.

428  {
429  switch (datatype)
430  {
431  case DT_Float:
432  {
433  if (typeid(T) == typeid(float))
434  {
435  memcpy(page, srcPtr, pageSize * sizeof(T));
436  }
437  else
438  {
439  auto* ptr = (float *) page;
440  for (size_t i = 0; i < pageSize; ++i, ++ptr)
441  *ptr = (float) srcPtr[i];
442  }
443  break;
444  }
445  case DT_Double:
446  {
447  if (typeid(T) == typeid(double))
448  {
449  memcpy(page, srcPtr, pageSize * sizeof(T));
450  }
451  else
452  {
453  auto* ptr = (double *) page;
454  for (size_t i = 0; i < pageSize; ++i, ++ptr)
455  *ptr = (double) srcPtr[i];
456  }
457  break;
458  }
459  case DT_UShort:
460  {
461  if (typeid(T) == typeid(unsigned short))
462  {
463  memcpy(page, srcPtr, pageSize * sizeof(T));
464  }
465  else
466  {
467  auto* ptr = (unsigned short *) page;
468  for (size_t i = 0; i < pageSize; ++i, ++ptr)
469  *ptr = (unsigned short) srcPtr[i];
470  }
471  break;
472  }
473  case DT_Short:
474  {
475  if (typeid(T) == typeid(short))
476  {
477  memcpy(page, srcPtr, pageSize * sizeof(T));
478  }
479  else
480  {
481  auto* ptr = (short *) page;
482  for (size_t i = 0; i < pageSize; ++i, ++ptr)
483  *ptr = (short) srcPtr[i];
484  }
485  break;
486  }
487  case DT_UHalfByte:
488  case DT_UChar:
489  {
490  if (typeid(T) == typeid(unsigned char))
491  {
492  memcpy(page, srcPtr, pageSize * sizeof(T));
493  }
494  else
495  {
496  auto* ptr = (unsigned char *) page;
497  for (size_t i = 0; i < pageSize; ++i, ++ptr)
498  *ptr = (unsigned char) srcPtr[i];
499  }
500  break;
501  }
502  case DT_SChar:
503  {
504  if (typeid(T) == typeid(char))
505  {
506  memcpy(page, srcPtr, pageSize * sizeof(T));
507  }
508  else
509  {
510  auto* ptr = (char *) page;
511  for (size_t i = 0; i < pageSize; ++i, ++ptr)
512  *ptr = (char) srcPtr[i];
513  }
514  break;
515  }
516  case DT_HalfFloat:
517  {
518  if (typeid(T) == typeid(half_float::half))
519  {
520  memcpy(page, srcPtr, pageSize * sizeof(T));
521  }
522  else
523  {
524  auto* ptr = (half_float::half *) page;
525  for (size_t i = 0; i < pageSize; ++i, ++ptr)
526  *ptr = (half_float::half) srcPtr[i];
527  }
528  break;
529  }
530  default:
531  {
532  std::cerr << "outputDatatype = " << datatype << std::endl;
534  " ERROR: cannot cast T to outputDatatype");
535  }
536  }
537  }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define i
DataType datatype() const
Incorrect type received.
Definition: xmipp_error.h:190

◆ castPage2Datatype() [3/3]

template<>
void Image< std::complex< double > >::castPage2Datatype ( std::complex< double > *  srcPtr,
char *  page,
DataType  datatype,
size_t  pageSize 
) const

◆ castPage2T() [1/3]

template<>
void Image< std::complex< double > >::castPage2T ( char *  page,
std::complex< double > *  ptrDest,
DataType  datatype,
size_t  pageSize 
)

Definition at line 141 of file xmipp_image.cpp.

145 {
146 
147  switch (datatype)
148  {
149  case DT_CShort:
150  {
151  std::complex<short> * ptr = (std::complex<short> *) page;
152  for(size_t i=0; i<pageSize;i++)
153  ptrDest[i]= std::complex<double> (real(ptr[i]),imag(ptr[i]));
154  }
155  break;
156  case DT_CInt:
157  {
158  std::complex<int> * ptr = (std::complex<int> *) page;
159  for(size_t i=0; i<pageSize;i++)
160  ptrDest[i]= std::complex<double> (real(ptr[i]),imag(ptr[i]));
161  }
162  break;
163  case DT_CFloat:
164  {
165  std::complex<float> * ptr = (std::complex<float> *) page;
166  for(size_t i=0; i<pageSize;i++)
167  ptrDest[i]= std::complex<double> (real(ptr[i]),imag(ptr[i]));
168  }
169  break;
170  case DT_CDouble:
171  memcpy(ptrDest, page, pageSize*sizeof(std::complex<double>));
172  break;
173  default:
174  std::cerr<<"Datatype= "<<datatype<<std::endl;
175  REPORT_ERROR(ERR_TYPE_INCORRECT," ERROR: cannot cast datatype to std::complex<double>");
176  break;
177  }
178 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define i
DataType datatype() const
Incorrect type received.
Definition: xmipp_error.h:190

◆ castPage2T() [2/3]

template<typename T>
void Image< T >::castPage2T ( char *  page,
T *  ptrDest,
DataType  datatype,
size_t  pageSize 
)
inline

Cast a page of data from type dataType to type Tdest input pointer char *

Definition at line 268 of file xmipp_image.h.

269  {
270  switch (datatype)
271  {
272  case DT_Unknown:
273  REPORT_ERROR(ERR_TYPE_INCORRECT, "ERROR: datatype is Unknown_Type");
274  case DT_UHalfByte:
275  case DT_UChar:
276  {
277  if (typeid(T) == typeid(unsigned char))
278  memcpy(ptrDest, page, pageSize * sizeof(T));
279  else
280  {
281  const auto* ptr = (unsigned char *) page;
282  for (size_t i = 0; i < pageSize; ++i, ++ptr)
283  ptrDest[i] = (T) *ptr;
284  }
285  break;
286  }
287  case DT_SChar:
288  {
289  if (typeid(T) == typeid(signed char))
290  {
291  memcpy(ptrDest, page, pageSize * sizeof(T));
292  }
293  else
294  {
295  const auto* ptr = (signed char *) page;
296  for (size_t i = 0; i < pageSize; ++i, ++ptr)
297  ptrDest[i] = (T) *ptr;
298  }
299  break;
300  }
301  case DT_UShort:
302  {
303  if (typeid(T) == typeid(unsigned short))
304  {
305  memcpy(ptrDest, page, pageSize * sizeof(T));
306  }
307  else
308  {
309  const auto* ptr = (unsigned short *) page;
310  for (size_t i = 0; i < pageSize; ++i, ++ptr)
311  ptrDest[i] = (T) *ptr;
312  }
313  break;
314  }
315  case DT_Short:
316  {
317  if (typeid(T) == typeid(short))
318  {
319  memcpy(ptrDest, page, pageSize * sizeof(T));
320  }
321  else
322  {
323  const auto* ptr = (short *) page;
324  for (size_t i = 0; i < pageSize; ++i, ++ptr)
325  ptrDest[i] = (T) *ptr;
326  }
327  break;
328  }
329  case DT_UInt:
330  {
331  if (typeid(T) == typeid(unsigned int))
332  {
333  memcpy(ptrDest, page, pageSize * sizeof(T));
334  }
335  else
336  {
337  const auto* ptr = (unsigned int *) page;
338  for (size_t i = 0; i < pageSize; ++i, ++ptr)
339  ptrDest[i] = (T) *ptr;
340  }
341  break;
342  }
343  case DT_Int:
344  {
345  if (typeid(T) == typeid(int))
346  {
347  memcpy(ptrDest, page, pageSize * sizeof(T));
348  }
349  else
350  {
351  const auto* ptr = (int *) page;
352  for (size_t i = 0; i < pageSize; ++i, ++ptr)
353  ptrDest[i] = (T) *ptr;
354  }
355  break;
356  }
357  case DT_Long:
358  {
359  if (typeid(T) == typeid(long))
360  {
361  memcpy(ptrDest, page, pageSize * sizeof(T));
362  }
363  else
364  {
365  const auto* ptr = (long *) page;
366  for (size_t i = 0; i < pageSize; ++i, ++ptr)
367  ptrDest[i] = (T) *ptr;
368  }
369  break;
370  }
371  case DT_Float:
372  {
373  if (typeid(T) == typeid(float))
374  {
375  memcpy(ptrDest, page, pageSize * sizeof(T));
376  }
377  else
378  {
379  const auto* ptr = (float *) page;
380  for (size_t i = 0; i < pageSize; ++i, ++ptr)
381  ptrDest[i] = (T) *ptr;
382  }
383  break;
384  }
385  case DT_Double:
386  {
387  if (typeid(T) == typeid(double))
388  {
389  memcpy(ptrDest, page, pageSize * sizeof(T));
390  }
391  else
392  {
393  const auto* ptr = (double *) page;
394  for (size_t i = 0; i < pageSize; ++i, ++ptr)
395  ptrDest[i] = (T) *ptr;
396  }
397  break;
398  }
399  case DT_HalfFloat:
400  {
401  if (typeid(T) == typeid(half_float::half))
402  {
403  memcpy(ptrDest, page, pageSize * sizeof(T));
404  }
405  else
406  {
407  const auto* ptr = (half_float::half *) page;
408  for (size_t i = 0; i < pageSize; ++i, ++ptr)
409  ptrDest[i] = (T) *ptr;
410  }
411  break;
412  }
413  default:
414  {
415  std::cerr << "Datatype= " << datatype << std::endl;
416  REPORT_ERROR(ERR_TYPE_INCORRECT, " ERROR: cannot cast datatype to T");
417  }
418  }
419 
420  }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define i
DataType datatype() const
Incorrect type received.
Definition: xmipp_error.h:190

◆ castPage2T() [3/3]

template<>
void Image< std::complex< double > >::castPage2T ( char *  page,
std::complex< double > *  ptrDest,
DataType  datatype,
size_t  pageSize 
)

◆ checkMmapT()

template<typename T>
bool Image< T >::checkMmapT ( DataType  datatype)
inlineoverridevirtual

Check if file Datatype is the same as the declared image object (T type) to use mmap.

Implements ImageBase.

Definition at line 797 of file xmipp_image.h.

798  {
799 
800  switch (datatype)
801  {
802  case DT_Unknown:
803  REPORT_ERROR(ERR_TYPE_INCORRECT, "ERROR: datatype is Unknown_Type");
804  case DT_UHalfByte:
805  return 0;
806  case DT_UChar:
807  return typeid(T) == typeid(unsigned char);
808  case DT_SChar:
809  return typeid(T) == typeid(char);
810  case DT_UShort:
811  return typeid(T) == typeid(unsigned short);
812  case DT_Short:
813  return typeid(T) == typeid(short);
814  case DT_UInt:
815  return typeid(T) == typeid(unsigned int);
816  case DT_Int:
817  return typeid(T) == typeid(int);
818  case DT_Long:
819  return typeid(T) == typeid(long);
820  case DT_Float:
821  return typeid(T) == typeid(float);
822  case DT_Double:
823  return typeid(T) == typeid(double);
824  case DT_HalfFloat:
825  return typeid(T) == typeid(half_float::half);
826  default:
827  {
828  std::cerr << "Datatype= " << datatype << std::endl;
829  REPORT_ERROR(ERR_TYPE_INCORRECT, " ERROR: cannot cast datatype to T");
830  }
831  }
832  }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
DataType datatype() const
Incorrect type received.
Definition: xmipp_error.h:190

◆ clear()

template<typename T>
void Image< T >::clear ( )
inlinevirtual

Clear. Initialize everything to 0

Implements ImageBase.

Definition at line 144 of file xmipp_image.h.

145  {
146  clearData();
147  init();
148  }
void clearData()
Definition: xmipp_image.h:156

◆ clearData()

template<typename T>
void Image< T >::clearData ( )
inline

Clear the data pointer either mapped or not. Initially fix the pointer position in case of tricking a lower number of slices and starting in a slice different from zero.

Definition at line 156 of file xmipp_image.h.

157  {
158  // If MultidimArray pointer has been moved to a slice different from zero, then reset it.
159  // This check must be done prior to mappedSize check, since mappedSlice is a trick over data pointer
160  if (virtualOffset != 0)
162  if (mmapOnRead || mmapOnWrite)
163  munmapFile();
164 
165  else
166  data.clear();
167 
168  }
size_t virtualOffset
MultidimArray< T > data
Definition: xmipp_image.h:55
void movePointerTo(int select_slice=ALL_SLICES, size_t select_img=ALL_IMAGES)
Definition: xmipp_image.h:931
#define ALL_SLICES

◆ getCastConvertPageFromT()

template<typename T>
void Image< T >::getCastConvertPageFromT ( size_t  offset,
char *  page,
DataType  datatype,
size_t  pageSize,
double  min0,
double  max0,
CastWriteMode  castMode = CW_CONVERT 
) const
inlinevirtual

Implements ImageBase.

Definition at line 786 of file xmipp_image.h.

789  {
791  pageSize, min0, max0, castMode);
792  }
#define MULTIDIM_ARRAY(v)
void castConvertPage2Datatype(T *srcPtr, char *page, DataType datatype, size_t pageSize, double min0, double max0, CastWriteMode castMode=CW_CONVERT) const
Definition: xmipp_image.h:544
MultidimArray< T > data
Definition: xmipp_image.h:55
DataType datatype() const

◆ getInverseAxisOrder()

template<typename T>
void Image< T >::getInverseAxisOrder ( const std::array< int, 4 > &  order,
std::array< int, 4 > &  result 
)
inline

Obtain the inverse axis mapping

Definition at line 184 of file xmipp_image.h.

186  {
187  for (size_t i = 0; i < result.size(); ++i)
188  {
189  size_t j = 0;
190  while(j < order.size() && order[j] != i) ++j; // Find inverse mapping
191  if (j >= order.size())
192  REPORT_ERROR(ERR_LOGIC_ERROR, "Invalid axis mapping");
193 
194  result[i] = j;
195  }
196  }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define i
#define j
Some logical error in the pipeline.
Definition: xmipp_error.h:147

◆ getPageFromT()

template<typename T>
void Image< T >::getPageFromT ( size_t  offset,
char *  page,
DataType  datatype,
size_t  pageSize 
)
inlinevirtual

Implements ImageBase.

Definition at line 779 of file xmipp_image.h.

780  {
782  pageSize);
783  }
#define MULTIDIM_ARRAY(v)
MultidimArray< T > data
Definition: xmipp_image.h:55
void castPage2Datatype(T *srcPtr, char *page, DataType datatype, size_t pageSize) const
Definition: xmipp_image.h:426
DataType datatype() const

◆ getPreview()

template<typename T >
void Image< T >::getPreview ( ImageBase imgBOut,
size_t  Xdim,
size_t  Ydim = 0,
int  select_slice = CENTRAL_SLICE,
size_t  select_img = FIRST_IMAGE 
)
virtual

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.

Implements ImageBase.

Definition at line 276 of file xmipp_image.cpp.

278 {
279  // Zdim is used to choose the slices: -1 = CENTRAL_SLICE, 0 = ALL_SLICES, else This Slice
280 
281  size_t Zdim;
282  ArrayDim imAdim;
283  MULTIDIM_ARRAY(*this).getDimensions(imAdim);
284  MULTIDIM_ARRAY(*this).setXmippOrigin();
285 
286  double scale;
287 
288  // If only Xdim is passed, it is the higher allowable size, for any dimension
289  if (Ydim == 0 && imAdim.xdim < imAdim.ydim)
290  {
291  Ydim = Xdim;
292  scale = ((double) Ydim) / ((double) imAdim.ydim);
293  Xdim = (int) (scale * imAdim.xdim);
294  }
295  else
296  {
297  scale = ((double) Xdim) / ((double) imAdim.xdim);
298  if (Ydim == 0)
299  Ydim = (int) (scale * imAdim.ydim);
300  }
301 
302  Image<T> &imgOut = *((Image<T>*) imgBOut);
303 
304  int mode = (scale <= 1) ? xmipp_transformation::NEAREST : xmipp_transformation::LINEAR; // If scale factor is higher than 1, LINEAR mode is used to avoid artifacts
305 
306  if (select_slice > ALL_SLICES) // In this case a specific slice number has been chosen (Not central slice)
307  {
308  movePointerTo(select_slice, select_img);
309  scaleToSize(mode, IMGMATRIX(imgOut), IMGMATRIX(*this), Xdim, Ydim);
310  }
311  else // Otherwise, All slices or Central slice is selected
312  {
313  movePointerTo(ALL_SLICES, select_img);
314  Zdim = (select_slice == ALL_SLICES) ? imAdim.zdim : 1;
315  scaleToSize(mode, IMGMATRIX(imgOut), IMGMATRIX(*this), Xdim, Ydim,
316  Zdim);
317  }
318 
319  movePointerTo();
320  IMGMATRIX(*this).resetOrigin();
321 
322  // We set the actual dimesions of th MDA to the imageOut as if it were read from file.
323  imgOut.setADimFile(IMGMATRIX(imgOut).getDimensions());
324 }
size_t xdim
#define MULTIDIM_ARRAY(v)
ArrayDim getDimensions()
#define IMGMATRIX(I)
void setADimFile(ArrayDim aDim)
size_t zdim
double scale(const size_t n=0) const
void mode
void scaleToSize(int SplineDegree, MultidimArrayGeneric &V2, const MultidimArrayGeneric &V1, int Xdim, int Ydim, int Zdim)
void movePointerTo(int select_slice=ALL_SLICES, size_t select_img=ALL_IMAGES)
Definition: xmipp_image.h:931
size_t ydim
#define ALL_SLICES

◆ getSize()

template<typename T>
size_t Image< T >::getSize ( ) const
inlinevirtual

Get Image dimensions

Implements ImageBase.

Definition at line 1091 of file xmipp_image.h.

1092  {
1093  return NZYXSIZE(data);
1094  }
MultidimArray< T > data
Definition: xmipp_image.h:55
#define NZYXSIZE(v)

◆ getTransformationMatrix()

template<typename T >
void Image< T >::getTransformationMatrix ( Matrix2D< double > &  A,
bool  only_apply_shifts = false,
const size_t  n = 0 
)
virtual

Get geometric transformation matrix from 2D-image header

Implements ImageBase.

Definition at line 266 of file xmipp_image.cpp.

268 {
269  // This has only been implemented for 2D images...
270  MULTIDIM_ARRAY(*this).checkDimension(2);
271  A.resizeNoCopy(3, 3);
272  geo2TransformationMatrix(*MD[n], A, only_apply_shifts);
273 }
void geo2TransformationMatrix(const MDRow &imageGeo, Matrix2D< double > &A, bool only_apply_shifts)
std::vector< std::unique_ptr< MDRow > > MD
#define MULTIDIM_ARRAY(v)
void resizeNoCopy(int Ydim, int Xdim)
Definition: matrix2d.h:534
int * n

◆ isComplexT()

template<typename T>
bool Image< T >::isComplexT ( ) const
inlinevirtual

Check whether image is complex based on T

Implements ImageBase.

Definition at line 173 of file xmipp_image.h.

174  {
175  return (typeid(T) == typeid(std::complex<double>)
176  || typeid(T) == typeid(std::complex<float>));
177  }

◆ mirrorX()

template<typename T>
void Image< T >::mirrorX ( void  )
inline

flip image around Y axis

Definition at line 865 of file xmipp_image.h.

866  {
867  T aux(0);
868  size_t Z, Y, X, N, X2;
869 
870  X = XSIZE(data);
871  Y = YSIZE(data);
872  Z = ZSIZE(data);
873  N = NSIZE(data);
874  X2 = X / 2;
875  X--;
876  for (size_t l = 0; l < N; ++l)
877  for (size_t k = 0; k < Z; ++k)
878  for (size_t i = 0; i < Y; ++i)
879  for (size_t j = 0; j < X2; ++j)
880  {
881  aux = DIRECT_NZYX_ELEM(data, l, k, i, j);
883  i, X - j);
884  DIRECT_NZYX_ELEM(data, l, k, i, X - j) = aux;
885  }
886  }
#define NSIZE(v)
#define YSIZE(v)
#define DIRECT_NZYX_ELEM(v, l, k, i, j)
#define i
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
MultidimArray< T > data
Definition: xmipp_image.h:55
#define XSIZE(v)
#define ZSIZE(v)
#define j

◆ mirrorY()

template<typename T>
void Image< T >::mirrorY ( void  )
inlinevirtual

flip image around X axis

Implements ImageBase.

Definition at line 838 of file xmipp_image.h.

839  {
840  T aux(0);
841  size_t Z, Y, X, N, Y2;
842 
843  X = XSIZE(data);
844  Y = YSIZE(data);
845  Z = ZSIZE(data);
846  N = NSIZE(data);
847  Y2 = Y / 2;
848  Y--;
849  for (size_t l = 0; l < N; ++l)
850  for (size_t k = 0; k < Z; ++k)
851  for (size_t i = 0; i < Y2; ++i)
852  for (size_t j = 0; j < X; ++j)
853  {
854  aux = DIRECT_NZYX_ELEM(data, l, k, i, j);
856  Y - i, j);
857  DIRECT_NZYX_ELEM(data, l, k, Y-i, j) = aux;
858  }
859  }
#define NSIZE(v)
#define YSIZE(v)
#define DIRECT_NZYX_ELEM(v, l, k, i, j)
#define i
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
MultidimArray< T > data
Definition: xmipp_image.h:55
#define XSIZE(v)
#define ZSIZE(v)
#define j

◆ movePointerTo()

template<typename T>
void Image< T >::movePointerTo ( int  select_slice = ALL_SLICES,
size_t  select_img = ALL_IMAGES 
)
inlinevirtual

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.

Implements ImageBase.

Definition at line 931 of file xmipp_image.h.

932  {
933  if (MULTIDIM_ARRAY(VOLMATRIX(*this)) == NULL)
935  "Image::movePointerTo: Image is empty");
936  if (select_slice > (int) aDimFile.zdim)
938  formatString(
939  "movePointerTo: Selected slice %4d cannot be higher than Z size %4d.",
940  select_slice, aDimFile.zdim));
941  else if (select_img > aDimFile.ndim)
943  formatString(
944  "movePointerTo: Selected image %4d cannot be higher than N size %4d.",
945  select_img, aDimFile.ndim));
946 
947  ArrayDim newDim;
948  VOLMATRIX(*this).getDimensions(newDim);
949 
950  /* Restore the real dimensions from the MDA, as it may be
951  * X-Y dimensioned different from file (readPreview). */
952  newDim.zdim = aDimFile.zdim;
953  newDim.ndim = aDimFile.ndim;
954 
955  int phys_slice;
956 
957  switch (select_slice)
958  {
959  case CENTRAL_SLICE:
960  phys_slice = aDimFile.zdim / 2;
961  newDim.zdim = 1;
962  break;
963  case ALL_SLICES:
964  phys_slice = 0;
965  break;
966  default:
967  phys_slice = select_slice - 1;
968  newDim.zdim = 1;
969  break;
970  }
971 
972  /* If we select a single slice, we are forced to chose also an image.
973  * as at this moment we cannot select the same slice from different images at a time.
974  */
975  if (select_slice > 0 && select_img == ALL_IMAGES)
976  select_img = FIRST_IMAGE;
977  if (select_img > ALL_IMAGES)
978  newDim.ndim = 1;
979 
980  VOLMATRIX(*this).setDimensions(newDim);
981 
982  size_t newVirtualOffset = YXSIZE(VOLMATRIX(*this))
983  * (aDimFile.zdim * IMG_INDEX(select_img) + phys_slice);
984  MULTIDIM_ARRAY(VOLMATRIX(*this)) += (newVirtualOffset - virtualOffset);
985  virtualOffset = newVirtualOffset;
986  }
MultidimArray is empty.
Definition: xmipp_error.h:175
ArrayDim aDimFile
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define VOLMATRIX(V)
#define MULTIDIM_ARRAY(v)
Incorrect MultidimArray size.
Definition: xmipp_error.h:174
size_t virtualOffset
size_t zdim
#define CENTRAL_SLICE
size_t ndim
#define ALL_IMAGES
String formatString(const char *format,...)
#define IMG_INDEX(select_img)
#define FIRST_IMAGE
#define YXSIZE(v)
#define ALL_SLICES

◆ operator()() [1/4]

template<typename T>
MultidimArray<T>& Image< T >::operator() ( )
inline

Data access

This operator can be used to access the data multidimarray. In this way we could resize an image just by resizing its associated matrix or we could add two images by adding their matrices.

I().resize(128, 128);
I2() = I1() + I2();

Definition at line 1025 of file xmipp_image.h.

1026  {
1027  return data;
1028  }
MultidimArray< T > data
Definition: xmipp_image.h:55

◆ operator()() [2/4]

template<typename T>
const MultidimArray<T>& Image< T >::operator() ( ) const
inline

Definition at line 1030 of file xmipp_image.h.

1031  {
1032  return data;
1033  }
MultidimArray< T > data
Definition: xmipp_image.h:55

◆ operator()() [3/4]

template<typename T>
T& Image< T >::operator() ( int  i,
int  j 
) const
inline

Pixel access

This operator is used to access a pixel within a 2D image. This is a logical access, so you could access to negative positions if the image has been defined so (see the general explanation for the class).

std::cout << "Grey level of pixel (-3,-3) of the image = " << I(-3, -3)
<< std::endl;
I(-3, -3) = I(-3, -2);

Definition at line 1049 of file xmipp_image.h.

1050  {
1051  return A2D_ELEM(data, i, j);
1052  }
#define A2D_ELEM(v, i, j)
#define i
MultidimArray< T > data
Definition: xmipp_image.h:55
#define j

◆ operator()() [4/4]

template<typename T>
T& Image< T >::operator() ( int  k,
int  i,
int  j 
) const
inline

Voxel access

This operator is used to access a voxel within a 3D image. This is a logical access, so you could access to negative positions if the image has been defined so (see the general explanation for the class).

std::cout << "Grey level of pixel (-3,-3, 1) of the volume = " << I(-3, -3, 1)
<< std::endl;
I(-3, -3, 1) = I(-3, -2, 0);

Definition at line 1076 of file xmipp_image.h.

1077  {
1078  return A3D_ELEM(data, k, i, j);
1079  }
#define i
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
#define A3D_ELEM(V, k, i, j)
MultidimArray< T > data
Definition: xmipp_image.h:55
#define j

◆ operator=()

template<typename T>
Image<T>& Image< T >::operator= ( const Image< T > &  op1)
inline

Copy the MDA and the fields related to the (possible) original file

Definition at line 1006 of file xmipp_image.h.

1007  {
1008  this->copy(op1);
1009  data = op1.data;
1010  return *this;
1011  }
MultidimArray< T > data
Definition: xmipp_image.h:55
void copy(const ImageBase &other)

◆ operator==()

template<typename T>
bool Image< T >::operator== ( const Image< T > &  i1) const
inline

equal operator

Definition at line 1057 of file xmipp_image.h.

1058  {
1059  return (this->data == i1.data);
1060  }
MultidimArray< T > data
Definition: xmipp_image.h:55

◆ readPreview()

template<typename T >
int Image< T >::readPreview ( const FileName name,
size_t  Xdim,
size_t  Ydim = 0,
int  select_slice = CENTRAL_SLICE,
size_t  select_img = FIRST_IMAGE 
)
virtual

Implements ImageBase.

Definition at line 38 of file xmipp_image.cpp.

40 {
41  // Zdim is used to choose the slices: -1 = CENTRAL_SLICE, 0 = ALL_SLICES, else This Slice
42 
43  ImageGeneric im;
44  size_t imXdim, imYdim, imZdim, Zdim;
45  int err;
46  err = im.readMapped(name, select_img);
47  im.getDimensions(imXdim, imYdim, imZdim);
48  ImageInfo imgInfo;
49  im.getInfo(imgInfo);
50 
51  //Set information from image file
52  setName(name);
53  setDatatype(imgInfo.datatype);
54  aDimFile = imgInfo.adim;
55 
56  im().setXmippOrigin();
57 
58  double scale;
59 
60  // If only Xdim is passed, it is the higher allowable size, for any dimension
61  if (Ydim == 0 && imXdim < imYdim)
62  {
63  Ydim = Xdim;
64  scale = ((double) Ydim) / ((double) imYdim);
65  Xdim = (int) (scale * imXdim);
66  }
67  else
68  {
69  scale = ((double) Xdim) / ((double) imXdim);
70  if (Ydim == 0)
71  Ydim = (int) (scale * imYdim);
72  }
73 
74  int mode = (scale <= 1) ? xmipp_transformation::NEAREST : xmipp_transformation::LINEAR; // If scale factor is higher than 1, LINEAR mode is used to avoid artifacts
75 
76  if (select_slice > ALL_SLICES) // In this case a specific slice number has been chosen (Not central slice)
77  {
78  MultidimArrayGeneric array(im(), select_slice - 1);
79  array.setXmippOrigin();
80 
81  scaleToSize(mode, IMGMATRIX(*this), array, Xdim, Ydim);
82  }
83  else // Otherwise, All slices or Central slice is selected
84  {
85  Zdim = (select_slice == ALL_SLICES) ? imZdim : 1;
86  scaleToSize(mode, IMGMATRIX(*this), im(), Xdim, Ydim, Zdim);
87  }
88 
89  IMGMATRIX(*this).resetOrigin();
90  return err;
91 }
ArrayDim aDimFile
void setDatatype(DataType datatype)
#define IMGMATRIX(I)
void getDimensions(size_t &Xdim, size_t &Ydim, size_t &Zdim, size_t &Ndim) const
void getInfo(ImageInfo &imgInfo) const
double scale(const size_t n=0) const
ArrayDim adim
void mode
void scaleToSize(int SplineDegree, MultidimArrayGeneric &V2, const MultidimArrayGeneric &V1, int Xdim, int Ydim, int Zdim)
void setName(const FileName &_filename)
DataType datatype
#define ALL_SLICES
int readMapped(const FileName &name, size_t select_img=ALL_IMAGES, int mode=WRITE_READONLY)

◆ selfApplyGeometry()

template<typename T >
void Image< T >::selfApplyGeometry ( int  SplineDegree,
bool  wrap = xmipp_transformation::WRAP,
bool  only_apply_shifts = false 
)
virtual

Internal apply geometrical transformations

Implements ImageBase.

Definition at line 247 of file xmipp_image.cpp.

249 {
250  //apply geo has not been defined for volumes
251  //and only make sense when reading data
252  if (data.getDim() < 3 && dataMode >= DATA)
253  {
255  getTransformationMatrix(A, only_apply_shifts);
256  if (!A.isIdentity())
257  {
258  MultidimArray<T> tmp = MULTIDIM_ARRAY(*this);
259  applyGeometry(SplineDegree, MULTIDIM_ARRAY(*this), tmp, A, xmipp_transformation::IS_NOT_INV,
260  wrap);
261  }
262  }
263 }
bool isIdentity() const
Definition: matrix2d.cpp:1323
DataMode dataMode
void applyGeometry(int SplineDegree, MultidimArray< std::complex< double > > &V2, const MultidimArray< std::complex< double > > &V1, const Matrix2D< double > &A, bool inv, bool wrap, std::complex< double > outside, MultidimArray< double > *BcoeffsPtr)
#define MULTIDIM_ARRAY(v)
MultidimArray< T > data
Definition: xmipp_image.h:55
void getTransformationMatrix(Matrix2D< double > &A, bool only_apply_shifts=false, const size_t n=0)

◆ setDimensions()

template<typename T>
void Image< T >::setDimensions ( int  Xdim,
int  Ydim,
int  Zdim,
size_t  Ndim 
)
inlineprotectedvirtual

Set the image dimensions

Implements ImageBase.

Definition at line 1127 of file xmipp_image.h.

1128  {
1129  data.setDimensions(Xdim, Ydim, Zdim, Ndim);
1130  data.getDimensions(aDimFile);
1131  }
ArrayDim aDimFile
MultidimArray< T > data
Definition: xmipp_image.h:55

◆ setPage2T()

template<typename T>
void Image< T >::setPage2T ( size_t  offset,
char *  page,
DataType  datatype,
size_t  pageSize 
)
inlinevirtual

Implements ImageBase.

Definition at line 773 of file xmipp_image.h.

774  {
775  castPage2T(page, MULTIDIM_ARRAY(data) + offset, datatype, pageSize);
776  }
#define MULTIDIM_ARRAY(v)
MultidimArray< T > data
Definition: xmipp_image.h:55
void castPage2T(char *page, T *ptrDest, DataType datatype, size_t pageSize)
Definition: xmipp_image.h:268
DataType datatype() const

◆ sumWithFile()

template<typename T>
void Image< T >::sumWithFile ( const FileName fn)
inlinevirtual

Sum this object with other file and keep in this object

Implements ImageBase.

Definition at line 1105 of file xmipp_image.h.

1106  {
1107  Image<T> aux;
1108  aux.read(fn, DATA, ALL_IMAGES, true);
1109  (*this)() += aux();
1110  }
#define ALL_IMAGES
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)

◆ transposeAxisSizes()

template<typename T>
void Image< T >::transposeAxisSizes ( const std::array< size_t, 4 > &  sizes,
const std::array< int, 4 > &  order,
std::array< size_t, 4 > &  result 
)
inline

Trasposes the given size array according to inverseOrder

Definition at line 202 of file xmipp_image.h.

205  {
206  std::array<int, 4> inverseOrder;
207  getInverseAxisOrder(order, inverseOrder);
208 
209  result = {
210  sizes[inverseOrder[0]],
211  sizes[inverseOrder[1]],
212  sizes[inverseOrder[2]],
213  sizes[inverseOrder[3]]
214  };
215  }
void getInverseAxisOrder(const std::array< int, 4 > &order, std::array< int, 4 > &result)
Definition: xmipp_image.h:184

◆ transposeInPlace()

template<typename T>
void Image< T >::transposeInPlace ( MultidimArray< T > &  multidimArray,
const std::array< int, 4 > &  order 
)
inline

Trasposes the given MultidimArray with the given order

Definition at line 221 of file xmipp_image.h.

222  {
223  std::array<int, 4> inverseOrder;
224  getInverseAxisOrder(order, inverseOrder);
225 
226  // Creating new multidim array of the same size than the original
227  const std::array<size_t,4> sizes = {
228  NSIZE(multidimArray),
229  ZSIZE(multidimArray),
230  YSIZE(multidimArray),
231  XSIZE(multidimArray)
232  };
233 
234  MultidimArray<T> result(
235  sizes[inverseOrder[0]],
236  sizes[inverseOrder[1]],
237  sizes[inverseOrder[2]],
238  sizes[inverseOrder[3]]
239  );
240 
241  // Performing transposition in a loop for every dimension
242  for (size_t n = 0; n < NSIZE(multidimArray); n++) {
243  for (size_t z = 0; z < ZSIZE(multidimArray); z++) {
244  for (size_t y = 0; y < YSIZE(multidimArray); y++) {
245  for (size_t x = 0; x < XSIZE(multidimArray); x++) {
246  // Defining array to access with the axis orders
247  const std::array<size_t,4> indices = {n, z, y, x};
248  const auto l = indices[inverseOrder[0]];
249  const auto k = indices[inverseOrder[1]];
250  const auto i = indices[inverseOrder[2]];
251  const auto j = indices[inverseOrder[3]];
252 
253  // Transposing element
254  DIRECT_NZYX_ELEM(result, l, k, i, j) = DIRECT_NZYX_ELEM(multidimArray, n, z, y, x);
255  }
256  }
257  }
258  }
259 
260  // Remapping pointers from original multidim array to transposed one
261  multidimArray = std::move(result);
262  }
#define NSIZE(v)
#define YSIZE(v)
#define DIRECT_NZYX_ELEM(v, l, k, i, j)
static double * y
doublereal * x
#define i
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
void getInverseAxisOrder(const std::array< int, 4 > &order, std::array< int, 4 > &result)
Definition: xmipp_image.h:184
#define XSIZE(v)
#define ZSIZE(v)
double z
#define j
int * n

◆ writePageAsDatatype()

template<typename T>
void Image< T >::writePageAsDatatype ( FILE *  fimg,
DataType  datatype,
size_t  datasize_n 
)
inlinevirtual

Write an entire page as datatype

A page of datasize_n elements T is cast to datatype and written to fimg The memory for the casted page is allocated and freed internally.

Implements ImageBase.

Definition at line 994 of file xmipp_image.h.

995  {
996  size_t datasize = datasize_n * gettypesize(datatype);
997  char * fdata = (char *) askMemory(datasize);
998  castPage2Datatype(MULTIDIM_ARRAY(data), fdata, datatype, datasize_n);
999  fwrite(fdata, datasize, 1, fimg);
1000  freeMemory(fdata, datasize);
1001  }
#define MULTIDIM_ARRAY(v)
MultidimArray< T > data
Definition: xmipp_image.h:55
int freeMemory(void *ptr, size_t memsize)
void castPage2Datatype(T *srcPtr, char *page, DataType datatype, size_t pageSize) const
Definition: xmipp_image.h:426
char * askMemory(size_t memsize)
DataType datatype() const
size_t gettypesize(DataType type)
Returns memory size of datatype.

Friends And Related Function Documentation

◆ Image

template<typename T>
template<typename TT >
friend class Image
friend

Definition at line 1550 of file xmipp_image.h.

◆ ImageCollection

template<typename T>
friend class ImageCollection
friend

Definition at line 1548 of file xmipp_image.h.

Member Data Documentation

◆ data

template<typename T>
MultidimArray<T> Image< T >::data

Definition at line 55 of file xmipp_image.h.


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