Xmipp  v3.23.11-Nereus
Classes | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
ImageBase Class Referenceabstract

Image base class. More...

#include <xmipp_image_base.h>

Inheritance diagram for ImageBase:
Inheritance graph
[legend]
Collaboration diagram for ImageBase:
Collaboration graph
[legend]

Classes

struct  EMHead
 
struct  PIFDataHeader
 
struct  PIFMainHeader
 
struct  SPIDERhead
 
struct  TIFFDirHead
 

Public Member Functions

void init ()
 
void copy (const ImageBase &other)
 
virtual void clear ()=0
 
void clearHeader ()
 
virtual bool isComplexT () const =0
 
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)
 
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
 
virtual void getPreview (ImageBase *imgOut, size_t Xdim, size_t Ydim=0, int select_slice=CENTRAL_SLICE, size_t select_img=FIRST_IMAGE)=0
 
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)
 
virtual void movePointerTo (int select_slice=ALL_SLICES, size_t select_img=ALL_IMAGES)=0
 
virtual DataType myT () const =0
 
virtual bool checkMmapT (DataType datatype)=0
 
virtual void writePageAsDatatype (FILE *fimg, DataType datatype, size_t datasize_n)=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)
 
virtual size_t getSize () const =0
 
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
 
virtual void setDimensions (int Xdim, int Ydim, int Zdim, size_t Ndim)=0
 
virtual void setDimensions (ArrayDim &aDim)
 
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)
 
virtual void getTransformationMatrix (Matrix2D< double > &A, bool only_apply_shifts=false, const size_t n=0)=0
 
virtual void sumWithFile (const FileName &fn)=0
 
virtual void mirrorY ()=0
 
virtual void selfApplyGeometry (int SplineDegree, bool wrap, bool only_apply_shifts)=0
 

Public Attributes

MultidimArrayBasemdaBase
 
std::vector< std::unique_ptr< MDRow > > MD
 
MDRowVec MDMainHeader
 

Protected Member Functions

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
 
virtual void applyGeo (const MDRow &row, bool only_apply_shifts=false, bool wrap=xmipp_transformation::WRAP)=0
 
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)
 
virtual void readData (FILE *fimg, size_t select_img, DataType datatype, size_t pad)=0
 
virtual void readData4bit (FILE *fimg, size_t select_img, DataType datatype, size_t pad)=0
 
virtual void writeData (FILE *fimg, size_t offset, DataType wDType, size_t datasize_n, CastWriteMode castMode=CW_CAST)=0
 
virtual void setPage2T (size_t offset, char *page, DataType datatype, size_t pageSize)=0
 
virtual void getPageFromT (size_t offset, char *page, DataType datatype, size_t pageSize)=0
 
virtual void getCastConvertPageFromT (size_t offset, char *page, DataType datatype, size_t pageSize, double min0, double max0, CastWriteMode castMode=CW_CONVERT) const =0
 
virtual void mmapFile ()=0
 
virtual void munmapFile ()=0
 
void setDatatype (DataType datatype)
 

Protected Attributes

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

static constexpr std::array< int, 4 > defaultAxisOrder = {0,1,2,3}
 

Friends

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

Detailed Description

Image base class.

Definition at line 238 of file xmipp_image_base.h.

Constructor & Destructor Documentation

◆ ~ImageBase()

ImageBase::~ImageBase ( )
virtual

Destructor.

Definition at line 1205 of file xmipp_image_base.cpp.

1206 {
1207  delete m_auxI;
1208 }

Member Function Documentation

◆ _read()

int ImageBase::_read ( const FileName name,
ImageFHandler hFile,
DataMode  datamode = DATA,
size_t  select_img = ALL_IMAGES,
bool  mapData = false 
)
protected

Internal read image file method.

Definition at line 792 of file xmipp_image_base.cpp.

794 {
795  // Temporary Error to find old select_img == -1
796  if (select_img == (size_t) -1)
797  REPORT_ERROR(ERR_DEBUG_TEST, "To select all images use ALL_IMAGES macro, or FIRST_IMAGE macro.");
798 
799  int err = 0;
800  dataMode = datamode;
801 
802  // If MultidimArray pointer has been moved to a slice/image different from zero, then reset it.
803  // This check must be done prior to mappedSize check, since mappedSlice is a trick over data pointer
804  if ( virtualOffset != 0)
806  // If Image has been previously used with mmap, then close the previous file
807  if (mappedSize != 0)
808  munmapFile();
809 
810  // Check whether to map the data or not
811 #ifdef XMIPP_MMAP
812 
813  mmapOnRead = mapData;
814 #endif
815 
816  const auto &ext_name = hFile->ext_name;
817  fimg = hFile->fimg;
818  fhed = hFile->fhed;
819  tif = hFile->tif;
820  fhdf5 = hFile->fhdf5;
821 
822  size_t image_num = name.getPrefixNumber();
823  filename = name;
824  dataFName = hFile->fileName;
825 
826  if (image_num != ALL_IMAGES)
827  select_img = image_num;
828 
829 #undef DEBUG
830  // #define DEBUG
831 #ifdef DEBUG
832 
833  std::cerr << "READ\n" <<
834  "name="<<name <<std::endl;
835  std::cerr << "ext= "<<ext_name <<std::endl;
836  std::cerr << " now reading: "<< filename <<" dataflag= "<<dataMode
837  << " select_img " << select_img << ", image_num = " << image_num << std::endl;
838 #endif
839 #undef DEBUG
840 
841  // Defining default axis order (will be overwritten by data types that need it)
843 
844  //Just clear the header before reading
846  //Set the file pointer at beginning
847  if (fimg != NULL)
848  fseek(fimg, 0, SEEK_SET);
849  if (fhed != NULL)
850  fseek(fhed, 0, SEEK_SET);
851 
852  if (ext_name.contains("spi") || ext_name.contains("xmp") ||
853  ext_name.contains("stk") || ext_name.contains("vol"))
854  err = readSPIDER(select_img);
855  else if (isMRCStack(ext_name)) //mrc stack MUST go BEFORE plain MRC
856  err = readMRC(select_img,true);
857  else if (isMRCImageOrVolume(ext_name)) //mrc
858  err = readMRC(select_img,false);
859  else if (ext_name.contains("eer"))//EER
860  err = readEER(select_img);
861  else if (ext_name.contains("img") || ext_name.contains("hed"))//
862  err = readIMAGIC(select_img);//imagic is always an stack
863  else if (ext_name.contains("ser"))//TIA
864  err = readTIA(select_img,false);
865  else if (ext_name.contains("dm3"))//DM3
866  err = readDM3(select_img,false);
867  else if (ext_name.contains("dm4"))//DM4
868  err = readDM4(select_img,false);
869  else if (ext_name.contains("ems"))//EM stack
870  err = readEM(select_img, true);
871  else if (ext_name.contains("em"))//EM
872  err = readEM(select_img);
873  else if (ext_name.contains("pif"))//PIF
874  err = readPIF(select_img);
875  else if (ext_name.contains("inf"))//RAW with INF file
876  err = readINF(select_img,false);
877  else if (ext_name.contains("raw"))//RAW without INF file
878  err = readRAW(select_img,false);
879  else if (ext_name.contains("tif") || ext_name.contains("gain"))//TIFF
880  err = readTIFF(select_img,false);
881  else if (ext_name.contains("spe"))//SPE
882  err = readSPE(select_img,false);
883  else if (ext_name.contains("jpg"))//SPE
884  err = readJPEG(select_img);
885  else if (ext_name.contains("hdf") || ext_name.contains("h5"))//SPE
886  err = readHDF5(select_img);
887  else
888  err = readSPIDER(select_img);
889 
890  // Negative errors are bad.
891  return err;
892 }
virtual void munmapFile()=0
std::array< int, 4 > axisOrder
int readEM(size_t select_img, bool isStack=false)
Definition: rwEM.cpp:33
DataMode dataMode
Just an error for debugging purpose.
Definition: xmipp_error.h:119
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
FileName dataFName
int readDM3(size_t img_select, bool isStack=false)
Definition: rwDM3.cpp:445
int readSPIDER(size_t select_img)
Definition: rwSPIDER.cpp:292
int readSPE(size_t select_img, bool isStack=false)
Definition: rwSPE.cpp:38
int readIMAGIC(size_t img_select)
Definition: rwIMAGIC.cpp:127
const FileName & name() const
static constexpr std::array< int, 4 > defaultAxisOrder
size_t virtualOffset
int readTIA(int img_select, bool isStack=false)
Definition: rwTIA.cpp:79
int readMRC(size_t select_img, bool isStack=false)
Definition: rwMRC.cpp:352
int readPIF(size_t select_img)
Definition: rwPIF.cpp:33
size_t getPrefixNumber(size_t pos=0) const
int readEER(size_t select_img)
Definition: rwEER.cpp:569
int readHDF5(size_t select_img)
Definition: rwHDF5.cpp:136
virtual void movePointerTo(int select_slice=ALL_SLICES, size_t select_img=ALL_IMAGES)=0
int readJPEG(size_t select_img)
Definition: rwJPEG.cpp:34
int readTIFF(size_t select_img, bool isStack=false)
Definition: rwTIFF.cpp:134
int readINF(size_t img_select, bool isStack=false)
Definition: rwINF.cpp:39
MDRowVec MDMainHeader
size_t mappedSize
int readDM4(size_t img_select, bool isStack=false)
Definition: rwDM4.cpp:466
int readRAW(size_t select_img, bool isStack=false)
Definition: rwRAW.cpp:70
#define ALL_IMAGES
FileName filename
bool isMRCStack(const FileName &ext_name)
void clear() override
#define ALL_SLICES
bool isMRCImageOrVolume(const FileName &ext_name)

◆ _readBatch()

int ImageBase::_readBatch ( const FileName name,
ImageFHandler hFile,
size_t  start_img,
size_t  batch_size,
DataMode  datamode = DATA,
bool  mapData = false 
)
protected

Definition at line 894 of file xmipp_image_base.cpp.

896 {
897 
898  int err = 0;
899  dataMode = datamode;
900 
901  // If MultidimArray pointer has been moved to a slice/image different from zero, then reset it.
902  // This check must be done prior to mappedSize check, since mappedSlice is a trick over data pointer
903  if ( virtualOffset != 0)
905  // If Image has been previously used with mmap, then close the previous file
906  if (mappedSize != 0)
907  munmapFile();
908 
909  // Check whether to map the data or not
910 #ifdef XMIPP_MMAP
911 
912  mmapOnRead = mapData;
913 #endif
914 
915  const auto &ext_name = hFile->ext_name;
916  fimg = hFile->fimg;
917  fhed = hFile->fhed;
918  tif = hFile->tif;
919  fhdf5 = hFile->fhdf5;
920 
921  filename = name;
922  dataFName = hFile->fileName;
923 
924 
925  //Just clear the header before reading
927  //Set the file pointer at beginning
928  if (fimg != NULL)
929  fseek(fimg, 0, SEEK_SET);
930  if (fhed != NULL)
931  fseek(fhed, 0, SEEK_SET);
932 
933  if (ext_name.contains("spi") || ext_name.contains("xmp") ||
934  ext_name.contains("stk") || ext_name.contains("vol")) {
935  err = readSPIDER(start_img, batch_size);
936  } else if (isMRCStack(ext_name)) { //mrc stack MUST go BEFORE plain MRC
937  err = readMRC(start_img, batch_size, true);
938  } else if (isMRCImageOrVolume(ext_name)) {//mrc
939  err = readMRC(start_img, batch_size, false);
940  } else {
941  REPORT_ERROR(ERR_NOT_IMPLEMENTED, "Reading of a range of files is implemented only for SPIDER and MRC stack.");
942  }
943 
944  // Negative errors are bad.
945  return err;
946 }
virtual void munmapFile()=0
Case or algorithm not implemented yet.
Definition: xmipp_error.h:177
DataMode dataMode
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
FileName dataFName
int readSPIDER(size_t select_img)
Definition: rwSPIDER.cpp:292
const FileName & name() const
size_t virtualOffset
int readMRC(size_t select_img, bool isStack=false)
Definition: rwMRC.cpp:352
virtual void movePointerTo(int select_slice=ALL_SLICES, size_t select_img=ALL_IMAGES)=0
MDRowVec MDMainHeader
size_t mappedSize
FileName filename
bool isMRCStack(const FileName &ext_name)
void clear() override
#define ALL_SLICES
bool isMRCImageOrVolume(const FileName &ext_name)

◆ _write()

void ImageBase::_write ( const FileName name,
ImageFHandler hFile,
size_t  select_img = ALL_IMAGES,
bool  isStack = false,
int  mode = WRITE_OVERWRITE,
CastWriteMode  castMode = CW_CAST 
)
protected

Internal write image file method.

Datatype info must be from filename after "%" symbol

If we are going to changes all images, then swap of the file may be changed, otherwise, original swap remains.

Definition at line 950 of file xmipp_image_base.cpp.

952 {
953  // Temporary Error to find old select_img == -1
954  if (select_img == (size_t) -1)
955  REPORT_ERROR(ERR_DEBUG_TEST, "To select all images use ALL_IMAGES macro, or FIRST_IMAGE macro.");
956 
957  int err = 0;
958 
959  // if image is mapped to file then close the file and clear
960  if (mmapOnWrite && mappedSize > 0)
961  {
962  munmapFile();
963  return;
964  }
965 
966  filename = name;
967  dataFName = hFile->fileName;
968  _exists = hFile->exist;
969  fimg = hFile->fimg;
970  fhed = hFile->fhed;
971  tif = hFile->tif;
972 
973  FileName ext_name = hFile->ext_name;
974 
975  size_t aux;
976  FileName filNamePlusExt;
977  name.decompose(aux, filNamePlusExt);
978 
979  if (select_img == ALL_IMAGES)
980  select_img = aux;
981 
983  size_t found = filNamePlusExt.find_first_of("%");
984  String imParam = "";
985  if (found!=String::npos)
986  {
987  imParam = filNamePlusExt.substr(found+1).c_str();
988  filNamePlusExt = filNamePlusExt.substr(0, found) ;
989  }
990 
991  // #define DEBUG
992 #ifdef DEBUG
993 
994  std::cerr << "write" <<std::endl;
995  std::cerr<<"extension for write= "<<ext_name<<std::endl;
996  std::cerr<<"filename= "<<filename<<std::endl;
997  std::cerr<<"mode= "<<mode<<std::endl;
998  std::cerr<<"isStack= "<<isStack<<std::endl;
999  std::cerr<<"select_img= "<<select_img<<std::endl;
1000  std::cerr << "exists=" << _exists << std::endl;
1001 #endif
1002 #undef DEBUG
1003  // Check that image is not empty
1004  if (getSize() < 1)
1005  REPORT_ERROR(ERR_MULTIDIM_EMPTY,(String)"write Image ERROR: image "+name+" is empty!");
1006 
1007  replaceNsize = 0;//reset replaceNsize in case image is reused
1008  if(isStack && select_img == ALL_IMAGES && mode == WRITE_REPLACE)
1009  REPORT_ERROR(ERR_VALUE_INCORRECT,"Please specify object to be replaced");
1010  else if (_exists && (mode == WRITE_REPLACE || mode == WRITE_APPEND))
1011  {
1012  // CHECK FOR INCONSISTENCIES BETWEEN data.xdim and x, etc???
1013  size_t Xdim, Ydim, Zdim, _Xdim, _Ydim, _Zdim, Ndim, _Ndim;
1014  Xdim = Ydim = Zdim = _Xdim = _Ydim = _Zdim = Ndim = _Ndim = 0;
1015  if (nullptr == m_auxI) {
1016  m_auxI = new Image<char>();
1017  }
1018  m_auxI->_read(filNamePlusExt, hFile, HEADER, ALL_IMAGES);
1019 
1020  this->getDimensions(Xdim, Ydim, Zdim, Ndim);
1021  m_auxI->getDimensions(_Xdim, _Ydim, _Zdim, _Ndim);
1022 
1023  if(m_auxI->getSize()>1)
1024  {
1025  replaceNsize = _Ndim;
1026 
1029  if (select_img > ALL_IMAGES || Ndim < replaceNsize)
1030  swapWrite = m_auxI->swap;
1031 
1032  if(Xdim != _Xdim ||
1033  Ydim != _Ydim ||
1034  Zdim != _Zdim)
1035  {
1037  "ImageBase::Write: images source and target have different sizes:\n"
1038  "Image source to be written (x,y,z,n) = %d %d %d %lu\n"
1039  "Image file target %s (x,y,z,n) = %d %d %d %lu",
1040  Xdim,Ydim,Zdim,Ndim,dataFName.c_str(),_Xdim,_Ydim,_Zdim,_Ndim));
1041  }
1042  }
1043  }
1044  else if(!_exists && mode == WRITE_APPEND)
1045  {
1046  ;
1047  }
1048  else if (mode == WRITE_READONLY)//If new file we are in the WRITE_OVERWRITE mode
1049  {
1050  REPORT_ERROR(ERR_ARG_INCORRECT, formatString("File %s opened in read-only mode. Cannot write.", name.c_str()));
1051  }
1052 
1053  /*
1054  * SELECT FORMAT
1055  */
1056  //Set the file pointer at beginning
1057  if (fimg != NULL)
1058  fseek(fimg, 0, SEEK_SET);
1059  if (fhed != NULL)
1060  fseek(fhed, 0, SEEK_SET);
1061 
1062  if(ext_name.contains("spi") || ext_name.contains("xmp") ||
1063  ext_name.contains("vol"))
1064  err = writeSPIDER(select_img,isStack,mode);
1065  else if (ext_name.contains("stk"))
1066  err = writeSPIDER(select_img,true,mode);
1067  else if (isMRCStack(ext_name) || isMRCImageOrVolume(ext_name))
1068  writeMRC(select_img,isStack,mode,imParam,castMode);
1069  else if (ext_name.contains("img") || ext_name.contains("hed"))
1070  writeIMAGIC(select_img,mode,imParam,castMode);
1071  else if (ext_name.contains("dm3"))
1072  writeDM3(select_img,false,mode);
1073  else if (ext_name.contains("dm4"))
1074  writeDM4(select_img,false,mode);
1075  else if (ext_name.contains("em"))
1076  writeEM(select_img,false,mode);
1077  else if (ext_name.contains("pif"))
1078  writePIF(select_img,false,mode);
1079  else if (ext_name.contains("ser"))
1080  writeTIA(select_img,false,mode);
1081  else if (ext_name.contains("raw") || ext_name.contains("inf"))
1082  writeINF(select_img,false,mode,imParam,castMode);
1083  else if (ext_name.contains("tif"))
1084  writeTIFF(select_img,isStack,mode,imParam,castMode);
1085  else if (ext_name.contains("spe"))
1086  writeSPE(select_img,isStack,mode);
1087  else if (ext_name.contains("jpg"))
1088  writeJPEG(select_img, false, WRITE_OVERWRITE, "", CW_ADJUST);
1089  else if (ext_name.contains("hdf5") || ext_name.contains("h5"))
1090  writeHDF5(select_img);
1091  else
1092  err = writeSPIDER(select_img,isStack,mode);
1093 
1094  if ( err < 0 )
1095  {
1096  std::cerr << " Filename = " << filename << " Extension= " << ext_name << std::endl;
1097  REPORT_ERROR(ERR_IO_NOWRITE, "Error writing file");
1098  }
1099 
1100  /* If initially the file did not existed, once the first image is written,
1101  * then the file exists
1102  */
1103  if (!_exists)
1104  hFile->exist = _exists = true;
1105 }
virtual void munmapFile()=0
int writeTIA(int img_select, bool isStack=false, int mode=WRITE_OVERWRITE)
Definition: rwTIA.cpp:253
int writeDM3(size_t img_select, bool isStack=false, int mode=WRITE_OVERWRITE)
Definition: rwDM3.cpp:437
MultidimArray is empty.
Definition: xmipp_error.h:175
Just an error for debugging purpose.
Definition: xmipp_error.h:119
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
int writeSPE(size_t select_img, bool isStack=false, int mode=WRITE_OVERWRITE)
Definition: rwSPE.cpp:84
FileName dataFName
Couldn&#39;t write to file.
Definition: xmipp_error.h:140
int writeHDF5(size_t select_img, bool isStack=false, int mode=WRITE_OVERWRITE, String bitDepth="", CastWriteMode castMode=CW_CAST)
Definition: rwHDF5.cpp:321
int writeIMAGIC(size_t img_select=ALL_IMAGES, int mode=WRITE_OVERWRITE, const String &bitDepth="", CastWriteMode castMode=CW_CAST)
Definition: rwIMAGIC.cpp:259
size_t getSize() const
Definition: xmipp_image.h:1091
ArrayDim getDimensions()
const FileName & name() const
Incorrect MultidimArray size.
Definition: xmipp_error.h:174
void decompose(size_t &no, String &str) const
int writeTIFF(size_t select_img, bool isStack=false, int mode=WRITE_OVERWRITE, String bitDepth="", CastWriteMode castMode=CW_CAST)
Definition: rwTIFF.cpp:342
int writeMRC(size_t select_img, bool isStack=false, int mode=WRITE_OVERWRITE, const String &bitDepth="", CastWriteMode castMode=CW_CAST)
Definition: rwMRC.cpp:369
int writeEM(size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE)
Definition: rwEM.cpp:148
int writeINF(size_t img_select, bool isStack=false, int mode=WRITE_OVERWRITE, String bitDepth="", CastWriteMode castMode=CW_CAST)
Definition: rwINF.cpp:132
Incorrect argument received.
Definition: xmipp_error.h:113
int writePIF(size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE)
Definition: rwPIF.cpp:161
void mode
bool contains(const String &str) const
int writeSPIDER(size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE)
Definition: rwSPIDER.cpp:320
size_t mappedSize
int _read(const FileName &name, ImageFHandler *hFile, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false)
std::string String
Definition: xmipp_strings.h:34
#define ALL_IMAGES
String formatString(const char *format,...)
FileName filename
bool isMRCStack(const FileName &ext_name)
Incorrect value received.
Definition: xmipp_error.h:195
size_t replaceNsize
int writeJPEG(size_t select_img, bool isStack=false, int mode=WRITE_OVERWRITE, String bitDepth="", CastWriteMode castMode=CW_CONVERT)
Definition: rwJPEG.cpp:130
int writeDM4(size_t img_select, bool isStack=false, int mode=WRITE_OVERWRITE)
Definition: rwDM4.cpp:676
virtual size_t getSize() const =0
bool isMRCImageOrVolume(const FileName &ext_name)
void getDimensions(size_t &Xdim, size_t &Ydim, size_t &Zdim, size_t &Ndim) const

◆ applyGeo() [1/2]

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

Apply geometry in referring metadata to the image

Definition at line 246 of file xmipp_image_base.cpp.

247 {
248  std::unique_ptr<const MDRow> row(md.getRow(objId));
249  applyGeo(*row, params.only_apply_shifts, params.wrap);
250 }
virtual std::unique_ptr< MDRow > getRow(size_t id)=0
void applyGeo(const MetaData &md, size_t objId, const ApplyGeoParams &params=DefaultApplyGeoParams)

◆ applyGeo() [2/2]

virtual void ImageBase::applyGeo ( const MDRow row,
bool  only_apply_shifts = false,
bool  wrap = xmipp_transformation::WRAP 
)
protectedpure virtual

◆ checkMmapT()

virtual bool ImageBase::checkMmapT ( DataType  datatype)
pure virtual

◆ clear()

virtual void ImageBase::clear ( )
pure virtual

◆ clearHeader()

void ImageBase::clearHeader ( )

Clear the header of the image

Definition at line 109 of file xmipp_image_base.cpp.

110 {
112  MD.clear();
113  //Just to ensure there is an empty MDRow
114  MD.push_back(std::unique_ptr<MDRow>(new MDRowVec(MDMainHeader)));
115 }
std::vector< std::unique_ptr< MDRow > > MD
MDRowVec MDMainHeader
void clear() override

◆ closeFile()

void ImageBase::closeFile ( ImageFHandler hFile = NULL) const
protected

Close file function. Close the image file according to its name and file handler.

Definition at line 707 of file xmipp_image_base.cpp.

708 {
709  FileName ext_name, fileName;
710  FILE* fimg, *fhed;
711  TIFF* tif;
712  hid_t fhdf5;
713 
714  if (hFile != NULL)
715  {
716  fileName = hFile->fileName;
717  ext_name = hFile->ext_name;
718  fimg = hFile->fimg;
719  fhed = hFile->fhed;
720  tif = hFile->tif;
721  fhdf5 = hFile->fhdf5;
722  }
723  else
724  {
725  fileName = filename;
726  ext_name = filename.getFileFormat();
727  fimg = this->fimg;
728  fhed = this->fhed;
729  tif = this->tif;
730  fhdf5 = this->fhdf5;
731 
732  }
733 
734  if (ext_name.contains("tif"))
735  {
736  TIFFClose(tif);
737  /* Since when creating a TIFF file without adding an image the file is 8 bytes
738  * and this same file returns an error when trying to open again, we are going
739  * to suppose that under 8 bytes this is empty.
740  */
741  if (fileName.getFileSize() < 9)
743  }
744  else if (ext_name.contains("hdf") || ext_name.contains("h5"))
745  {
746  H5Fclose(fhdf5);
747  if (fclose(fimg) != 0 )
748  REPORT_ERROR(ERR_IO_NOCLOSED,(String)"Can not close image file "+ filename);
749  }
750  else
751  {
752  if (fclose(fimg) != 0 )
753  REPORT_ERROR(ERR_IO_NOCLOSED,(String)"Can not close image file "+ filename);
754 
755  if (fhed != NULL && fclose(fhed) != 0 )
756  REPORT_ERROR(ERR_IO_NOCLOSED,(String)"Can not close header file of "
757  + filename);
758  }
759  delete hFile;
760 }
struct tiff TIFF
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
ImageFHandler * hFile
File cannot be closed.
Definition: xmipp_error.h:135
bool contains(const String &str) const
void deleteFile() const
std::string String
Definition: xmipp_strings.h:34
String getFileFormat() const
FileName filename
size_t getFileSize() const

◆ copy()

void ImageBase::copy ( const ImageBase other)

Copy. Copy ImageBase from other image

Definition at line 70 of file xmipp_image_base.cpp.

70  {
71  MDMainHeader = other.MDMainHeader;
72  MD.clear();
73  MD.reserve(other.MD.size());
74  if ((other.MD.size() > 0) && (dynamic_cast<MDRowVec*>(other.MD[0].get()) != nullptr)) {
75  for (const std::unique_ptr<MDRow>& rowPtr : other.MD) {
76  const MDRow& row = *rowPtr;
77  MD.emplace_back(std::unique_ptr<MDRow>(new MDRowVec(dynamic_cast<const MDRowVec&>(row))));
78  }
79  }
80  if ((other.MD.size() > 0) && (dynamic_cast<MDRowSql*>(other.MD[0].get()) != nullptr)) {
81  for (const std::unique_ptr<MDRow>& rowPtr : other.MD) {
82  const MDRow& row = *rowPtr;
83  MD.emplace_back(std::unique_ptr<MDRow>(new MDRowSql(dynamic_cast<const MDRowSql&>(row))));
84  }
85  }
86 
87  filename = other.filename;
88  tempFilename = other.tempFilename;
89  dataFName = other.dataFName;
90  fimg = other.fimg;
91  fhed = other.fhed;
92  tif = other.tif;
93  hFile = other.hFile;
94  aDimFile = other.aDimFile;
95  offset = other.offset;
96  swap = other.swap;
97  swapWrite = other.swapWrite;
98  transform = other.transform;
99  replaceNsize = other.replaceNsize;
100  _exists = other._exists;
101  mmapOnRead = other.mmapOnRead;
102  mmapOnWrite = other.mmapOnWrite;
103  mFd = other.mFd;
104  mappedSize = other.mappedSize;
105  mappedOffset = other.mappedOffset;
107 }
ArrayDim aDimFile
size_t mappedOffset
FileName tempFilename
FileName dataFName
std::vector< std::unique_ptr< MDRow > > MD
ImageFHandler * hFile
TransformType transform
size_t virtualOffset
MDRowVec MDMainHeader
size_t mappedSize
FileName filename
size_t replaceNsize

◆ datatype()

DataType ImageBase::datatype ( ) const

Get datatype info from MDMainHeader.

In theory, it must be the image file data type.

std::cout << "datatype= " << datatype() << std::endl;

Data type

std::cout << "datatype= " << dataType() << std::endl;

Definition at line 483 of file xmipp_image_base.cpp.

484 {
485  int dummy;
487  return (DataType)dummy;
488 }
if read from file original image datatype, this is an struct defined in image
T & getValue(MDLabel label)
DataType
double dummy
MDRowVec MDMainHeader

◆ flip()

bool ImageBase::flip ( const size_t  n = 0) const

Get Flip

std::cout << "flip= " << flip() << std::endl;

Definition at line 470 of file xmipp_image_base.cpp.

471 {
472  bool dummy = false;
473  MD[n]->getValue(MDL_FLIP, dummy);
474  return dummy;
475 }
std::vector< std::unique_ptr< MDRow > > MD
Flip the image? (bool)
double dummy
int * n

◆ getCastConvertPageFromT()

virtual void ImageBase::getCastConvertPageFromT ( size_t  offset,
char *  page,
DataType  datatype,
size_t  pageSize,
double  min0,
double  max0,
CastWriteMode  castMode = CW_CONVERT 
) const
protectedpure virtual

◆ getDimensions() [1/3]

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

Get dimensions of the multidimArray inside image. TODO: This method must be changed to return the size of the image read from file, i.e. aDimFile, and where this is used should be used the imageBase::mda->getDimensions instead.

Definition at line 544 of file xmipp_image_base.cpp.

545 {
546  Xdim = XSIZE(*mdaBase);
547  Ydim = YSIZE(*mdaBase);
548  Zdim = ZSIZE(*mdaBase);
549  Ndim = NSIZE(*mdaBase);
550 }
#define NSIZE(v)
#define YSIZE(v)
#define XSIZE(v)
#define ZSIZE(v)
MultidimArrayBase * mdaBase

◆ getDimensions() [2/3]

void ImageBase::getDimensions ( ArrayDim aDim)
inline

Get Image dimensions

Definition at line 513 of file xmipp_image_base.h.

514  {
515  aDim = aDimFile;
516  }
ArrayDim aDimFile

◆ getDimensions() [3/3]

ArrayDim ImageBase::getDimensions ( )
inline

Definition at line 517 of file xmipp_image_base.h.

518  {
519  return aDimFile;
520  }
ArrayDim aDimFile

◆ getEulerAngles()

void ImageBase::getEulerAngles ( double &  rot,
double &  tilt,
double &  psi,
const size_t  n = 0 
) const

Get Euler angles from image header

Definition at line 519 of file xmipp_image_base.cpp.

521 {
522  MD[n]->getValue(MDL_ANGLE_ROT, rot);
523  MD[n]->getValue(MDL_ANGLE_TILT, tilt);
524  MD[n]->getValue(MDL_ANGLE_PSI, psi);
525 }
Rotation angle of an image (double,degrees)
double psi(const size_t n=0) const
Tilting angle of an image (double,degrees)
std::vector< std::unique_ptr< MDRow > > MD
Special label to be used when gathering MDs in MpiMetadataPrograms.
double rot(const size_t n=0) const
double tilt(const size_t n=0) const
int * n

◆ getGeometry()

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

Return geometry row

Definition at line 551 of file xmipp_image_base.h.

552  {
553  return *MD[n];
554  }
std::vector< std::unique_ptr< MDRow > > MD
int * n

◆ getInfo() [1/2]

void ImageBase::getInfo ( ImageInfo imgInfo) const

Get basic information from already read image file

Get Image dimensions

Definition at line 554 of file xmipp_image_base.cpp.

555 {
556  imgInfo.filename = filename;
557  imgInfo.offset = offset;
558  imgInfo.datatype = datatype();
559  imgInfo.swap = getSwap() > 0;
560  imgInfo.adim = aDimFile ;
561 }
FileName filename
ArrayDim aDimFile
int getSwap() const
ArrayDim adim
DataType datatype() const
DataType datatype
FileName filename

◆ getInfo() [2/2]

void ImageBase::getInfo ( const FileName name,
ImageInfo imgInfo 
)

Get basic information from image file

Definition at line 563 of file xmipp_image_base.cpp.

564 {
565  read(name, HEADER);
566  getInfo(imgInfo);
567 }
void getInfo(ImageInfo &imgInfo) const
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)

◆ getOffsetAndSwap()

void ImageBase::getOffsetAndSwap ( size_t &  _offset,
int &  _swap 
) const
inline

Get Image offset and swap

Definition at line 536 of file xmipp_image_base.h.

537  {
538  _offset = offset;
539  _swap = swap;
540  }

◆ getPageFromT()

virtual void ImageBase::getPageFromT ( size_t  offset,
char *  page,
DataType  datatype,
size_t  pageSize 
)
protectedpure virtual

◆ getPreview()

virtual void ImageBase::getPreview ( ImageBase imgOut,
size_t  Xdim,
size_t  Ydim = 0,
int  select_slice = CENTRAL_SLICE,
size_t  select_img = FIRST_IMAGE 
)
pure 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.

Implemented in Image< T >, Image< double >, Image< float >, Image< int >, Image< unsigned int >, Image< short int >, Image< unsigned char >, Image< char >, and Image< unsigned short int >.

◆ getScale()

void ImageBase::getScale ( double &  scale,
const size_t  n = 0 
)
inline

Get scale from image header

Definition at line 756 of file xmipp_image_base.h.

757  {
758  MD[n]->getValue(MDL_SCALE, scale);
759  }
std::vector< std::unique_ptr< MDRow > > MD
double scale(const size_t n=0) const
scaling factor for an image or volume (double)
int * n

◆ getShifts()

void ImageBase::getShifts ( double &  xoff,
double &  yoff,
double &  zoff,
const size_t  n = 0 
) const

Get origin offsets from image header

Definition at line 537 of file xmipp_image_base.cpp.

538 {
539  MD[n]->getValue(MDL_SHIFT_X, xoff);
540  MD[n]->getValue(MDL_SHIFT_Y, yoff);
541  MD[n]->getValue(MDL_SHIFT_Z, zoff);
542 }
Shift for the image in the X axis (double)
std::vector< std::unique_ptr< MDRow > > MD
Shift for the image in the Z axis (double)
Shift for the image in the Y axis (double)
int * n

◆ getSize()

virtual size_t ImageBase::getSize ( ) const
pure virtual

◆ getSwap()

int ImageBase::getSwap ( ) const
inline

Get Image swap

Definition at line 544 of file xmipp_image_base.h.

545  {
546  return swap;
547  }

◆ getTransformationMatrix()

virtual void ImageBase::getTransformationMatrix ( Matrix2D< double > &  A,
bool  only_apply_shifts = false,
const size_t  n = 0 
)
pure virtual

◆ individualContainsLabel()

bool ImageBase::individualContainsLabel ( MDLabel  label) const
inline

Definition at line 562 of file xmipp_image_base.h.

563  {
564  return (!MD.empty() && MD[0]->containsLabel(label));
565  }
std::vector< std::unique_ptr< MDRow > > MD

◆ init()

void ImageBase::init ( void  )

Init. Initialize everything to 0

Definition at line 50 of file xmipp_image_base.cpp.

51 {
52  clearHeader();
53 
55  fimg = fhed = NULL;
56  hFile = NULL;
57  tif = NULL;
58  dataMode = DATA;
60  filename.clear();
61  offset = 0;
62  swap = swapWrite = 0;
63  replaceNsize = 0;
64  _exists = mmapOnRead = mmapOnWrite = false;
65  mFd = 0;
67  m_auxI = nullptr;
68 }
DataMode dataMode
size_t mappedOffset
FileName tempFilename
FileName dataFName
ImageFHandler * hFile
TransformType transform
size_t virtualOffset
virtual bool isComplexT() const =0
size_t mappedSize
FileName filename
size_t replaceNsize

◆ initGeometry()

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

Init geometry transformation with defaults values

Definition at line 39 of file xmipp_image_base.cpp.

40 {
42 }
std::vector< std::unique_ptr< MDRow > > MD
static void emptifyHeader(MDRow &)
int * n

◆ isComplex()

bool ImageBase::isComplex ( ) const
inline

Check whether image is complex based on transform

Definition at line 294 of file xmipp_image_base.h.

295  {
296  return !(transform==NoTransform);
297  }
TransformType transform

◆ isComplexImage()

bool ImageBase::isComplexImage ( const FileName name)
inline

Is this file a complex image

Check whether a fourier-space (complex) image can be read

Definition at line 327 of file xmipp_image_base.h.

328  {
329  return (isImage(name) && isComplex());
330  }
bool isComplex() const
bool isImage(const FileName &name)

◆ isComplexT()

virtual bool ImageBase::isComplexT ( ) const
pure virtual

◆ isImage()

bool ImageBase::isImage ( const FileName name)

Is this file an image

Check whether a real-space image can be read

Definition at line 1107 of file xmipp_image_base.cpp.

1108 {
1109  try
1110  {
1111  return !read(name, HEADER);
1112  }
1113  catch (XmippError &xe)
1114  {
1115  return false;
1116  }
1117 }
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)

◆ isMapped()

bool ImageBase::isMapped ( )
inline

Check if image is mapped on file

Definition at line 309 of file xmipp_image_base.h.

310  {
311  return (mmapOnRead || mmapOnWrite);
312  }

◆ isRealImage()

bool ImageBase::isRealImage ( const FileName name)
inline

Is this file a real-valued image

Check whether a real-space image can be read

Definition at line 318 of file xmipp_image_base.h.

319  {
320  return (isImage(name) && !isComplex());
321  }
bool isComplex() const
bool isImage(const FileName &name)

◆ mainContainsLabel()

bool ImageBase::mainContainsLabel ( MDLabel  label) const
inline

Definition at line 568 of file xmipp_image_base.h.

569  {
570  return MDMainHeader.containsLabel(label);
571  }
bool containsLabel(MDLabel label) const override
MDRowVec MDMainHeader

◆ mapFile2Write()

void ImageBase::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 
)

Create a mapped image file

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. The image object must be cleared prior to use this method.

New mapped file

If XMIPP_MMAP is not defined this function is supposed to create the empty file only

Definition at line 202 of file xmipp_image_base.cpp.

204 {
207 #ifdef XMIPP_MMAP
208  mmapOnWrite = true;
209 #endif
210 
211  setDimensions(Xdim, Ydim, Zdim, 1); // Images with Ndim >1 cannot be mapped to image file
212  MD.resize(1);
213  filename = _filename;
214  FileName fnToOpen;
215  if (createTempFile)
216  {
217  tempFilename.initUniqueName("temp_XXXXXX");
218  fnToOpen = tempFilename + ":" + _filename.getExtension();
219  }
220  else
221  fnToOpen=_filename;
222 
223  /* If the filename is in stack or an image is selected, we will suppose
224  * you want to write this, even if you have not set the flags to.
225  */
226  if ( (filename.isInStack() || select_img > ALL_IMAGES) && mode == WRITE_OVERWRITE)
227  {
228  isStack = true;
230  }
231 
232  hFile = openFile(fnToOpen, mode);
233  _write(filename, hFile, select_img, isStack, mode);
234  closeFile(hFile);
235 }
ImageFHandler * openFile(const FileName &name, int mode=WRITE_READONLY) const
FileName tempFilename
std::vector< std::unique_ptr< MDRow > > MD
ImageFHandler * hFile
void initUniqueName(const char *templateStr="xmippTemp_XXXXXX", const String &fnDir="")
void _write(const FileName &name, ImageFHandler *hFile, size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST)
String getExtension() const
void closeFile(ImageFHandler *hFile=NULL) const
virtual void setDimensions(int Xdim, int Ydim, int Zdim, size_t Ndim)=0
void mode
#define ALL_IMAGES
FileName filename
bool isInStack() const

◆ mirrorY()

virtual void ImageBase::mirrorY ( )
pure virtual

◆ mmapFile()

virtual void ImageBase::mmapFile ( )
protectedpure virtual

Mmap the Image class to an image file.

◆ movePointerTo()

virtual void ImageBase::movePointerTo ( int  select_slice = ALL_SLICES,
size_t  select_img = ALL_IMAGES 
)
pure virtual

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.

Implemented in Image< T >, Image< double >, Image< float >, Image< int >, Image< unsigned int >, Image< short int >, Image< unsigned char >, Image< char >, and Image< unsigned short int >.

◆ munmapFile()

virtual void ImageBase::munmapFile ( )
protectedpure virtual

Munmap the image file.

◆ myT()

virtual DataType ImageBase::myT ( ) const
pure virtual

◆ name()

const FileName& ImageBase::name ( ) const
inline

Get file name

std::cout << "Image name = " << I.name() << std::endl;

Definition at line 500 of file xmipp_image_base.h.

501  {
502  return filename;
503  }
FileName filename

◆ openFile()

ImageFHandler * ImageBase::openFile ( const FileName name,
int  mode = WRITE_READONLY 
) const
protected


Open file function Open the image file and returns its file hander.

Definition at line 572 of file xmipp_image_base.cpp.

573 {
574  if (name.empty())
575  REPORT_ERROR(ERR_PARAM_INCORRECT, "ImageBase::openFile Cannot open an empty Filename.");
576 
578  FileName fileName, headName = "";
579  FileName ext_name = name.getFileFormat();
580 
581  // Remove image number and block name
582  fileName = name.removeAllPrefixes();
583 
584  fileName = fileName.removeFileFormat();
585 
586  size_t found = fileName.find_first_of("%");
587  if (found!=String::npos)
588  fileName = fileName.substr(0, found) ;
589 
590  bool exist = fileName.exists();
591  bool sizeZero = true;
592 
593  if (exist)
594  sizeZero = fileName.getFileSize() <= 0;
595  hFile->exist = exist && !sizeZero;
596  hFile->mode = mode;
597 
598  String wmChar;
599 
600  switch (mode)
601  {
602  case WRITE_READONLY:
603  if (!exist)
604  REPORT_ERROR(ERR_IO_NOTEXIST, formatString("Cannot access file '%s'. It doesn't exist", name.c_str()));
605  else if (sizeZero)
606  REPORT_ERROR(ERR_IO_SIZE, formatString("Cannot read zero size file '%s'.", name.c_str()));
607 
608  wmChar = "r";
609  break;
610  case WRITE_OVERWRITE:
611  wmChar = "w";
612  break;
613  case WRITE_APPEND:
614  case WRITE_REPLACE:
615  wmChar = (hFile->exist) ? "r+" : "w+";
616  break;
617 
618  }
619 
620  if (ext_name.contains("tif"))
621  {
622  TIFFSetWarningHandler(NULL); // Switch off warning messages
623  if ((hFile->tif = TIFFOpen(fileName.c_str(), wmChar.c_str())) == NULL)
624  REPORT_ERROR(ERR_IO_NOTOPEN,"rwTIFF: There is a problem opening the TIFF file.");
625  hFile->fimg = NULL;
626  hFile->fhed = NULL;
627  }
628  else if (ext_name.contains("hdf") || ext_name.contains("h5"))
629  {
630  if ((hFile->fhdf5 = H5Fopen(fileName.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT)) == -1 )
631  REPORT_ERROR(ERR_IO_NOTOPEN,"ImageBase::openFile: There is a problem opening the HDF5 file.");
632  // hFile->fimg = NULL;
633 
634  if ( (hFile->fimg = fopen(fileName.c_str(), wmChar.c_str())) == NULL )
635  {
636  if (errno == EACCES)
637  REPORT_ERROR(ERR_IO_NOPERM,formatString("Image::openFile: permission denied when opening %s",fileName.c_str()));
638  else
639  REPORT_ERROR(ERR_IO_NOTOPEN,formatString("Image::openFile cannot open: %s", fileName.c_str()));
640  }
641 
642  hFile->fhed = NULL;
643  hFile->tif = NULL;
644  }
645  else
646  {
647  hFile->tif = NULL;
648 
649  if (ext_name.contains("img") || ext_name.contains("hed"))
650  {
651  fileName = fileName.withoutExtension();
652  headName = fileName.addExtension("hed");
653  fileName = fileName.addExtension("img");
654  }
655  else if (ext_name.contains("raw"))
656  {
657  if (mode != WRITE_READONLY || fileName.addExtension("inf").exists() )
658  {
659  headName = fileName.addExtension("inf");
660  ext_name = "inf";
661  }
662  else
663  ext_name = "raw";
664  }
665  else if (ext_name.contains("inf"))
666  {
667  headName = fileName;
668  fileName = fileName.withoutExtension();
669  ext_name = "inf";
670  }
671 
672  // Open image file
673  if ( (hFile->fimg = fopen(fileName.c_str(), wmChar.c_str())) == NULL )
674  {
675  if (errno == EACCES)
676  REPORT_ERROR(ERR_IO_NOPERM,formatString("Image::openFile: permission denied when opening %s",fileName.c_str()));
677  else
678  REPORT_ERROR(ERR_IO_NOTOPEN,formatString("Image::openFile cannot open: %s", fileName.c_str()));
679  }
680 
681 
682  if (headName != "")
683  {
684  if ((hFile->fhed = fopen(headName.c_str(), wmChar.c_str())) == NULL )
685  {
686  if (errno == EACCES)
687  REPORT_ERROR(ERR_IO_NOPERM,formatString("Image::openFile: permission denied when opening %s",headName.c_str()));
688  else
689  REPORT_ERROR(ERR_IO_NOTOPEN,formatString("Image::openFile cannot open: %s",headName.c_str()));
690  }
691 
692  }
693  else
694  hFile->fhed = NULL;
695 
696  }
697  hFile->fileName = fileName;
698  hFile->headName = headName;
699  hFile->ext_name = ext_name;
700 
701  return hFile;
702 }
Parameter incorrect.
Definition: xmipp_error.h:181
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
FileName removeFileFormat() const
FileName addExtension(const String &ext) const
ImageFHandler * hFile
FileName removeAllPrefixes() const
File or directory does not exist.
Definition: xmipp_error.h:136
void mode
bool contains(const String &str) const
bool exists() const
File cannot be open.
Definition: xmipp_error.h:137
FileName withoutExtension() const
std::string String
Definition: xmipp_strings.h:34
String formatString(const char *format,...)
String getFileFormat() const
Incorrect file size.
Definition: xmipp_error.h:145
Insufficient permissions to perform operation.
Definition: xmipp_error.h:138
size_t getFileSize() const

◆ psi()

double ImageBase::psi ( const size_t  n = 0) const

Get Psi angle

std::cout << "Third Euler angle " << I.psi() << std::endl;

Definition at line 391 of file xmipp_image_base.cpp.

392 {
393  double dummy = 0;
394  MD[n]->getValue(MDL_ANGLE_PSI, dummy);
395  return dummy;
396 }
std::vector< std::unique_ptr< MDRow > > MD
Special label to be used when gathering MDs in MpiMetadataPrograms.
double dummy
int * n

◆ read()

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

General read function you can read a single image from a single image file or a single image file from an stack, in the second case the select slide may come in the image name or in the select_img parameter file name takes precedence over select_img If ALL_IMAGES is given the whole object is read.

Parameter mapData allows to access to image mapped to disk instead of loaded into memory. In case the mapped image is intended to be modified the parameter mode must be WRITE_REPLACE.

This function cannot apply geometrical transformations.

General read function

Definition at line 119 of file xmipp_image_base.cpp.

121 {
122  if (!mapData)
123  mode = WRITE_READONLY; //TODO: Check if openfile other than readonly is necessary
124 
125  hFile = openFile(name, mode);
126  int err = _read(name, hFile, datamode, select_img, mapData);
127  closeFile(hFile);
128  return err;
129 }
ImageFHandler * openFile(const FileName &name, int mode=WRITE_READONLY) const
ImageFHandler * hFile
void closeFile(ImageFHandler *hFile=NULL) const
void mode
int _read(const FileName &name, ImageFHandler *hFile, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false)

◆ readApplyGeo() [1/3]

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

General read function you can read a single image from a single image file or a single image file from an stack, in the second case the select slide may come in the image name or in the select_img parameter file name takes precedence over select_img If -1 is given the whole object is read

This function can apply geometrical transformations, but cannot map the image in disk

Definition at line 264 of file xmipp_image_base.cpp.

265 {
266  ImageFHandler* hFile = openFile(name);
267  int err = _read(name, hFile, params.datamode, params.select_img);
268  applyGeo(row, params.only_apply_shifts, params.wrap);
269  closeFile(hFile);
270  return err;
271 }
ImageFHandler * openFile(const FileName &name, int mode=WRITE_READONLY) const
ImageFHandler * hFile
void closeFile(ImageFHandler *hFile=NULL) const
void applyGeo(const MetaData &md, size_t objId, const ApplyGeoParams &params=DefaultApplyGeoParams)
int _read(const FileName &name, ImageFHandler *hFile, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false)

◆ readApplyGeo() [2/3]

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

Read an image from metadata, filename is provided

Definition at line 275 of file xmipp_image_base.cpp.

276 {
277  std::unique_ptr<const MDRow> row(md.getRow(objId));
278  READ_AND_RETURN();
279 }
virtual std::unique_ptr< MDRow > getRow(size_t id)=0
#define READ_AND_RETURN()

◆ readApplyGeo() [3/3]

int ImageBase::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 283 of file xmipp_image_base.cpp.

284 {
285  std::unique_ptr<const MDRow> row(md.getRow(objId));
286  FileName name;
287  row->getValue(MDL_IMAGE, name);
288  READ_AND_RETURN();
289 }
const FileName & name() const
virtual std::unique_ptr< MDRow > getRow(size_t id)=0
#define READ_AND_RETURN()
Name of an image (std::string)

◆ readBatch()

int ImageBase::readBatch ( const FileName name,
size_t  start_img,
size_t  batch_size,
DataMode  datamode = DATA,
bool  mapData = false,
int  mode = WRITE_READONLY 
)

Reads batch_size images from a single image file starting from image with index start_img. If batch_size == ALL_IMAGES, then all images starting from start_img to last image are read.

Definition at line 131 of file xmipp_image_base.cpp.

133 {
134  if (!mapData) {
136  }
137 
138  hFile = openFile(name, mode);
139  int err = _readBatch(name, hFile, start_img, batch_size, datamode, mapData);
140  closeFile(hFile);
141  return err;
142 }
ImageFHandler * openFile(const FileName &name, int mode=WRITE_READONLY) const
ImageFHandler * hFile
void closeFile(ImageFHandler *hFile=NULL) const
void mode
int _readBatch(const FileName &name, ImageFHandler *hFile, size_t start_img, size_t batch_size, DataMode datamode=DATA, bool mapData=false)

◆ readData()

virtual void ImageBase::readData ( FILE *  fimg,
size_t  select_img,
DataType  datatype,
size_t  pad 
)
protectedpure virtual

Read the raw data

◆ readData4bit()

virtual void ImageBase::readData4bit ( FILE *  fimg,
size_t  select_img,
DataType  datatype,
size_t  pad 
)
protectedpure virtual

Read the raw data in MRC 4bit mode

◆ readEER()

int ImageBase::readEER ( size_t  select_img)
protected

Definition at line 569 of file rwEER.cpp.

569  {
570  int upsampling = 1;
571  StringVector info;
573  size_t found = filename.find_first_of("#");
574  FileName infolist = filename.substr(found + 1);
575  filename = filename.substr(0, found);
576  infolist.toLowercase();
577  splitString(infolist, ",", info, false);
578 
579  if (info.size() < 3)
580  REPORT_ERROR(ERR_ARG_MISSING, (String) "Cannot open file " + filename +
581  ". Not enough header arguments.");
582 
583  const int fractioning = std::atoi(info[0].c_str());
584  if (fractioning < 1)
585  {
586  REPORT_ERROR(ERR_PARAM_INCORRECT, "Incorrect fractioning value (must be greater than zero)");
587  }
588  if (select_img > fractioning) {
589  REPORT_ERROR(ERR_PARAM_INCORRECT, (String) "Incorrect frame number selected (" + std::to_string(select_img) + "). Number of frames is " + std::to_string(fractioning) + ".");
590  }
591 
592  int _xDim,_yDim,_zDim;
593  size_t _nDim;
594  if (info[1] == "4K")
595  {
596  _xDim = _yDim = 4096;
597  }
598  else if (info[1] == "8K")
599  {
600  _xDim = _yDim = 8192;
601  }
602  else {
603  REPORT_ERROR(ERR_PARAM_INCORRECT, "Incorrect output size. Valid sizes are: 4K, 8K.");
604  }
605 
606  _zDim = _nDim = 1;
607  setDimensions(_xDim, _yDim, _zDim, _nDim);
609 
610  if(info[2] == "uint8")
611  datatype = DT_UChar;
612  else if (info[2] == "uint16")
613  datatype = DT_UShort;
614  else
615  REPORT_ERROR(ERR_PARAM_INCORRECT, "Incorrect output data type. Valid types are: uint8, uint16.");
616 
619  MDMainHeader.setValue(MDL_DATATYPE,(int)datatype);
620 
621  MD.clear();
622  MD.push_back(std::unique_ptr<MDRowVec>(new MDRowVec(MDL::emptyHeaderVec())));
623 
624  if( dataMode < DATA )
625  return 0;
626 
627  EERRenderer renderer;
628  renderer.read(hFile->fileName, upsampling);
629 
630  MultidimArray<int> buffer(_yDim, _xDim);
631  const auto step = renderer.getNFrames() / fractioning;
632  const auto first = (select_img-1)*step;
633  const auto last = first + step - 1;
634  renderer.renderFrames(first, last, buffer);
635  setPage2T(
636  0UL, reinterpret_cast<char*>(MULTIDIM_ARRAY(buffer)),
637  DT_Int,
639  );
640 
641  return 0;
642 }
Argument missing.
Definition: xmipp_error.h:114
Parameter incorrect.
Definition: xmipp_error.h:181
sampling rate in A/pixel (double)
long long renderFrames(int frame_start, int frame_end, MultidimArray< T > &image)
Definition: rwEER.cpp:389
sampling rate in A/pixel (double)
DataMode dataMode
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
virtual void setPage2T(size_t offset, char *page, DataType datatype, size_t pageSize)=0
#define MULTIDIM_SIZE(v)
virtual void coreAllocateReuse()=0
HBITMAP buffer
Definition: svm-toy.cpp:37
void setValue(const MDObject &object) override
std::vector< std::unique_ptr< MDRow > > MD
ImageFHandler * hFile
#define MULTIDIM_ARRAY(v)
if read from file original image datatype, this is an struct defined in image
std::vector< String > StringVector
Definition: xmipp_strings.h:35
glob_log first
int splitString(const String &input, const String &delimiter, StringVector &results, bool includeEmpties)
virtual void setDimensions(int Xdim, int Ydim, int Zdim, size_t Ndim)=0
void read(const FileName &_fn_movie, int eer_upsampling)
Definition: rwEER.cpp:286
static MDRowVec emptyHeaderVec()
DataType
FileName toLowercase() const
MDRowVec MDMainHeader
DataType datatype() const
std::string String
Definition: xmipp_strings.h:34
FileName filename
std::string to_string(bond_type bondType)
Definition: compound.cpp:43
MultidimArrayBase * mdaBase
int getNFrames()
Definition: rwEER.cpp:360

◆ readEM()

int ImageBase::readEM ( size_t  select_img,
bool  isStack = false 
)
protected

Read image from EM file format

Parameters
select_imgIndex number of selected image
Returns

Definition at line 33 of file rwEM.cpp.

34 {
35  // EM File formats does not support stacks
36  if (select_img > FIRST_IMAGE & !isStack)
37  REPORT_ERROR(ERR_ARG_INCORRECT, "readEM: EM file format does not support stacks.");
38 
39  EMHead header;
40 
41  if ( fread( &header, EMHEADERSIZE, 1, fimg ) != 1 )
42  REPORT_ERROR(ERR_IO_NOREAD, formatString("rwEM: cannot read EM main header from file %s"
43  ". Error message: %s", filename.c_str() ,strerror(errno)));
44 
45  // endian: If machine is SGI, OS-9 or MAC: Big Endian, otherwise Litle Endian
46  // Check Machine endianess
47  bool isLE = IsLittleEndian();
48 
49  if (header.machine == 0 || header.machine == 3 || header.machine == 5)
50  swap = isLE;
51  else if (header.machine == 1 || header.machine == 2 || header.machine == 4 || header.machine == 6)
52  swap = !isLE;
53  else
54  REPORT_ERROR(ERR_IMG_UNKNOWN, "rwEM: Unknown source machine to determine Endianness");
55 
56  if (swap)
57  swapPage((char *) &header, EMHEADERSIZE - 256, DT_UInt); // EMHEADERSIZE - 256 is to exclude userdata from swapping
58 
59  // Setting image dimensions
60 
61  ArrayDim aDim;
62  if (isStack)
63  {
64  if ( select_img > header.zdim )
65  REPORT_ERROR(ERR_INDEX_OUTOFBOUNDS, formatString("readEM: %s Image number %lu exceeds stack size %lu", this->filename.c_str(), select_img, header.zdim));
66 
67  aDim.ndim = (select_img > ALL_IMAGES)? 1 : header.zdim;
68  aDim.zdim = 1;
69  }
70  else
71  {
72  aDim.ndim = 1;
73  aDim.zdim = header.zdim;
74  }
75 
76  aDim.xdim = header.xdim;
77  aDim.ydim= header.ydim;
78 
79  replaceNsize = aDim.ndim;
80  setDimensions(aDim);
81 
82 
84  switch (header.datatype)
85  {
86  case 1:
87  datatype = DT_SChar;
88  break;
89  case 2:
90  datatype = DT_Short;
91  break;
92  case 4:
93  datatype = DT_Int;
94  break;
95  case 3:
96  case 5:
97  datatype = DT_Float;
98  break;
99  case 8:
100  datatype = DT_CFloat;
101  break;
102  case 9:
103  datatype = DT_CDouble;
104  break;
105  default:
106  REPORT_ERROR(ERR_ARG_INCORRECT, formatString("readEM: Unknown datatype value: %c", header.datatype));
107  break;
108  }
109  MDMainHeader.setValue(MDL_DATATYPE,(int)datatype);
110 
112 
113  // If only header is read: return
114  if (dataMode==HEADER || (dataMode == _HEADER_ALL && aDim.ndim > 1)) // Stop reading if not necessary
115  return 0;
116 
117  size_t imgStart = IMG_INDEX(select_img);
118  size_t imgEnd = (select_img != ALL_IMAGES) ? imgStart + 1 : aDim.ndim;
119 
120  MD.clear();
121  for (size_t i = 0; i < imgEnd-imgStart; i++)
122  MD.push_back(std::unique_ptr<MDRowVec>(new MDRowVec(MDL::emptyHeaderVec())));
123 
124  /* As MRC does not support stacks, we use the geometry stored in the header
125  for any image when we simulate the file is a stack.*/
126  if (dataMode == _HEADER_ALL || dataMode == _DATA_ALL)
127  {
128  for ( size_t i = 0; i < imgEnd - imgStart; ++i )
129  {
130  MD[i]->setValue(MDL_SHIFT_X, 0.);
131  MD[i]->setValue(MDL_SHIFT_Y, 0.);
132  MD[i]->setValue(MDL_SHIFT_Z, 0.);
133  MD[i]->setValue(MDL_ORIGIN_X, 0.);
134  MD[i]->setValue(MDL_ORIGIN_Y, 0.);
135  MD[i]->setValue(MDL_ORIGIN_Z, 0.);
136  }
137  }
138 
139  if ( dataMode < DATA ) // Don't read the individual header and the data if not necessary
140  return 0;
141 
142  readData(fimg, select_img, datatype, 0);
143 
144  return(0);
145 }
Index out of bounds.
Definition: xmipp_error.h:132
#define EMHEADERSIZE
Definition: rwEM.cpp:31
size_t xdim
DataMode dataMode
bool IsLittleEndian(void)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
virtual void readData(FILE *fimg, size_t select_img, DataType datatype, size_t pad)=0
void setValue(const MDObject &object) override
Shift for the image in the X axis (double)
void swapPage(char *page, size_t pageNrElements, DataType datatype, int swap=1)
std::vector< std::unique_ptr< MDRow > > MD
if read from file original image datatype, this is an struct defined in image
Unknown image type.
Definition: xmipp_error.h:130
auxiliary label to be used as an index (long)
int xdim
Definition: rwEM.h:58
#define i
size_t zdim
Origin for the image in the Y axis (double)
Incorrect argument received.
Definition: xmipp_error.h:113
int ydim
Definition: rwEM.h:59
int zdim
Definition: rwEM.h:60
virtual void setDimensions(int Xdim, int Ydim, int Zdim, size_t Ndim)=0
char datatype
Definition: rwEM.h:48
Definition: rwEM.h:36
Couldn&#39;t read from file.
Definition: xmipp_error.h:139
char machine
Definition: rwEM.h:38
static MDRowVec emptyHeaderVec()
DataType
MDRowVec MDMainHeader
size_t ndim
DataType datatype() const
#define ALL_IMAGES
String formatString(const char *format,...)
Shift for the image in the Z axis (double)
#define IMG_INDEX(select_img)
size_t ydim
Origin for the image in the Z axis (double)
#define FIRST_IMAGE
FileName filename
Shift for the image in the Y axis (double)
size_t replaceNsize

◆ readJPEG()

int ImageBase::readJPEG ( size_t  select_img)
protected

Definition at line 34 of file rwJPEG.cpp.

35 {
36  struct jpeg_decompress_struct cinfo;
37  struct jpeg_error_mgr jerr;
38 
39  cinfo.err = jpeg_std_error(&jerr);
40  jpeg_create_decompress(&cinfo);
41 
42  jpeg_stdio_src(&cinfo, fimg);
43  jpeg_read_header(&cinfo, TRUE);
44 
53 
54  ArrayDim aDim;
55  aDim.xdim = cinfo.image_width;
56  aDim.ydim = cinfo.image_height;
57  aDim.zdim = 1;
58  aDim.ndim = 1;
59 
60  setDimensions(aDim);
61 
62  replaceNsize = aDim.ndim;
63 
64  //Read header only
65  if (dataMode == HEADER || (dataMode == _HEADER_ALL )) // Stop reading if not necessary
66  {
67  jpeg_destroy_decompress(&cinfo);
68  return 0;
69  }
70 
71  /* As we cannot mmap a TIFF File, when this option is passed we are going to mmap
72  * the multidimarray of Image
73  */
74 
75  if (mmapOnRead)
76  {
77  mmapOnRead = false;
78  if (aDim.nzyxdim*gettypesize(DT_UChar) > tiff_map_min_size)
79  mdaBase->setMmap(true);
80  }
81 
82  // Allocate memory for image data (Assume xdim, ydim, zdim and ndim are already set
83  //if memory already allocated use it (no resize allowed)
85 
86  MD.clear();
87  for (size_t i = 0; i < aDim.ndim; i++)
88  MD.push_back(std::unique_ptr<MDRowVec>(new MDRowVec(MDL::emptyHeaderVec())));
89 
90  /* Start decompression jpeg here */
91  jpeg_start_decompress( &cinfo );
92 
93  /* allocate memory to hold the uncompressed image */
94  char * buffer = new char [aDim.xdim];
95  /* now actually read the jpeg into the raw buffer */
96  JSAMPROW row_pointer[1];
97  row_pointer[0] = new unsigned char [aDim.xdim*cinfo.num_components];
98  /* read one scan line at a time */
99  while( cinfo.output_scanline < cinfo.image_height )
100  {
101  jpeg_read_scanlines( &cinfo, row_pointer, 1 );
102  for(size_t i=0; i<cinfo.image_width;i++)
103  buffer[i] = row_pointer[0][i*cinfo.num_components];
104  setPage2T((cinfo.output_scanline - 1)*cinfo.image_width, buffer, DT_UChar, aDim.xdim);
105  }
106  /* wrap up decompression, destroy objects, free pointers and close open files */
107  jpeg_finish_decompress( &cinfo );
108  jpeg_destroy_decompress( &cinfo );
109  delete[] row_pointer[0];
110 
111  return 0;
112 }
tsne coefficients in 2D
sampling rate in A/pixel (double)
size_t xdim
sampling rate in A/pixel (double)
DataMode dataMode
sampling rate in A/pixel (double)
virtual void setPage2T(size_t offset, char *page, DataType datatype, size_t pageSize)=0
Maximum value (double)
virtual void coreAllocateReuse()=0
HBITMAP buffer
Definition: svm-toy.cpp:37
void setValue(const MDObject &object) override
std::vector< std::unique_ptr< MDRow > > MD
if read from file original image datatype, this is an struct defined in image
#define i
Minimum value (double)
size_t nzyxdim
size_t zdim
const size_t tiff_map_min_size
void setMmap(bool mmap)
virtual void setDimensions(int Xdim, int Ydim, int Zdim, size_t Ndim)=0
static MDRowVec emptyHeaderVec()
MDRowVec MDMainHeader
size_t ndim
#define TRUE
Definition: defines.h:25
size_t ydim
average value (double)
size_t replaceNsize
MultidimArrayBase * mdaBase
size_t gettypesize(DataType type)
Returns memory size of datatype.

◆ readMapped()

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

Definition at line 156 of file xmipp_image_base.cpp.

157 {
158  read(name, HEADER);
159  bool swap = this->swap > 0;
160  return read(name, DATA, select_img, !swap, mode);
161 }
void mode
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)

◆ readMRC()

int ImageBase::readMRC ( size_t  start_img,
size_t  batch_size,
bool  isStack = false 
)
protected

Definition at line 132 of file rwMRC.cpp.

133 {
134 
135 #undef DEBUG
136  //#define DEBUG
137 #ifdef DEBUG
138  printf("DEBUG readMRC: Reading MRC file\n");
139 #endif
140 
141  std::unique_ptr< MRChead > header( new MRChead() );
142 
143  int errCode = 0;
144 
145  if ( fread( header.get(), MRCSIZE, 1, fimg ) < 1 )
146  return(-2);
147 
148  // Determine byte order and swap bytes if from little-endian machine
149  if ( (swap = (( abs( header->mode ) > SWAPTRIG ) || ( abs(header->nz) > SWAPTRIG ))) )
150  {
151 #ifdef DEBUG
152  fprintf(stderr, "Warning: Swapping header byte order for 4-byte types\n");
153 #endif
154 
155  swapPage((char *) header.get(), MRCSIZE - 800, DT_Float); // MRCSIZE - 800 is to exclude labels from swapping
156  }
157 
158  // Convert VAX floating point types if necessary
159  // if ( header->amin > header->amax )
160  // REPORT_ERROR(ERR_IMG_NOREAD,"readMRC: amin > max: VAX floating point conversion unsupported");
161 
162  size_t _xDim,_yDim,_zDim,_nDim;
163  size_t _nDimSet;
164 
165  _xDim = header->nx;
166  _yDim = header->ny;
167  _zDim = header->nz;
168 
169  // Reading and storing axis order
170  axisOrder[0] = 0;
171  axisOrder[1] = 4 - header->maps;
172  axisOrder[2] = 4 - header->mapr;
173  axisOrder[3] = 4 - header->mapc;
174 
175  bool isVolStk = (header->ispg > 400);
176 
177  /* isStack is already true if file uses our customized "mrcs" extension. In this case
178  * we ignore the stack behavior in header. If format is forced through ":" flag suffix,
179  * then we also ignore the stack behavior in header */
180  if ( !isStack && (isVolStk || !filename.contains(":")))
181  isStack = ((header->ispg == 0 || isVolStk ) && (header->nsymbt == 0));
182 
183  // std::cout << "isStack = " << isStack << std::endl;
184 
185  if(isStack)
186  {
187  if (isVolStk)
188  {
189  _nDim = _zDim / header->mz;
190  _zDim = header->mz;
191  }
192  else
193  {
194  _nDim = _zDim;// When isStack slices in Z are supposed to be a stack of images
195  _zDim = 1;
196  }
197 
198  if (batch_size == ALL_IMAGES) {
199  _nDimSet = _nDim - start_img + 1;
200  } else {
201  _nDimSet = std::min( start_img + batch_size - 1, _nDim ) - start_img + 1;
202  }
203 
204 
205  if ( start_img > _nDim )
206  REPORT_ERROR(ERR_INDEX_OUTOFBOUNDS, formatString("readMRC: %s Image number %lu exceeds stack size %lu", this->filename.c_str(), start_img, _nDim));
207 
208  }
209  else // If the reading is not like a stack, then the select_img is not taken into account and must be selected the only image
210  {
211  start_img = 1;
212  _nDim = 1;
213  _nDimSet = 1;
214  }
215 
217  switch ( header->mode )
218  {
219  case 0:
220  datatype = DT_UChar;
221  break;
222  case 1:
223  datatype = DT_Short;
224  break;
225  case 2:
226  datatype = DT_Float;
227  break;
228  case 3:
229  datatype = DT_CShort;
230  break;
231  case 4:
232  datatype = DT_CFloat;
233  break;
234  case 6:
235  datatype = DT_UShort;
236  break;
237  case 12:
238  datatype = DT_HalfFloat;
239  break;
240  case 101:
241  datatype = DT_UHalfByte;
242  break;
243 
244  default:
245  datatype = DT_Unknown;
246  errCode = -1;
247  break;
248  }
249 
250  replaceNsize = _nDim;
251  setDimensions(_xDim, _yDim, _zDim, _nDimSet);
252 
253 
254  offset = MRCSIZE + header->nsymbt;
255  size_t datasize_n;
256  datasize_n = _xDim*_yDim*_zDim;
257 
258  // If mode is any of the fourier transforms (3,4)
259  if ( header->mode > 2 && header->mode < 5 )
260  {
262  fseek(fimg, 0, SEEK_END);
263  if ( ftell(fimg) > offset + 0.8*datasize_n*gettypesize(datatype) )
264  _xDim = (2 * (_xDim - 1));
265  if ( header->mx%2 == 1 )
266  _xDim += 1; // Quick fix for odd x-size maps
267  setDimensions(_xDim, _yDim, _zDim, _nDim);
268  }
269 
270  MDMainHeader.setValue(MDL_MIN,(double)header->amin);
271  MDMainHeader.setValue(MDL_MAX,(double)header->amax);
272  MDMainHeader.setValue(MDL_AVG,(double)header->amean);
273  MDMainHeader.setValue(MDL_STDDEV,(double)header->arms);
274  MDMainHeader.setValue(MDL_DATATYPE,(int)datatype);
275 
276  double sampling;
278  if ( header->mx && header->a!=0 && sampling == 1.0)//ux
279  MDMainHeader.setValue(MDL_SAMPLINGRATE_X,(double)header->a/header->mx);
281  if ( header->my && header->b!=0 && sampling == 1.0)//yx
282  MDMainHeader.setValue(MDL_SAMPLINGRATE_Y,(double)header->b/header->my);
284  if ( header->mz && header->c!=0 && sampling == 1.0)//zx
285  MDMainHeader.setValue(MDL_SAMPLINGRATE_Z,(double)header->c/header->mz);
286 
287  if (dataMode==HEADER || (dataMode == _HEADER_ALL && _nDim > 1)) // Stop reading if not necessary
288  {
289  readData(NULL, 0, DT_Unknown, 0); // To consider axis ordering. Will not read actual data
290  return errCode;
291  }
292 
293  const size_t imgStart = IMG_INDEX(start_img);
294  const size_t imgEnd = start_img + _nDimSet - 1;
295 
296  MD.clear();
297  for (size_t i = 0; i < imgEnd-imgStart; i++)
298  MD.push_back(std::unique_ptr<MDRowVec>(new MDRowVec(MDL::emptyHeaderVec())));
299 
300  /* As MRC does not support stacks, we use the geometry stored in the header
301  for any image when we simulate the file is a stack.*/
302  if (dataMode == _HEADER_ALL || dataMode == _DATA_ALL)
303  {
304  double aux;
305  for ( size_t i = 0; i < imgEnd - imgStart; ++i )
306  {
307  MD[i]->setValue(MDL_SHIFT_X, (double) -header->nxStart);
308  MD[i]->setValue(MDL_SHIFT_Y, (double) -header->nyStart);
309  MD[i]->setValue(MDL_SHIFT_Z, (double) -header->nzStart);
310 
311  // We include auto detection of MRC2000 or CCP4 style origin based on http://situs.biomachina.org/fmap.pdf
312  if (header->xOrigin != 0)
313  MD[i]->setValue(MDL_ORIGIN_X, (double)-header->xOrigin);
314  else if (header->nxStart != 0 && MDMainHeader.getValue(MDL_SAMPLINGRATE_X,aux))
315  MD[i]->setValue(MDL_ORIGIN_X, -header->nxStart/aux);
316 
317  if (header->yOrigin !=0)
318  MD[i]->setValue(MDL_ORIGIN_Y, (double)-header->yOrigin);
319  else if(header->nyStart !=0 && MDMainHeader.getValue(MDL_SAMPLINGRATE_Y,aux))
320  MD[i]->setValue(MDL_ORIGIN_Y, -header->nyStart/aux);
321 
322  if (header->zOrigin != 0)
323  MD[i]->setValue(MDL_ORIGIN_Z, (double)-header->zOrigin);
324  else if(header->nzStart !=0 && MDMainHeader.getValue(MDL_SAMPLINGRATE_Z,aux))
325  MD[i]->setValue(MDL_ORIGIN_Z, -header->nzStart/aux);
326  }
327  }
328 
329  if ( dataMode < DATA ) // Don't read the individual header and the data if not necessary
330  {
331  readData(NULL, 0, DT_Unknown, 0); // To consider axis ordering. Will not read actual data
332  return errCode;
333  }
334 
335  // Lets read the data
336 
337  // 4-bits mode: Here is the magic to expand the compressed images
338  if (datatype == DT_UHalfByte){
339  readData4bit(fimg, start_img, datatype, 0);
340  }
341  else{
342  readData(fimg, start_img, datatype, 0);
343  }
344 
345  return errCode;
346 }
Index out of bounds.
Definition: xmipp_error.h:132
tsne coefficients in 2D
void min(Image< double > &op1, const Image< double > &op2)
std::array< int, 4 > axisOrder
#define SWAPTRIG
sampling rate in A/pixel (double)
sampling rate in A/pixel (double)
DataMode dataMode
#define MRCSIZE
Definition: rwMRC.cpp:44
sampling rate in A/pixel (double)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
virtual void readData(FILE *fimg, size_t select_img, DataType datatype, size_t pad)=0
Maximum value (double)
void setValue(const MDObject &object) override
Shift for the image in the X axis (double)
void swapPage(char *page, size_t pageNrElements, DataType datatype, int swap=1)
std::vector< std::unique_ptr< MDRow > > MD
const T & getValueOrDefault(MDLabel label, const T &def) const
void abs(Image< double > &op)
if read from file original image datatype, this is an struct defined in image
TransformType transform
auxiliary label to be used as an index (long)
#define i
T & getValue(MDLabel label)
Minimum value (double)
Origin for the image in the Y axis (double)
virtual void setDimensions(int Xdim, int Ydim, int Zdim, size_t Ndim)=0
#define sampling
static MDRowVec emptyHeaderVec()
DataType
bool contains(const String &str) const
MDRowVec MDMainHeader
DataType datatype() const
#define ALL_IMAGES
String formatString(const char *format,...)
Shift for the image in the Z axis (double)
#define IMG_INDEX(select_img)
fprintf(glob_prnt.io, "\)
Origin for the image in the Z axis (double)
average value (double)
FileName filename
Shift for the image in the Y axis (double)
size_t replaceNsize
size_t gettypesize(DataType type)
Returns memory size of datatype.
virtual void readData4bit(FILE *fimg, size_t select_img, DataType datatype, size_t pad)=0

◆ readOrReadMapped()

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

Definition at line 163 of file xmipp_image_base.cpp.

164 {
165  try
166  {
167  return read(name, DATA, select_img, false, mode);
168  }
169  catch (XmippError &xe)
170  {
171  if (xe.__errno == ERR_MEM_NOTENOUGH)
172  {
173  reportWarning("ImageBase::readOrReadMapped: Not enough memory to allocate. \n"
174  " Proceeding to map image from file.");
175  return readMapped(name, select_img, mode);
176  }
177  else
178  throw xe;
179  }
180 }
void reportWarning(const String &what)
There is not enough memory for allocation.
Definition: xmipp_error.h:166
void mode
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
ErrorType __errno
Definition: xmipp_error.h:227
int readMapped(const FileName &name, size_t select_img=ALL_IMAGES, int mode=WRITE_READONLY)

◆ readOrReadPreview()

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

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 182 of file xmipp_image_base.cpp.

184 {
185  read(name, HEADER);
186  size_t imXdim, imYdim, imZdim, imNdim;
187  getDimensions(imXdim, imYdim, imZdim, imNdim);
188 
189  if (imXdim != Xdim || imYdim != Ydim)
190  return readPreview(name, Xdim, Ydim, select_slice, select_img);
191  else
192  {
193  int ret = read(name, DATA, select_img, mapData);
194  if (select_slice != ALL_SLICES)
195  movePointerTo(select_slice);
196  return ret;
197  }
198 
199 }
ArrayDim getDimensions()
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
virtual void movePointerTo(int select_slice=ALL_SLICES, size_t select_img=ALL_IMAGES)=0
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
#define ALL_SLICES

◆ readPIF()

int ImageBase::readPIF ( size_t  select_img)
protected

Read image from PIF file format

Parameters
select_imgIndex number of selected image
Returns

Definition at line 33 of file rwPIF.cpp.

34 {
35  PIFMainHeader mainHeader;
36  if ( fread( &mainHeader, PIFHEADERSIZE, 1, fimg ) != 1 )
37  REPORT_ERROR(ERR_IO_NOREAD, formatString("rwPIF: cannot read Spider main header from file %s"
38  ". Error message: %s", filename.c_str() ,strerror(errno)));
39 
40  // Check Machine endianness
41  bool isLE = IsLittleEndian();
42 
43  // Determine byte order and swap bytes if from different-endian machine
44  swap = (isLE == mainHeader.endianNess);
45 
46  if (swap)
47  swapPage((char *) &mainHeader, PIFHEADERSIZE, DT_Int);
48 
49 
51  switch (mainHeader.mode)
52  {
53  case 0:
54  datatype = DT_SChar;
55  break;
56  case 1:
57  case 7: // Actually it's floatint*2, but it isn't moved to float
58  datatype = DT_Short;
59  break;
60  case 2:
61  case 46: // This case is not documented, but I think this is floatInt*4
62  datatype = DT_Int; // We aren't moving to float actually
63  break;
64  case 3:
65  case 8: // Actually it's complex floatint*2, but it isn't moved to float
66  datatype = DT_CShort;
67  break;
68  case 4:
69  datatype = DT_CInt; // We aren't moving to float actually
70  break;
71  case 9:
72  datatype = DT_Float;
73  break;
74  case 10:
75  datatype = DT_CFloat;
76  break;
77  case 97:
78  REPORT_ERROR(ERR_NOT_IMPLEMENTED, "readPIF: Reading from colormap datatype file not implemented.\n"
79  "If you're interested in this feature, please contact us at xmipp@cnb.csic.es \n"
80  "and send us an example image file to help implementing.");
81  break;
82  default:
83  REPORT_ERROR(ERR_NOT_IMPLEMENTED, formatString("readPIF: Reading from datatype code %d file not implemented.\n"
84  "If you're interested in this feature, please contact us at xmipp@cnb.csic.es \n"
85  "and send us an example image file to help implementing.", mainHeader.mode));
86  break;
87  }
88  MDMainHeader.setValue(MDL_DATATYPE,(int)datatype);
89 
90 
91  // Check selected image
92  if (select_img > (size_t)mainHeader.numImages)
93  REPORT_ERROR(ERR_INDEX_OUTOFBOUNDS, formatString("readPIF (%s): Image number %lu exceeds stack size %lu" ,filename.c_str(),select_img, mainHeader.numImages));
94 
95  // Setting image dimensions
96  ArrayDim aDim;
97 
98  aDim.ndim = (select_img == ALL_IMAGES)? mainHeader.numImages : 1;
99  aDim.zdim = mainHeader.nz;
100  aDim.ydim = mainHeader.ny;
101  aDim.xdim = mainHeader.nx;
102 
103  replaceNsize = aDim.ndim;
104 
105  setDimensions(aDim);
106 
107 
108  size_t imgStart = IMG_INDEX(select_img);
109  size_t datatypeSize = gettypesize(datatype);
110  offset = PIFHEADERSIZE*2;// + (aDimFile.zyxdim*datatypeSize + PIFHEADERSIZE)*imgStart;
111 
112  if (dataMode == HEADER || (dataMode == _HEADER_ALL && aDim.ndim > 1)) // Stop reading if not necessary
113  return 0;
114 
115  size_t imgEnd = (select_img != ALL_IMAGES) ? imgStart + 1 : aDim.ndim;
116 
117  size_t imageSize = PIFHEADERSIZE + aDimFile.zyxdim*datatypeSize;
118  size_t pad = PIFHEADERSIZE;
119  size_t headerOffset = PIFHEADERSIZE;
120 
121  MD.clear();
122  for (size_t i = 0; i < imgEnd-imgStart; i++)
123  MD.push_back(std::unique_ptr<MDRowVec>(new MDRowVec(MDL::emptyHeaderVec())));
124 
125  PIFDataHeader dataHeader;
126 
127  for (size_t n = 0, i = imgStart; i < imgEnd; ++i, ++n )
128  {
129  if (fseek( fimg, headerOffset + i*imageSize, SEEK_SET ) != 0)//fseek return 0 on success
130  REPORT_ERROR(ERR_IO, formatString("rwPIF: error seeking %lu to read image %lu", headerOffset, i));
131 
132  if ( fread( &dataHeader, PIFHEADERSIZE, 1, fimg ) != 1 )
133  REPORT_ERROR(ERR_IO_NOREAD, formatString("rwPIF: cannot read PIF image %lu header", i));
134 
135  if ( swap )
136  swapPage((char *) &dataHeader, PIFHEADERSIZE, DT_Int);
137 
138  if (dataMode == _HEADER_ALL || dataMode == _DATA_ALL)
139  {
140  MD[n]->setValue(MDL_ORIGIN_X, (double)dataHeader.nxstart);
141  MD[n]->setValue(MDL_ORIGIN_Y, (double)dataHeader.nystart);
142  MD[n]->setValue(MDL_ORIGIN_Z, (double)dataHeader.nzstart);
143  MD[n]->setValue(MDL_ANGLE_ROT, (double)dataHeader.alpha);
144  MD[n]->setValue(MDL_ANGLE_TILT, (double)dataHeader.beta);
145  MD[n]->setValue(MDL_ANGLE_PSI, (double)dataHeader.gamma);
146  MD[n]->setValue(MDL_SAMPLINGRATE_X, (double)dataHeader.xlength/aDim.xdim);
147  MD[n]->setValue(MDL_SAMPLINGRATE_Y, (double)dataHeader.ylength/aDim.ydim);
148  MD[n]->setValue(MDL_SAMPLINGRATE_Z, (double)dataHeader.zlength/aDim.zdim);
149  }
150  }
151 
152  if (dataMode < DATA) // Don't read data if not necessary but read the header
153  return 0;
154 
155  //offset should point to the begin of the data
156  readData(fimg, select_img, datatype, pad );
157 
158  return(0);
159 }
Index out of bounds.
Definition: xmipp_error.h:132
Rotation angle of an image (double,degrees)
Case or algorithm not implemented yet.
Definition: xmipp_error.h:177
sampling rate in A/pixel (double)
size_t xdim
sampling rate in A/pixel (double)
DataMode dataMode
sampling rate in A/pixel (double)
bool IsLittleEndian(void)
float xlength
Definition: rwPIF.h:113
ArrayDim aDimFile
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
virtual void readData(FILE *fimg, size_t select_img, DataType datatype, size_t pad)=0
Tilting angle of an image (double,degrees)
void setValue(const MDObject &object) override
float ylength
Definition: rwPIF.h:114
void swapPage(char *page, size_t pageNrElements, DataType datatype, int swap=1)
std::vector< std::unique_ptr< MDRow > > MD
Special label to be used when gathering MDs in MpiMetadataPrograms.
if read from file original image datatype, this is an struct defined in image
Input/Output general error.
Definition: xmipp_error.h:134
int nx
Definition: rwPIF.h:53
auxiliary label to be used as an index (long)
float beta
Definition: rwPIF.h:117
#define i
int numImages
Definition: rwPIF.h:42
int nystart
Definition: rwPIF.h:108
size_t zdim
Origin for the image in the Y axis (double)
size_t zyxdim
virtual void setDimensions(int Xdim, int Ydim, int Zdim, size_t Ndim)=0
float zlength
Definition: rwPIF.h:115
int nxstart
Definition: rwPIF.h:107
Couldn&#39;t read from file.
Definition: xmipp_error.h:139
static MDRowVec emptyHeaderVec()
DataType
int nz
Definition: rwPIF.h:55
int mode
Definition: rwPIF.h:56
float gamma
Definition: rwPIF.h:118
int nzstart
Definition: rwPIF.h:109
float alpha
Definition: rwPIF.h:116
#define PIFHEADERSIZE
Definition: rwPIF.cpp:31
MDRowVec MDMainHeader
size_t ndim
DataType datatype() const
#define ALL_IMAGES
String formatString(const char *format,...)
#define IMG_INDEX(select_img)
size_t ydim
Origin for the image in the Z axis (double)
FileName filename
int endianNess
Definition: rwPIF.h:43
size_t replaceNsize
int * n
int ny
Definition: rwPIF.h:54
size_t gettypesize(DataType type)
Returns memory size of datatype.

◆ readPreview()

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

◆ readRange()

int ImageBase::readRange ( const FileName name,
size_t  start_img,
size_t  end_img,
DataMode  datamode = DATA,
bool  mapData = false,
int  mode = WRITE_READONLY 
)

Reads range of images form a single image file starting from image with index start_img and ending with image with index end_img inclusive.

Definition at line 144 of file xmipp_image_base.cpp.

146 {
147  if (end_img < start_img) {
148  REPORT_ERROR(ERR_ARG_DEPENDENCE, formatString("readRange: end_img %lu is smaller than start_img %lu\n", end_img, start_img));
149  }
150 
151  readBatch(name, start_img, end_img - start_img + 1, datamode, mapData, mode);
152  return true;
153 }
int readBatch(const FileName &name, size_t start_img, size_t batch_size, DataMode datamode=DATA, bool mapData=false, int mode=WRITE_READONLY)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Error with some arguments dependencies.
Definition: xmipp_error.h:115
void mode
String formatString(const char *format,...)

◆ rename()

void ImageBase::rename ( const FileName name)
inline

Rename the image

Definition at line 333 of file xmipp_image_base.h.

334  {
335  filename = name;
336  }
const FileName & name() const
FileName filename

◆ rot()

double ImageBase::rot ( const size_t  n = 0) const

Get Rot angle

std::cout << "First Euler angle " << I.rot() << std::endl;

Definition at line 365 of file xmipp_image_base.cpp.

366 {
367  double dummy = 0;
368  MD[n]->getValue(MDL_ANGLE_ROT, dummy);
369  return dummy;
370 }
Rotation angle of an image (double,degrees)
std::vector< std::unique_ptr< MDRow > > MD
double dummy
int * n

◆ samplingRateX()

double ImageBase::samplingRateX ( ) const

Sampling RateX

std::cout << "sampling= " << samplingRateX() << std::endl;

Definition at line 500 of file xmipp_image_base.cpp.

501 {
502  double dummy = 1.;
504  return dummy;
505 }
sampling rate in A/pixel (double)
T & getValue(MDLabel label)
double dummy
MDRowVec MDMainHeader

◆ scale()

double ImageBase::scale ( const size_t  n = 0) const

Get Scale factor

std::cout << "scale= " << I.scale() << std::endl;

Definition at line 456 of file xmipp_image_base.cpp.

457 {
458  double dummy = 1;
459  MD[n]->getValue(MDL_SCALE, dummy);
460  return dummy;
461 }
std::vector< std::unique_ptr< MDRow > > MD
scaling factor for an image or volume (double)
double dummy
int * n

◆ selfApplyGeometry()

virtual void ImageBase::selfApplyGeometry ( int  SplineDegree,
bool  wrap,
bool  only_apply_shifts 
)
pure virtual

◆ setADimFile()

void ImageBase::setADimFile ( ArrayDim  aDim)
inline

Set the information of the original image dimensions

Definition at line 670 of file xmipp_image_base.h.

671  {
672  aDimFile = aDim;
673  }
ArrayDim aDimFile

◆ setDataMode()

void ImageBase::setDataMode ( DataMode  mode)
inline

Set the read/write dataMode of the object

Definition at line 683 of file xmipp_image_base.h.

684  {
685  dataMode = mode;
686  }
DataMode dataMode
void mode

◆ setDatatype()

void ImageBase::setDatatype ( DataType  datatype)
protected

Set datatype info in MDMainHeader

Definition at line 490 of file xmipp_image_base.cpp.

491 {
493 }
void setValue(const MDObject &object) override
if read from file original image datatype, this is an struct defined in image
MDRowVec MDMainHeader
DataType datatype() const

◆ setDimensions() [1/2]

virtual void ImageBase::setDimensions ( int  Xdim,
int  Ydim,
int  Zdim,
size_t  Ndim 
)
pure virtual

◆ setDimensions() [2/2]

void ImageBase::setDimensions ( ArrayDim aDim)
virtual

Definition at line 44 of file xmipp_image_base.cpp.

45 {
46  mdaBase->setDimensions(aDim);
47  aDimFile = aDim;
48 }
ArrayDim aDimFile
void setDimensions(int Xdim, int Ydim, int Zdim, size_t Ndim)
MultidimArrayBase * mdaBase

◆ setEulerAngles()

void ImageBase::setEulerAngles ( double  rot,
double  tilt,
double  psi,
const size_t  n = 0 
)

Set Euler angles in image header

Definition at line 509 of file xmipp_image_base.cpp.

511 {
512  MD[n]->setValue(MDL_ANGLE_ROT, rot);
513  MD[n]->setValue(MDL_ANGLE_TILT, tilt);
514  MD[n]->setValue(MDL_ANGLE_PSI, psi);
515 }
Rotation angle of an image (double,degrees)
double psi(const size_t n=0) const
Tilting angle of an image (double,degrees)
std::vector< std::unique_ptr< MDRow > > MD
Special label to be used when gathering MDs in MpiMetadataPrograms.
double rot(const size_t n=0) const
double tilt(const size_t n=0) const
int * n

◆ setFlip()

void ImageBase::setFlip ( bool  flip,
const size_t  n = 0 
)
inline

Set flip in image header

Definition at line 763 of file xmipp_image_base.h.

764  {
765  MD[n]->setValue(MDL_FLIP, flip);
766  }
std::vector< std::unique_ptr< MDRow > > MD
Flip the image? (bool)
bool flip(const size_t n=0) const
int * n

◆ setGeo()

void ImageBase::setGeo ( const MDRow row,
size_t  n = 0 
)

Set geo. Copy the input geometry row into the image metadata row n.

Definition at line 252 of file xmipp_image_base.cpp.

253 {
254  if (n < MD.size()) {
255  if (dynamic_cast<const MDRowVec*>(&row) != nullptr)
256  MD[n] = std::unique_ptr<MDRow>(new MDRowVec(dynamic_cast<const MDRowVec&>(row)));
257  if (dynamic_cast<const MDRowSql*>(&row) != nullptr)
258  MD[n] = std::unique_ptr<MDRow>(new MDRowSql(dynamic_cast<const MDRowSql&>(row)));
259  } else {
260  REPORT_ERROR(ERR_MD_OBJECTNUMBER, "Trying to set a value outside the current metadata size");
261  }
262 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
std::vector< std::unique_ptr< MDRow > > MD
Incorrect number of objects in Metadata.
Definition: xmipp_error.h:160
int * n

◆ setName()

void ImageBase::setName ( const FileName _filename)
inline

Set file name

Definition at line 676 of file xmipp_image_base.h.

677  {
678  filename = _filename;
679  }
FileName filename

◆ setPage2T()

virtual void ImageBase::setPage2T ( size_t  offset,
char *  page,
DataType  datatype,
size_t  pageSize 
)
protectedpure virtual

◆ setPsi()

void ImageBase::setPsi ( double  psi,
const size_t  n = 0 
)
inline

Set Rotation angle to image

Definition at line 711 of file xmipp_image_base.h.

712  {
713  MD[n]->setValue(MDL_ANGLE_PSI, psi);
714  }
double psi(const size_t n=0) const
std::vector< std::unique_ptr< MDRow > > MD
Special label to be used when gathering MDs in MpiMetadataPrograms.
int * n

◆ setRot()

void ImageBase::setRot ( double  rot,
const size_t  n = 0 
)
inline

Set Rotation angle to image

Definition at line 699 of file xmipp_image_base.h.

700  {
701  MD[n]->setValue(MDL_ANGLE_ROT, rot);
702  }
Rotation angle of an image (double,degrees)
std::vector< std::unique_ptr< MDRow > > MD
double rot(const size_t n=0) const
int * n

◆ setScale()

void ImageBase::setScale ( double  scale,
const size_t  n = 0 
)
inline

Set scale in image header

Definition at line 749 of file xmipp_image_base.h.

750  {
751  MD[n]->setValue(MDL_SCALE, scale);
752  }
std::vector< std::unique_ptr< MDRow > > MD
double scale(const size_t n=0) const
scaling factor for an image or volume (double)
int * n

◆ setShifts()

void ImageBase::setShifts ( double  xoff,
double  yoff,
double  zoff = 0.,
const size_t  n = 0 
)

Set origin offsets in image header

Definition at line 529 of file xmipp_image_base.cpp.

530 {
531  MD[n]->setValue(MDL_SHIFT_X, xoff);
532  MD[n]->setValue(MDL_SHIFT_Y, yoff);
533  MD[n]->setValue(MDL_SHIFT_Z, zoff);
534 }
Shift for the image in the X axis (double)
std::vector< std::unique_ptr< MDRow > > MD
Shift for the image in the Z axis (double)
Shift for the image in the Y axis (double)
int * n

◆ setTilt()

void ImageBase::setTilt ( double  tilt,
const size_t  n = 0 
)
inline

Set Tilt angle to image

Definition at line 705 of file xmipp_image_base.h.

706  {
707  MD[n]->setValue(MDL_ANGLE_TILT, tilt);
708  }
Tilting angle of an image (double,degrees)
std::vector< std::unique_ptr< MDRow > > MD
double tilt(const size_t n=0) const
int * n

◆ setWeight()

void ImageBase::setWeight ( double  weight,
const size_t  n = 0 
)
inline

Set Weight in image header

Definition at line 770 of file xmipp_image_base.h.

771  {
772  MD[n]->setValue(MDL_WEIGHT, weight);
773  }
std::vector< std::unique_ptr< MDRow > > MD
double weight(const size_t n=0) const
int * n
< Score 4 for volumes

◆ setXoff()

void ImageBase::setXoff ( double  xoff,
const size_t  n = 0 
)
inline

Set X offset in image header

Definition at line 728 of file xmipp_image_base.h.

729  {
730  MD[n]->setValue(MDL_SHIFT_X, xoff);
731  }
Shift for the image in the X axis (double)
std::vector< std::unique_ptr< MDRow > > MD
int * n

◆ setYoff()

void ImageBase::setYoff ( double  yoff,
const size_t  n = 0 
)
inline

Set Y offset in image header

Definition at line 735 of file xmipp_image_base.h.

736  {
737  MD[n]->setValue(MDL_SHIFT_Y, yoff);
738  }
std::vector< std::unique_ptr< MDRow > > MD
Shift for the image in the Y axis (double)
int * n

◆ setZoff()

void ImageBase::setZoff ( double  zoff,
const size_t  n = 0 
)
inline

Set Z offset in image header

Definition at line 742 of file xmipp_image_base.h.

743  {
744  MD[n]->setValue(MDL_SHIFT_Z, zoff);
745  }
std::vector< std::unique_ptr< MDRow > > MD
Shift for the image in the Z axis (double)
int * n

◆ sumWithFile()

virtual void ImageBase::sumWithFile ( const FileName fn)
pure virtual

◆ swapOnWrite()

void ImageBase::swapOnWrite ( )
inline

Definition at line 489 of file xmipp_image_base.h.

490  {
491  swapWrite = true;
492  }

◆ swapPage()

void ImageBase::swapPage ( char *  page,
size_t  pageNrElements,
DataType  datatype,
int  swap = 1 
)

Swap an entire page input pointer char *

Definition at line 331 of file xmipp_image_base.cpp.

332 {
333  size_t datatypesize = gettypesize(datatype);
334 #ifdef DEBUG
335 
336  std::cerr<<"DEBUG swapPage: Swapping image data with swap= "
337  << swap<<" datatypesize= "<<datatypesize
338  << " pageNrElements " << pageNrElements
339  << " datatype " << datatype
340  <<std::endl;
341  ;
342 #endif
343 
344  // Swap bytes if required
345  if ( swap == 1 )
346  {
347  if ( datatype >= DT_CShort )
348  datatypesize /= 2;
349  for ( size_t i = 0; i < pageNrElements; i += datatypesize )
350  swapbytes(page+i, datatypesize);
351  }
352  else if ( swap > 1 )
353  {
354  for (size_t i=0; i<pageNrElements; i+=swap )
355  swapbytes(page+i, swap);
356  }
357 }
void swapbytes(char *v, unsigned long n)
#define i
DataType datatype() const
size_t gettypesize(DataType type)
Returns memory size of datatype.

◆ tilt()

double ImageBase::tilt ( const size_t  n = 0) const

Get Tilt angle

std::cout << "Second Euler angle " << I.tilt() << std::endl;

Definition at line 378 of file xmipp_image_base.cpp.

379 {
380  double dummy = 0;
381  MD[n]->getValue(MDL_ANGLE_TILT, dummy);
382  return dummy;
383 }
Tilting angle of an image (double,degrees)
std::vector< std::unique_ptr< MDRow > > MD
double dummy
int * n

◆ weight()

double ImageBase::weight ( const size_t  n = 0) const

Get Weight

std::cout << "weight= " << I.weight() << std::endl;

Definition at line 443 of file xmipp_image_base.cpp.

444 {
445  double dummy = 1;
446  MD[n]->getValue(MDL_WEIGHT, dummy);
447  return dummy;
448 }
std::vector< std::unique_ptr< MDRow > > MD
double dummy
int * n
< Score 4 for volumes

◆ write()

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

General write function select_img= which slice should I replace overwrite = 0, append slice overwrite = 1 overwrite slice

Definition at line 292 of file xmipp_image_base.cpp.

294 {
295  const FileName &fname = (name.empty()) ? filename : name;
296 
297  if (mmapOnWrite && mappedSize > 0)
298  {
299  bool hasTempFile = !tempFilename.empty();
300  if (hasTempFile && fname.isInStack())
301  mmapOnWrite = !(mmapOnRead = true); // We change mmap mode from write to read to allow writing the image into a stack.
302  else
303  {
304  if (_swapWrite > 0)
305  REPORT_ERROR(ERR_ARG_INCORRECT, "Cannot swap endianness on writing if file is already mapped.");
306  munmapFile();
307  if (hasTempFile && std::rename(tempFilename.c_str(), fname.c_str()) != 0)
308  REPORT_ERROR(ERR_IO, formatString("Error renaming file '%s' to '%s'.", tempFilename.c_str(), fname.c_str()));
309  return;
310  }
311  }
312  // Swap the endianness of the image file when writing
313  swapWrite = _swapWrite;
314 
315  /* If the filename is in stack we will suppose you want to write this,
316  * even if you have not set the flags to.
317  */
318  if ( fname.isInStack() && mode == WRITE_OVERWRITE)
319  {
320  isStack = true;
322  }
323  // else if (!isStack && mode != WRITE_OVERWRITE)
324  // mode = WRITE_OVERWRITE;
325 
326  hFile = openFile(fname, mode);
327  _write(fname, hFile, select_img, isStack, mode, castMode);
328  closeFile(hFile);
329 }
virtual void munmapFile()=0
ImageFHandler * openFile(const FileName &name, int mode=WRITE_READONLY) const
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
FileName tempFilename
ImageFHandler * hFile
Input/Output general error.
Definition: xmipp_error.h:134
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
Incorrect argument received.
Definition: xmipp_error.h:113
void mode
size_t mappedSize
String formatString(const char *format,...)
FileName filename
bool isInStack() const

◆ writeData()

virtual void ImageBase::writeData ( FILE *  fimg,
size_t  offset,
DataType  wDType,
size_t  datasize_n,
CastWriteMode  castMode = CW_CAST 
)
protectedpure virtual

Write the raw date after a data type casting.

◆ writeEM()

int ImageBase::writeEM ( size_t  select_img = ALL_IMAGES,
bool  isStack = false,
int  mode = WRITE_OVERWRITE 
)
protected

Write image to EM file format

Parameters
select_imgNumber of selected image to write
isStackForce to write as stack if possible
modeWrite file type: overwrite, replace, append....
Returns

Definition at line 148 of file rwEM.cpp.

149 {
150  REPORT_ERROR(ERR_IO_NOWRITE, "ERROR: writeEM is not implemented.");
151  return(-1);
152 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Couldn&#39;t write to file.
Definition: xmipp_error.h:140

◆ writeJPEG()

int ImageBase::writeJPEG ( size_t  select_img,
bool  isStack = false,
int  mode = WRITE_OVERWRITE,
String  bitDepth = "",
CastWriteMode  castMode = CW_CONVERT 
)
protected

Definition at line 130 of file rwJPEG.cpp.

131 {
132  if (isComplexT())
133  {
134  REPORT_ERROR(ERR_TYPE_INCORRECT,"rwJPEG: Complex images are not supported by JPEG format.");
135  return 0;
136  }
137 
138  ArrayDim aDim;
139  mdaBase->getDimensions(aDim);
140 
141  // Volumes are not supported
142  if (aDim.zdim > 1)
143  REPORT_ERROR(ERR_MULTIDIM_DIM, "rwJPEG: volumes are not supported.");
144 
145  //Selection of output datatype
146  DataType myTypeID = myT();
147 
148  if (mmapOnWrite)
149  {
150  /* As we cannot mmap a JPEG File, when this option is passed we are going to mmap
151  * the multidimarray of Image
152  */
153  mmapOnWrite = false;
154  dataMode = DATA;
155  MDMainHeader.setValue(MDL_DATATYPE,(int) myTypeID);
156 
157  if (aDim.nzyxdim*gettypesize(myTypeID) > tiff_map_min_size)
158  mdaBase->setMmap(true);
159 
160  // Allocate memory for image data (Assume xdim, ydim, zdim and ndim are already set
161  //if memory already allocated use it (no resize allowed)
162 
164 
165  return 0;
166  }
167 
168  jpeg_compress_struct cinfo;
169  jpeg_error_mgr jerr;
170 
171  // struct jpeg_destination_mgr dmgr;
172  //
173  // /* create our in-memory output buffer to hold the jpeg */
174  // JOCTET * out_buffer = new JOCTET[aDim.xdim * aDim.ydim];
175  //
176  // /* here is the magic */
177  // dmgr.init_destination = init_buffer;
178  // dmgr.empty_output_buffer = empty_buffer;
179  // dmgr.term_destination = term_buffer;
180  // dmgr.next_output_byte = out_buffer;
181  // dmgr.free_in_buffer = aDim.xdim * aDim.ydim;
182 
183  cinfo.err = jpeg_std_error(&jerr);
184  jpeg_create_compress(&cinfo);
185 
186  jpeg_stdio_dest(&cinfo, fimg);
187 
188  /* Set JPEG image properties */
189  cinfo.image_width = aDim.xdim; /* image width and height, in pixels */
190  cinfo.image_height = aDim.ydim;
191  cinfo.input_components = 1; /* # of color components per pixel */
192  cinfo.in_color_space = JCS_GRAYSCALE; /* colorspace of input image */
193 
194  jpeg_set_defaults(&cinfo);
195 
196  jpeg_start_compress(&cinfo, TRUE);
197 
198  JSAMPROW row_pointer[1]; /* pointer to a single row */
199  row_pointer[0] = new unsigned char [aDim.xdim];
200  char * buffer = (char*) row_pointer[0];
201  double min0, max0;
202  mdaBase->computeDoubleMinMaxRange(min0, max0, 0, aDim.xdim*aDim.ydim);
203 
204 
205  while (cinfo.next_scanline < cinfo.image_height)
206  {
207  getCastConvertPageFromT((cinfo.next_scanline)*cinfo.image_width, buffer,
208  DT_UChar, cinfo.image_width, min0, max0, castMode);
209 
210  jpeg_write_scanlines(&cinfo, row_pointer, 1);
211  }
212 
213  jpeg_finish_compress(&cinfo);
214  jpeg_destroy_compress(&cinfo);
215  delete[] row_pointer[0];
216 
217  // fwrite(out_buffer, cinfo.dest->next_output_byte - out_buffer,1 ,fimg);
218 
219  return(0);
220 }
size_t xdim
DataMode dataMode
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
virtual void coreAllocateReuse()=0
HBITMAP buffer
Definition: svm-toy.cpp:37
void setValue(const MDObject &object) override
if read from file original image datatype, this is an struct defined in image
virtual void computeDoubleMinMaxRange(double &minval, double &maxval, size_t offset, size_t size) const =0
size_t nzyxdim
size_t zdim
const size_t tiff_map_min_size
void setMmap(bool mmap)
virtual bool isComplexT() const =0
DataType
MDRowVec MDMainHeader
virtual void getCastConvertPageFromT(size_t offset, char *page, DataType datatype, size_t pageSize, double min0, double max0, CastWriteMode castMode=CW_CONVERT) const =0
#define TRUE
Definition: defines.h:25
size_t ydim
Incorrect MultidimArray dimensions.
Definition: xmipp_error.h:173
virtual DataType myT() const =0
Incorrect type received.
Definition: xmipp_error.h:190
MultidimArrayBase * mdaBase
size_t gettypesize(DataType type)
Returns memory size of datatype.
void getDimensions(size_t &Xdim, size_t &Ydim, size_t &Zdim, size_t &Ndim) const

◆ writePageAsDatatype()

virtual void ImageBase::writePageAsDatatype ( FILE *  fimg,
DataType  datatype,
size_t  datasize_n 
)
pure virtual

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.

Implemented in Image< T >, Image< double >, Image< float >, Image< int >, Image< unsigned int >, Image< short int >, Image< unsigned char >, Image< char >, and Image< unsigned short int >.

◆ writePIF()

int ImageBase::writePIF ( size_t  select_img = ALL_IMAGES,
bool  isStack = false,
int  mode = WRITE_OVERWRITE 
)
protected

Write image to PIF file format

Parameters
select_imgNumber of selected image to write
isStackForce to write as stack if possible
modeWrite file type: overwrite, replace, append....
Returns

Definition at line 161 of file rwPIF.cpp.

162 {
163  REPORT_ERROR(ERR_IO_NOWRITE, "ERROR: writePIF is not implemented.");
164  return(-1);
165 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Couldn&#39;t write to file.
Definition: xmipp_error.h:140

◆ Xoff()

double ImageBase::Xoff ( const size_t  n = 0) const

Get Xoff

std::cout << "Origin offset in X " << I.Xoff() << std::endl;

Definition at line 404 of file xmipp_image_base.cpp.

405 {
406  double dummy = 0;
407  MD[n]->getValue(MDL_SHIFT_X, dummy);
408  return dummy;
409 }
Shift for the image in the X axis (double)
std::vector< std::unique_ptr< MDRow > > MD
double dummy
int * n

◆ Yoff()

double ImageBase::Yoff ( const size_t  n = 0) const

Get Yoff

std::cout << "Origin offset in Y " << I.Yoff() << std::endl;

Definition at line 417 of file xmipp_image_base.cpp.

418 {
419  double dummy = 0;
420  MD[n]->getValue(MDL_SHIFT_Y, dummy);
421  return dummy;
422 }
std::vector< std::unique_ptr< MDRow > > MD
double dummy
Shift for the image in the Y axis (double)
int * n

◆ Zoff()

double ImageBase::Zoff ( const size_t  n = 0) const

Get Zoff

std::cout << "Origin offset in Z " << I.Zoff() << std::endl;

Definition at line 430 of file xmipp_image_base.cpp.

431 {
432  double dummy = 0;
433  MD[n]->getValue(MDL_SHIFT_Z, dummy);
434  return dummy;
435 }
std::vector< std::unique_ptr< MDRow > > MD
double dummy
Shift for the image in the Z axis (double)
int * n

Friends And Related Function Documentation

◆ operator<<

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

Show ImageBase

Show image properties

Definition at line 1121 of file xmipp_image_base.cpp.

1122 {
1123  o << std::endl;
1124  DataType * fileDT = NULL;
1125  if (!I.filename.empty())
1126  {
1127  o << "--- File information ---" << std::endl;
1128  o << "Filename : " << I.filename << std::endl;
1129  o << "Endianess : ";
1130  if (I.swap^IsLittleEndian())
1131  o << "Little" << std::endl;
1132  else
1133  o << "Big" << std::endl;
1134 
1135  o << "Reversed : ";
1136  if (I.swap)
1137  o << "True" << std::endl;
1138  else
1139  o << "False" << std::endl;
1140  fileDT = new DataType;
1141  *fileDT = I.datatype();
1142  o << "Data type : " << datatype2StrLong(*fileDT) << std::endl;
1143  o << "Data offset : " << I.offset << std::endl;
1144  }
1145 
1146  o << "--- Image information ---" << std::endl;
1147 
1148  DataType myDT = I.myT();
1149  if ((fileDT == NULL || myDT != *fileDT) && I.dataMode >= DATA )
1150  o << "Memory datatype: " << datatype2StrLong(I.myT()) << std::endl;
1151  o << "Image type : ";
1152  if (I.isComplex())
1153  o << "Fourier-space image" << std::endl;
1154  else
1155  o << "Real-space image" << std::endl;
1156 
1157  delete fileDT;
1158 
1159  size_t xdim, ydim, zdim, ndim;
1160  I.getDimensions(xdim, ydim, zdim, ndim);
1161  o << "Dimensions : " << ndim << " x " << zdim << " x " << ydim << " x " << xdim;
1162  o << " ((N)Objects x (Z)Slices x (Y)Rows x (X)Columns)" << std::endl;
1163 
1164  double sampling;
1166  if (sampling > 0)
1167  {
1168  o << "Sampling rate : " << std::endl;
1169  o << " X-rate (Angstrom/pixel) = " << sampling << std::endl;
1171  o << " Y-rate (Angstrom/pixel) = " << sampling << std::endl;
1173  o << " Z-rate (Angstrom/pixel) = " << sampling << std::endl;
1174  }
1175 
1176  std::stringstream oGeo;
1177 
1179  {
1180  oGeo << "Euler angles : " << std::endl;
1181  oGeo << " Phi (rotation around Z axis) = " << I.rot() << std::endl;
1182  oGeo << " Theta (tilt, second rotation around new Y axis) = " << I.tilt() << std::endl;
1183  oGeo << " Psi (third rotation around new Z axis) = " << I.psi() << std::endl;
1184  }
1186  {
1187  oGeo << "Origin Offsets : " << std::endl;
1188  oGeo << " Xoff (origin offset in X-direction) = " << I.Xoff() << std::endl;
1189  oGeo << " Yoff (origin offset in Y-direction) = " << I.Yoff() << std::endl;
1190  oGeo << " Zoff (origin offset in Z-direction) = " << I.Zoff() << std::endl;
1191  }
1193  oGeo << "Scale : " <<I.scale() << std::endl;
1195  oGeo << "Weight : " << I.weight() << std::endl;
1197  oGeo << "Flip : " << I.flip() << std::endl;
1198 
1199  if (!oGeo.str().empty())
1200  o << "--- Geometry ---" << std::endl << oGeo.str();
1201 
1202  return o;
1203 }
Rotation angle of an image (double,degrees)
sampling rate in A/pixel (double)
sampling rate in A/pixel (double)
DataMode dataMode
sampling rate in A/pixel (double)
bool IsLittleEndian(void)
double psi(const size_t n=0) const
double Zoff(const size_t n=0) const
Shift for the image in the X axis (double)
const T & getValueOrDefault(MDLabel label, const T &def) const
bool isComplex() const
double rot(const size_t n=0) const
double weight(const size_t n=0) const
T & getValue(MDLabel label)
double tilt(const size_t n=0) const
Flip the image? (bool)
#define sampling
double Yoff(const size_t n=0) const
double scale(const size_t n=0) const
DataType
scaling factor for an image or volume (double)
std::string datatype2StrLong(DataType datatype)
MDRowVec MDMainHeader
bool individualContainsLabel(MDLabel label) const
DataType datatype() const
double Xoff(const size_t n=0) const
FileName filename
bool flip(const size_t n=0) const
virtual DataType myT() const =0
< Score 4 for volumes
void getDimensions(size_t &Xdim, size_t &Ydim, size_t &Zdim, size_t &Ndim) const

Member Data Documentation

◆ _exists

bool ImageBase::_exists
protected

Definition at line 263 of file xmipp_image_base.h.

◆ aDimFile

ArrayDim ImageBase::aDimFile
protected

Definition at line 255 of file xmipp_image_base.h.

◆ axisOrder

std::array<int,4> ImageBase::axisOrder
protected

Definition at line 260 of file xmipp_image_base.h.

◆ dataFName

FileName ImageBase::dataFName
protected

Definition at line 249 of file xmipp_image_base.h.

◆ dataMode

DataMode ImageBase::dataMode
protected

Definition at line 256 of file xmipp_image_base.h.

◆ defaultAxisOrder

constexpr std::array<int,4> ImageBase::defaultAxisOrder = {0,1,2,3}
staticprotected

Definition at line 271 of file xmipp_image_base.h.

◆ fhdf5

hid_t ImageBase::fhdf5
protected

Definition at line 253 of file xmipp_image_base.h.

◆ fhed

FILE* ImageBase::fhed
protected

Definition at line 251 of file xmipp_image_base.h.

◆ filename

FileName ImageBase::filename
protected

Definition at line 247 of file xmipp_image_base.h.

◆ fimg

FILE* ImageBase::fimg
protected

Definition at line 250 of file xmipp_image_base.h.

◆ hFile

ImageFHandler* ImageBase::hFile
protected

Definition at line 254 of file xmipp_image_base.h.

◆ mappedOffset

size_t ImageBase::mappedOffset
protected

Definition at line 268 of file xmipp_image_base.h.

◆ mappedSize

size_t ImageBase::mappedSize
protected

Definition at line 267 of file xmipp_image_base.h.

◆ MD

std::vector<std::unique_ptr<MDRow> > ImageBase::MD

Definition at line 242 of file xmipp_image_base.h.

◆ mdaBase

MultidimArrayBase* ImageBase::mdaBase

Definition at line 241 of file xmipp_image_base.h.

◆ MDMainHeader

MDRowVec ImageBase::MDMainHeader

Definition at line 244 of file xmipp_image_base.h.

◆ mFd

int ImageBase::mFd
protected

Definition at line 266 of file xmipp_image_base.h.

◆ mmapOnRead

bool ImageBase::mmapOnRead
protected

Definition at line 264 of file xmipp_image_base.h.

◆ mmapOnWrite

bool ImageBase::mmapOnWrite
protected

Definition at line 265 of file xmipp_image_base.h.

◆ offset

size_t ImageBase::offset
protected

Definition at line 257 of file xmipp_image_base.h.

◆ replaceNsize

size_t ImageBase::replaceNsize
protected

Definition at line 262 of file xmipp_image_base.h.

◆ swap

int ImageBase::swap
protected

Definition at line 258 of file xmipp_image_base.h.

◆ swapWrite

int ImageBase::swapWrite
protected

Definition at line 259 of file xmipp_image_base.h.

◆ tempFilename

FileName ImageBase::tempFilename
protected

Definition at line 248 of file xmipp_image_base.h.

◆ tif

TIFF* ImageBase::tif
protected

Definition at line 252 of file xmipp_image_base.h.

◆ transform

TransformType ImageBase::transform
protected

Definition at line 261 of file xmipp_image_base.h.

◆ virtualOffset

size_t ImageBase::virtualOffset
protected

Definition at line 269 of file xmipp_image_base.h.


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