QXRD  0.11.16
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
QcepImageData< T > Class Template Reference

#include <qcepimagedata-ptr.h>

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

Public Member Functions

 QcepImageData (QcepSettingsSaverWPtr saver, int width, int height, T def, QcepObject *parent)
 
virtual ~QcepImageData ()
 
bool readImage (QString filename)
 
void resize (int width, int height)
 
void clear ()
 
void fill (double val)
 
double getImageData (int x, int y) const
 
QVector< double > getImageData (int x0, int y0, int x1, int y1) const
 
void setImageData (int x, int y, double v)
 
virtual void saveData (QString &name, QString filter, Overwrite canOverwrite=NoOverwrite)
 
void saveTIFFData (QString name)
 
double minValue () const
 
double maxValue () const
 
QPointF percentileRange (double lowpct, double highpct)
 
double sumInRectangle (QRectF rect)
 
double averageInRectangle (QRectF rect)
 
double minInRectangle (QRectF rect)
 
double maxInRectangle (QRectF rect)
 
double sumInEllipse (QRectF rect)
 
double averageInEllipse (QRectF rect)
 
double minInEllipse (QRectF rect)
 
double maxInEllipse (QRectF rect)
 
double sumInPeak (QRectF rect)
 
template<typename T2 >
void subtractDark (const QSharedPointer< QcepImageData< T2 > > dark)
 
void calculateRange ()
 
void calculateRangeInCircle ()
 
void dumpPixels (int x0, int y0, int x1, int y1)
 
T * data ()
 
value (int x, int y) const
 
value (double x, double y) const
 
void setValue (int x, int y, T val)
 
void addValue (int x, int y, T val)
 
void subtractValue (int x, int y, T val)
 
void multiplyValue (int x, int y, T val)
 
void divideValue (int x, int y, T val)
 
defaultValue () const
 
void setDefaultValue (T def)
 
QString rawFileName ()
 
template<typename T2 >
void copyImage (QSharedPointer< QcepImageData< T2 > > dest)
 
template<typename T2 >
void copyFrom (const QSharedPointer< QcepImageData< T2 > > img)
 
template<typename T2 >
void accumulateImage (QSharedPointer< QcepImageData< T2 > > image)
 
template<typename T2 >
void add (QSharedPointer< QcepImageData< T2 > > image)
 
template<typename T2 >
void subtract (QSharedPointer< QcepImageData< T2 > > image)
 
template<typename T2 >
void multiply (QSharedPointer< QcepImageData< T2 > > image)
 
template<typename T2 >
void divide (QSharedPointer< QcepImageData< T2 > > image)
 
void setMask (QcepMaskDataPtr mask, QcepMaskDataPtr overflow)
 
QcepMaskDataPtr mask () const
 
QcepMaskDataPtr overflow () const
 
double correlate (QSharedPointer< QcepImageData< T > > image, int dx, int dy, int mx, int my)
 
void shiftImage (QSharedPointer< QcepImageData< T > > image, double dx, double dy)
 
findMin () const
 
findMax () const
 
double findAverage () const
 
void correctBadBackgroundSubtraction (QcepDoubleImageDataPtr dark, int nImgExposures, int nDarkExposures)
 
template<>
void saveTIFFData (QString name)
 
- Public Member Functions inherited from QcepImageDataBase
 QcepImageDataBase (QcepSettingsSaverWPtr saver, int width, int height, int size, QcepObject *parent)
 
virtual ~QcepImageDataBase ()
 
QString get_DateString () const
 
void set_DateString (QString)
 
QString get_DataTypeName () const
 
void set_DataTypeName (QString)
 
void copyProperties (QcepImageDataBase *dest)
 
void copyPropertiesFrom (QSharedPointer< QcepImageDataBase > src)
 
void loadMetaData ()
 
void saveMetaData ()
 
void saveMetaData (QString name)
 
void saveTextData (QString name, QString sep, bool transp=false)
 
void setDefaultFileName (QString path)
 
virtual QString fileFormatFilterString ()
 
QString fileFormatTIFF ()
 
QString fileFormatTabDelimited ()
 
QString fileFormatTransposedTabDelimited ()
 
QString fileFormatCSV ()
 
QString fileFormatTransposedCSV ()
 
QMutex * mutex ()
 
- Public Member Functions inherited from QcepDataObject
 QcepDataObject (QcepSettingsSaverWPtr saver, QString name, int byteSize, QcepObject *parent)
 
virtual ~QcepDataObject ()
 
QcepSettingsSaverWPtr saver ()
 
virtual int childCount () const
 
virtual QcepDataObjectPtr item (int n)
 
virtual QcepDataObjectPtr item (QString nm)
 
virtual void setParentItem (QcepDataGroupWPtr parent)
 
virtual int indexInParent () const
 
virtual int rowCount () const
 
virtual int columnCount () const
 
virtual QVariant columnData (int col) const
 
- Public Member Functions inherited from QcepObject
 QcepObject (QString name, QcepObject *parent)
 
virtual ~QcepObject ()
 
virtual void writeSettings (QSettings *set, QString section)
 
virtual void readSettings (QSettings *set, QString section)
 
QString get_Name () const
 
void set_Name (QString name)
 

Static Public Member Functions

static QSharedPointer< QcepImageData< T > > newImage (QcepSettingsSaverWPtr saver, QString name, int width, int height, QcepObject *parent)
 
static QScriptValue toScriptValue (QScriptEngine *engine, const QSharedPointer< QcepImageData< T > > &data)
 
static void fromScriptValue (const QScriptValue &obj, QSharedPointer< QcepImageData< T > > &data)
 
- Static Public Member Functions inherited from QcepImageDataBase
static double secondsSinceEpoch ()
 
- Static Public Member Functions inherited from QcepDataObject
static QcepDataObjectPtr newDataObject (QcepSettingsSaverWPtr saver, QString name, QcepObject *parent)
 
static QScriptValue toScriptValue (QScriptEngine *engine, const QcepDataObjectPtr &data)
 
static void fromScriptValue (const QScriptValue &obj, QcepDataObjectPtr &data)
 
static int allocatedObjects ()
 
static int deletedObjects ()
 
- Static Public Member Functions inherited from QcepObject
static int allocatedObjects ()
 
static int deletedObjects ()
 
static QSet< QcepObject * > allocatedObjectsSet ()
 
static QString addSlashes (QString str)
 

Protected Attributes

QVector< T > m_Image
 
m_MinValue
 
m_MaxValue
 
m_Default
 
QcepMaskDataPtr m_Mask
 
QcepMaskDataPtr m_Overflow
 
- Protected Attributes inherited from QcepImageDataBase
int m_ImageCounter
 
QcepSettingsSaverWPtr m_Saver
 

Additional Inherited Members

- Public Types inherited from QcepImageDataBase
enum  {
  UndefinedData, Raw16Data, Raw32Data, DarkData,
  MaskData, SubtractedData, GainData, BadPixelsData
}
 
- Public Types inherited from QcepDataObject
enum  Overwrite { NoOverwrite, CanOverwrite }
 
- Public Slots inherited from QcepImageDataBase
virtual QString description () const
 
void printMessage (QString msg, QDateTime ts=QDateTime::currentDateTime()) const
 
double hValue (int n) const
 
double vValue (int n) const
 
- Public Slots inherited from QcepDataObject
virtual QString description () const
 
QString metaTypeName (int id) const
 
QString pathName () const
 
QcepDataGroupPtr rootItem ()
 
virtual QcepDataGroupPtr parentItem () const
 
- Public Slots inherited from QcepObject
virtual void printLine (QString line)
 
virtual void printMessage (QString msg, QDateTime dt=QDateTime::currentDateTime()) const
 
virtual void criticalMessage (QString msg, QDateTime ts=QDateTime::currentDateTime()) const
 
virtual void statusMessage (QString msg, QDateTime ts=QDateTime::currentDateTime()) const
 
virtual QString settingsScript ()
 
QString scriptValueLiteral (QVariant v)
 
- Signals inherited from QcepDataObject
void dataObjectChanged ()
 
- Protected Member Functions inherited from QcepDataObject
void mkPath (QString filePath)
 
QString uniqueFileName (QString name)
 
- Properties inherited from QcepImageDataBase
int width
 
int height
 
double hStart
 
double hStep
 
double vStart
 
double vStep
 
QString hLabel
 
QString hUnits
 
QString vLabel
 
QString vUnits
 
int dataType
 
QString dataTypeName
 
QString fileBase
 
QString title
 
int readoutMode
 
double exposureTime
 
int summedExposures
 
int imageSequenceNumber
 
int imageNumber
 
int phaseNumber
 
int nPhases
 
QDateTime dateTime
 
QString dateString
 
double timeStamp
 
int hBinning
 
int vBinning
 
double cameraGain
 
int triggered
 
QString userComment1
 
QString userComment2
 
QString userComment3
 
QString userComment4
 
QcepDoubleList normalization
 
QcepDoubleList extraInputs
 
bool used
 
- Properties inherited from QcepDataObject
QString type
 
quint64 byteSize
 
QString creator
 
QString version
 
QString qtVersion
 
QString description
 
QString fileName
 
int objectSaved
 
- Properties inherited from QcepObject
QString name
 

Detailed Description

template<typename T>
class QcepImageData< T >

Definition at line 7 of file qcepimagedata-ptr.h.

Constructor & Destructor Documentation

template<typename T>
QcepImageData< T >::QcepImageData ( QcepSettingsSaverWPtr  saver,
int  width,
int  height,
def,
QcepObject parent 
)

Definition at line 338 of file qcepimagedata.cpp.

References DEBUG_CONSTRUCTORS, HEXARG, QcepImageData< T >::m_Image, QcepObject::name, QcepImageDataBase::printMessage(), and qcepDebug().

339  : QcepImageDataBase(saver, width, height, width*height*sizeof(T), parent),
340  // m_Image(width*height, def),
342  m_MinValue(0),
343  m_MaxValue(0),
344  m_Default(def),
345  m_Mask(NULL),
346  m_Overflow(NULL)
347 {
349  printMessage(tr("QcepImageData<%1>::QcepImageData %2")
350  .arg(typeid(T).name())
351  .HEXARG(this));
352  }
353 
354  if (def) {
355  m_Image.fill(def);
356  }
357 
358  set_Type("Image Data");
359 }
QcepMaskDataPtr m_Overflow
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
QcepImageDataBase(QcepSettingsSaverWPtr saver, int width, int height, int size, QcepObject *parent)
QcepMaskDataPtr m_Mask
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const
#define HEXARG(a)
Definition: qcepdebug.h:50
QVector< T > m_Image
QString name
Definition: qcepobject.h:49
QcepSettingsSaverWPtr saver()

Here is the call graph for this function:

template<typename T >
QcepImageData< T >::~QcepImageData ( )
virtual

Definition at line 362 of file qcepimagedata.cpp.

References DEBUG_CONSTRUCTORS, HEXARG, QcepObject::name, QcepImageDataBase::printMessage(), and qcepDebug().

363 {
365  printMessage(tr("QcepImageData<%1>::~QcepImageData %2")
366  .arg(typeid(T).name())
367  .HEXARG(this));
368  }
369 }
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const
#define HEXARG(a)
Definition: qcepdebug.h:50
QString name
Definition: qcepobject.h:49

Here is the call graph for this function:

Member Function Documentation

template<typename T >
template<typename T2 >
template void QcepImageData< T >::accumulateImage< double > ( QSharedPointer< QcepImageData< T2 > >  image)

Definition at line 770 of file qcepimagedata.cpp.

References QcepImageData< T >::addValue(), and QcepImageData< T >::data().

771 {
772  if (image) {
773  int ncols = this -> get_Width();
774  int nrows = this -> get_Height();
775 
776  this->prop_SummedExposures()->incValue(image->get_SummedExposures());
777 
778  if (ncols == image->get_Width() && nrows == image->get_Height()) {
779  int npix = ncols*nrows;
780 
781  T *srcp = this -> data();
782  T2 *destp = image -> data();
783 
784  for (int i=0; i<npix; i++) {
785  *srcp++ += *destp++;
786  }
787  } else {
788  for (int row=0; row<nrows; row++) {
789  for (int col=0; col<ncols; col++) {
790  this -> addValue(col, row, image->value(col, row));
791  }
792  }
793 
794  QcepDoubleList norm = this->get_Normalization();
795  QcepDoubleList extra = this->get_ExtraInputs();
796 
797  QcepDoubleList norm2 = image->get_Normalization();
798  QcepDoubleList extra2= image->get_ExtraInputs();
799 
800  for (int i=0; i<norm.count(); i++) {
801  norm[i] += norm2.value(i);
802  }
803 
804  for (int i=0; i<extra.count(); i++) {
805  extra[i] += extra2.value(i);
806  }
807 
808  this->set_Normalization(norm);
809  this->set_ExtraInputs(extra);
810  }
811  }
812 }
void addValue(int x, int y, T val)
QList< double > QcepDoubleList
Definition: qcepmacros.h:28

Here is the call graph for this function:

template<typename T >
template<typename T2 >
template void QcepImageData< T >::add< double > ( QSharedPointer< QcepImageData< T2 > >  image)

Definition at line 816 of file qcepimagedata.cpp.

References QcepImageData< T >::addValue(), and QcepImageData< T >::data().

817 {
818  if (image) {
819  int ncols = this -> get_Width();
820  int nrows = this -> get_Height();
821 
822  this->prop_SummedExposures()->incValue(image->get_SummedExposures());
823 
824  if (ncols == image->get_Width() && nrows == image->get_Height()) {
825  int npix = ncols*nrows;
826 
827  T *srcp = this -> data();
828  T2 *destp = image -> data();
829 
830  for (int i=0; i<npix; i++) {
831  *srcp++ += *destp++;
832  }
833  } else {
834  for (int row=0; row<nrows; row++) {
835  for (int col=0; col<ncols; col++) {
836  this -> addValue(col, row, image->value(col, row));
837  }
838  }
839  }
840  }
841 }
void addValue(int x, int y, T val)

Here is the call graph for this function:

template<typename T>
void QcepImageData< T >::addValue ( int  x,
int  y,
val 
)

Definition at line 466 of file qcepimagedata.cpp.

References QcepImageData< T >::m_Image.

Referenced by QcepImageData< T >::accumulateImage(), and QcepImageData< T >::add().

467 {
468  if (x >= 0 && x < get_Width() && y >= 0 && y < get_Height()) {
469  m_Image[(get_Height()-y-1)*get_Width()+x] += val;
470  }
471 }
QVector< T > m_Image

Here is the caller graph for this function:

template<typename T >
double QcepImageData< T >::averageInEllipse ( QRectF  rect)
virtual

Implements QcepImageDataBase.

Definition at line 1583 of file qcepimagedata.cpp.

References QcepImageData< T >::m_Mask, and QcepImageData< T >::value().

1584 {
1585  QPointF c = rect.center();
1586  double a = rect.width()/2;
1587  double b = rect.height()/2;
1588 
1589  int bt = qRound(rect.bottom());
1590  int tp = qRound(rect.top());
1591 
1592  int np = 0;
1593  double sum = 0;
1594 
1595  for (int row=tp; row<=bt; row++) {
1596  double y=row - c.y();
1597  double xx = a*sqrt(1 - pow(y/b,2));
1598  int x1 = qRound(c.x() - xx);
1599  int x2 = qRound(c.x() + xx);
1600 
1601  for (int col=x1; col<=x2; col++) {
1602  if (m_Mask == NULL || m_Mask->value(col, row)) {
1603  T val = value(col, row);
1604 
1605  if (val==val) {
1606  np++;
1607  sum += val;
1608  }
1609  }
1610  }
1611  }
1612 
1613  return sum/np;
1614 }
T value(int x, int y) const
QcepMaskDataPtr m_Mask

Here is the call graph for this function:

template<typename T >
double QcepImageData< T >::averageInRectangle ( QRectF  rect)
virtual

Implements QcepImageDataBase.

Definition at line 1430 of file qcepimagedata.cpp.

References QcepImageData< T >::m_Mask, and QcepImageData< T >::value().

1431 {
1432  int l = qRound(rect.left());
1433  int t = qRound(rect.top());
1434  int r = qRound(rect.right());
1435  int b = qRound(rect.bottom());
1436 
1437  if (l > r) {
1438  l = qRound(rect.right());
1439  r = qRound(rect.left());
1440  }
1441 
1442  if (b > t) {
1443  b = qRound(rect.top());
1444  t = qRound(rect.bottom());
1445  }
1446 
1447  int np = 0;
1448  double sum = 0;
1449 
1450  for (int row=b; row<=t; row++) {
1451  for (int col=l; col<=r; col++) {
1452  if (m_Mask == NULL || m_Mask->value(col, row)) {
1453  T val = value(col, row);
1454 
1455  if (val==val) {
1456  np++;
1457  sum += val;
1458  }
1459  }
1460  }
1461  }
1462 
1463  return sum/np;
1464 }
T value(int x, int y) const
QcepMaskDataPtr m_Mask

Here is the call graph for this function:

template<typename T >
void QcepImageData< T >::calculateRange ( )

Definition at line 510 of file qcepimagedata.cpp.

References QcepImageData< T >::m_Image, QcepImageData< T >::m_MaxValue, and QcepImageData< T >::m_MinValue.

511 {
512  T *img = m_Image.data();
513  int total = m_Image.count();
514  int first = true;
515 
516  m_MinValue = 0;
517  m_MaxValue = 0;
518 
519  for (int i = 0; i<total; i++) {
520  T val = img[i];
521 
522  if (val == val) { // NaN test...
523  if (first) {
524  m_MaxValue = val;
525  m_MinValue = val;
526  first = false;
527  } else if (val > m_MaxValue) {
528  m_MaxValue = val;
529  } else if (val < m_MinValue) {
530  m_MinValue = val;
531  }
532  }
533  }
534 }
QVector< T > m_Image
template<typename T >
void QcepImageData< T >::calculateRangeInCircle ( )

Definition at line 537 of file qcepimagedata.cpp.

References QcepImageData< T >::m_MaxValue, QcepImageData< T >::m_MinValue, and QcepImageData< T >::value().

538 {
539  bool first = 1;
540 
541  double cx = get_Width()/2, cy = get_Height()/2;
542 
543  m_MinValue = 0;
544  m_MaxValue = 0;
545 
546  for (int y=0; y<get_Height(); y++) {
547  double dy = (((double)y)-cy)/cy;
548  double dx = sqrt(1-dy*dy);
549  int x0 = (int) (cx-dx*cx);
550  int x1 = (int) (cx+dx*cx);
551 
552  for (int x=x0; x<x1; x++) {
553  T val = value(x,y);
554 
555  if (val == val) { // NaN test...
556  if (first) {
557  m_MinValue = val;
558  m_MaxValue = val;
559  first = false;
560  } else if (val > m_MaxValue) {
561  m_MaxValue = val;
562  } else if (val < m_MinValue) {
563  m_MinValue = val;
564  }
565  }
566  }
567  }
568 }
T value(int x, int y) const

Here is the call graph for this function:

template<typename T >
void QcepImageData< T >::clear ( )
virtual

Implements QcepImageDataBase.

Definition at line 612 of file qcepimagedata.cpp.

References QcepImageData< T >::m_Default, and QcepImageData< T >::m_Image.

613 {
614  m_Image.fill(m_Default);
615 }
QVector< T > m_Image
template<typename T >
template<typename T2 >
template void QcepImageData< T >::copyFrom< unsigned int > ( const QSharedPointer< QcepImageData< T2 > >  img)

Definition at line 748 of file qcepimagedata.cpp.

References QcepImageDataBase::copyPropertiesFrom(), QcepImageData< T >::data(), and QcepImageData< T >::resize().

749 {
750  if (img) {
751  int ncols = img -> get_Width();
752  int nrows = img -> get_Height();
753  int npix = ncols*nrows;
754 
755  this -> resize(ncols, nrows);
756 
757  this -> copyPropertiesFrom(img);
758 
759  T2 *srcp = img -> data();
760  T *destp = this -> data();
761 
762  for (int i=0; i<npix; i++) {
763  *destp++ = *srcp++;
764  }
765  }
766 }
void resize(int width, int height)
void copyPropertiesFrom(QSharedPointer< QcepImageDataBase > src)

Here is the call graph for this function:

template<typename T >
template<typename T2 >
void QcepImageData< T >::copyImage ( QSharedPointer< QcepImageData< T2 > >  dest)

Definition at line 726 of file qcepimagedata.cpp.

References QcepImageDataBase::copyProperties(), QcepImageData< T >::data(), and QcepImageData< T >::resize().

727 {
728  if (dest) {
729  int ncols = this -> get_Width();
730  int nrows = this -> get_Height();
731  int npix = ncols*nrows;
732 
733  dest -> resize(ncols, nrows);
734 
735  this -> copyProperties(dest.data());
736 
737  T *srcp = this -> data();
738  T2 *destp = dest -> data();
739 
740  for (int i=0; i<npix; i++) {
741  *destp++ = *srcp++;
742  }
743  }
744 }
void resize(int width, int height)
void copyProperties(QcepImageDataBase *dest)

Here is the call graph for this function:

template<typename T >
void QcepImageData< T >::correctBadBackgroundSubtraction ( QcepDoubleImageDataPtr  dark,
int  nImgExposures,
int  nDarkExposures 
)

Definition at line 1146 of file qcepimagedata.cpp.

References QcepImageData< T >::setValue(), and QcepImageData< T >::value().

1147 {
1148  int ncols = this -> get_Width();
1149  int nrows = this -> get_Height();
1150 
1151  double badRatio = ((double) this->get_SummedExposures())/((double) dark->get_SummedExposures());
1152  double goodRatio = ((double) nImgExposures)/((double) nDarkExposures);
1153 
1154  for (int row=0; row<nrows; row++) {
1155  for (int col=0; col<ncols; col++) {
1156  double darkValue = dark->value(col,row);
1157  double imgValue = this->value(col,row);
1158 
1159  imgValue += darkValue*badRatio;
1160  imgValue -= darkValue*goodRatio;
1161 
1162  this->setValue(col, row, imgValue);
1163  }
1164  }
1165 
1166  this->set_SummedExposures(nImgExposures);
1167 }
T value(int x, int y) const
void setValue(int x, int y, T val)

Here is the call graph for this function:

template<typename T>
double QcepImageData< T >::correlate ( QSharedPointer< QcepImageData< T > >  image,
int  dx,
int  dy,
int  mx,
int  my 
)

Definition at line 931 of file qcepimagedata.cpp.

References QcepImageData< T >::value().

932 {
933  double sum=0;
934 
935  if (image) {
936  int wd = this->get_Width();
937  int ht = this->get_Height();
938 
939  for (int y=my; y<ht-my; y++) {
940  for (int x=mx; x<wd-mx; x++) {
941  sum += this->value(x,y)*image->value(x+dx,y+dy);
942  }
943  }
944  }
945 
946  return sum;
947 }
T value(int x, int y) const

Here is the call graph for this function:

template<typename T >
T * QcepImageData< T >::data ( )
template<typename T >
T QcepImageData< T >::defaultValue ( ) const

Definition at line 618 of file qcepimagedata.cpp.

References QcepImageData< T >::m_Default.

619 {
620  return m_Default;
621 }
template<typename T >
template<typename T2 >
template void QcepImageData< T >::divide< double > ( QSharedPointer< QcepImageData< T2 > >  image)

Definition at line 903 of file qcepimagedata.cpp.

References QcepImageData< T >::data(), and QcepImageData< T >::divideValue().

904 {
905  if (image) {
906  int ncols = this -> get_Width();
907  int nrows = this -> get_Height();
908 
909  this->prop_SummedExposures()->incValue(image->get_SummedExposures());
910 
911  if (ncols == image->get_Width() && nrows == image->get_Height()) {
912  int npix = ncols*nrows;
913 
914  T *srcp = this -> data();
915  T2 *destp = image -> data();
916 
917  for (int i=0; i<npix; i++) {
918  *srcp++ /= *destp++;
919  }
920  } else {
921  for (int row=0; row<nrows; row++) {
922  for (int col=0; col<ncols; col++) {
923  this -> divideValue(col, row, image->value(col, row));
924  }
925  }
926  }
927  }
928 }
void divideValue(int x, int y, T val)

Here is the call graph for this function:

template<typename T>
void QcepImageData< T >::divideValue ( int  x,
int  y,
val 
)

Definition at line 490 of file qcepimagedata.cpp.

References QcepImageData< T >::m_Image.

Referenced by QcepImageData< T >::divide().

491 {
492  if (x >= 0 && x < get_Width() && y >= 0 && y < get_Height()) {
493  m_Image[(get_Height()-y-1)*get_Width()+x] /= val;
494  }
495 }
QVector< T > m_Image

Here is the caller graph for this function:

template<typename T >
void QcepImageData< T >::dumpPixels ( int  x0,
int  y0,
int  x1,
int  y1 
)

Definition at line 571 of file qcepimagedata.cpp.

References QcepImageData< T >::value().

572 {
573  for (int y=y0; y<y1; y++) {
574  for (int x=x0; x<x1; x++) {
575  printf("%g ", (double) value(x,y));
576  }
577  printf("\n");
578  }
579 }
T value(int x, int y) const

Here is the call graph for this function:

template<typename T >
void QcepImageData< T >::fill ( double  val)
virtual

Implements QcepImageDataBase.

Definition at line 444 of file qcepimagedata.cpp.

References QcepImageData< T >::m_Image.

445 {
446  m_Image.fill(val);
447 }
QVector< T > m_Image
template<typename T >
double QcepImageData< T >::findAverage ( ) const

Definition at line 1052 of file qcepimagedata.cpp.

References QcepImageData< T >::m_Mask, and QcepImageData< T >::value().

1053 {
1054  int ncols = this -> get_Width();
1055  int nrows = this -> get_Height();
1056  double npix = 0;
1057  double sum = 0;
1058 
1059  for (int row=0; row<nrows; row++) {
1060  for (int col=0; col<ncols; col++) {
1061  if (m_Mask == NULL || m_Mask->value(col,row)) {
1062  double val = this -> value(col, row);
1063 
1064  if (val==val) {
1065  npix += 1;
1066  sum += val;
1067  }
1068  }
1069  }
1070  }
1071 
1072  if (npix <= 0) {
1073  return 0;
1074  } else {
1075  return sum/npix;
1076  }
1077 }
T value(int x, int y) const
QcepMaskDataPtr m_Mask

Here is the call graph for this function:

template<typename T >
T QcepImageData< T >::findMax ( ) const

Definition at line 1024 of file qcepimagedata.cpp.

References QcepImageData< T >::m_Mask, and QcepImageData< T >::value().

Referenced by QcepImageData< T >::maxValue().

1025 {
1026  int ncols = this -> get_Width();
1027  int nrows = this -> get_Height();
1028  int first = true;
1029  T maxv = 0;
1030 
1031  for (int row=0; row<nrows; row++) {
1032  for (int col=0; col<ncols; col++) {
1033  if (m_Mask == NULL || m_Mask->value(col,row)) {
1034  T val = this -> value(col, row);
1035 
1036  if (val == val) {
1037  if (first) {
1038  maxv = val;
1039  first = false;
1040  } else if (val > maxv){
1041  maxv = val;
1042  }
1043  }
1044  }
1045  }
1046  }
1047 
1048  return maxv;
1049 }
T value(int x, int y) const
QcepMaskDataPtr m_Mask

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename T >
T QcepImageData< T >::findMin ( ) const

Definition at line 996 of file qcepimagedata.cpp.

References QcepImageData< T >::m_Mask, and QcepImageData< T >::value().

Referenced by QcepImageData< T >::minValue().

997 {
998  int ncols = this -> get_Width();
999  int nrows = this -> get_Height();
1000  int first = true;
1001  T minv = 0;
1002 
1003  for (int row=0; row<nrows; row++) {
1004  for (int col=0; col<ncols; col++) {
1005  if (m_Mask == NULL || m_Mask->value(col,row)) {
1006  T val = this->value(col, row);
1007 
1008  if (val == val) { // Skip NaNs
1009  if (first) {
1010  minv = val;
1011  first = false;
1012  } else if (val < minv){
1013  minv = val;
1014  }
1015  }
1016  }
1017  }
1018  }
1019 
1020  return minv;
1021 }
T value(int x, int y) const
QcepMaskDataPtr m_Mask

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename T>
void QcepImageData< T >::fromScriptValue ( const QScriptValue &  obj,
QSharedPointer< QcepImageData< T > > &  data 
)
static

Definition at line 1176 of file qcepimagedata.cpp.

References QcepImageData< T >::data().

1177 {
1178  QObject *qobj = obj.toQObject();
1179 
1180  if (qobj) {
1181  QcepDataObject *qdobj = qobject_cast<QcepDataObject*>(qobj);
1182 
1183  if (qdobj) {
1184  QcepDataObjectPtr p = qdobj->sharedFromThis();
1185 
1186  if (p) {
1187  QSharedPointer<QcepImageData<T> > cs = qSharedPointerDynamicCast< QcepImageData<T> >(p);
1188 
1189  if (cs) {
1190  data = cs;
1191  }
1192  }
1193  }
1194  }
1195 }
QSharedPointer< QcepDataObject > QcepDataObjectPtr

Here is the call graph for this function:

template<typename T >
double QcepImageData< T >::getImageData ( int  x,
int  y 
) const
virtual

Implements QcepImageDataBase.

Definition at line 432 of file qcepimagedata.cpp.

References QcepImageData< T >::value().

433 {
434  return this->value(x,y);
435 }
T value(int x, int y) const

Here is the call graph for this function:

template<typename T >
QVector< double > QcepImageData< T >::getImageData ( int  x0,
int  y0,
int  x1,
int  y1 
) const
virtual

Implements QcepImageDataBase.

Definition at line 418 of file qcepimagedata.cpp.

References QcepImageData< T >::value().

419 {
420  QVector<double> res;
421 
422  for (int y=y0; y<y1; y++) {
423  for (int x=x0; x<x1; x++) {
424  res << this->value(x,y);
425  }
426  }
427 
428  return res;
429 }
T value(int x, int y) const

Here is the call graph for this function:

template<typename T >
QcepMaskDataPtr QcepImageData< T >::mask ( ) const

Definition at line 972 of file qcepimagedata.cpp.

References QcepImageData< T >::m_Mask.

Referenced by QcepImageData< T >::setMask().

973 {
974  return m_Mask;
975 }
QcepMaskDataPtr m_Mask

Here is the caller graph for this function:

template<typename T >
double QcepImageData< T >::maxInEllipse ( QRectF  rect)
virtual

Implements QcepImageDataBase.

Definition at line 1655 of file qcepimagedata.cpp.

References QcepImageData< T >::m_Mask, and QcepImageData< T >::value().

1656 {
1657  QPointF c = rect.center();
1658  double a = rect.width()/2;
1659  double b = rect.height()/2;
1660 
1661  int bt = qRound(rect.bottom());
1662  int tp = qRound(rect.top());
1663 
1664  int first = true;
1665  double max = 0;
1666 
1667  for (int row=tp; row<=bt; row++) {
1668  double y=row - c.y();
1669  double xx = a*sqrt(1 - pow(y/b,2));
1670  int x1 = qRound(c.x() - xx);
1671  int x2 = qRound(c.x() + xx);
1672 
1673  for (int col=x1; col<=x2; col++) {
1674  if (m_Mask == NULL || m_Mask->value(col, row)) {
1675  T val = value(col, row);
1676 
1677  if (val==val) {
1678  if (first) {
1679  max = val;
1680  first = false;
1681  } else if (val > max) {
1682  max = val;
1683  }
1684  }
1685  }
1686  }
1687  }
1688 
1689  return max;
1690 }
T value(int x, int y) const
QcepMaskDataPtr m_Mask

Here is the call graph for this function:

template<typename T >
double QcepImageData< T >::maxInRectangle ( QRectF  rect)
virtual

Implements QcepImageDataBase.

Definition at line 1508 of file qcepimagedata.cpp.

References QcepImageData< T >::m_Mask, and QcepImageData< T >::value().

1509 {
1510  int l = qRound(rect.left());
1511  int t = qRound(rect.top());
1512  int r = qRound(rect.right());
1513  int b = qRound(rect.bottom());
1514 
1515  if (l > r) {
1516  l = qRound(rect.right());
1517  r = qRound(rect.left());
1518  }
1519 
1520  if (b > t) {
1521  b = qRound(rect.top());
1522  t = qRound(rect.bottom());
1523  }
1524 
1525  int first = true;
1526  double max = 0;
1527 
1528  for (int row=b; row<=t; row++) {
1529  for (int col=l; col<=r; col++) {
1530  if (m_Mask == NULL || m_Mask->value(col, row)) {
1531  T val = value(col, row);
1532 
1533  if (val==val) {
1534  if (first) {
1535  max = val;
1536  first = false;
1537  } else if (val > max) {
1538  max = val;
1539  }
1540  }
1541  }
1542  }
1543  }
1544 
1545  return max;
1546 }
T value(int x, int y) const
QcepMaskDataPtr m_Mask

Here is the call graph for this function:

template<typename T >
double QcepImageData< T >::maxValue ( ) const
virtual

Implements QcepImageDataBase.

Definition at line 990 of file qcepimagedata.cpp.

References QcepImageData< T >::findMax().

Referenced by QcepImageData< T >::percentileRange().

991 {
992  return findMax();
993 }
T findMax() const

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename T >
double QcepImageData< T >::minInEllipse ( QRectF  rect)
virtual

Implements QcepImageDataBase.

Definition at line 1617 of file qcepimagedata.cpp.

References QcepImageData< T >::m_Mask, and QcepImageData< T >::value().

1618 {
1619  QPointF c = rect.center();
1620  double a = rect.width()/2;
1621  double b = rect.height()/2;
1622 
1623  int bt = qRound(rect.bottom());
1624  int tp = qRound(rect.top());
1625 
1626  int first = true;
1627  double min = 0;
1628 
1629  for (int row=tp; row<=bt; row++) {
1630  double y=row - c.y();
1631  double xx = a*sqrt(1 - pow(y/b,2));
1632  int x1 = qRound(c.x() - xx);
1633  int x2 = qRound(c.x() + xx);
1634 
1635  for (int col=x1; col<=x2; col++) {
1636  if (m_Mask == NULL || m_Mask->value(col, row)) {
1637  T val = value(col, row);
1638 
1639  if (val==val) {
1640  if (first) {
1641  min = val;
1642  first = false;
1643  } else if (val < min) {
1644  min = val;
1645  }
1646  }
1647  }
1648  }
1649  }
1650 
1651  return min;
1652 }
T value(int x, int y) const
QcepMaskDataPtr m_Mask

Here is the call graph for this function:

template<typename T >
double QcepImageData< T >::minInRectangle ( QRectF  rect)
virtual

Implements QcepImageDataBase.

Definition at line 1467 of file qcepimagedata.cpp.

References QcepImageData< T >::m_Mask, and QcepImageData< T >::value().

1468 {
1469  int l = qRound(rect.left());
1470  int t = qRound(rect.top());
1471  int r = qRound(rect.right());
1472  int b = qRound(rect.bottom());
1473 
1474  if (l > r) {
1475  l = qRound(rect.right());
1476  r = qRound(rect.left());
1477  }
1478 
1479  if (b > t) {
1480  b = qRound(rect.top());
1481  t = qRound(rect.bottom());
1482  }
1483 
1484  int first = true;
1485  double min = 0;
1486 
1487  for (int row=b; row<=t; row++) {
1488  for (int col=l; col<=r; col++) {
1489  if (m_Mask == NULL || m_Mask->value(col, row)) {
1490  T val = value(col, row);
1491 
1492  if (val==val) {
1493  if (first) {
1494  min = val;
1495  first = false;
1496  } else if (val < min) {
1497  min = val;
1498  }
1499  }
1500  }
1501  }
1502  }
1503 
1504  return min;
1505 }
T value(int x, int y) const
QcepMaskDataPtr m_Mask

Here is the call graph for this function:

template<typename T >
double QcepImageData< T >::minValue ( ) const
virtual

Implements QcepImageDataBase.

Definition at line 984 of file qcepimagedata.cpp.

References QcepImageData< T >::findMin().

Referenced by QcepImageData< T >::percentileRange().

985 {
986  return findMin();
987 }
T findMin() const

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename T >
template<typename T2 >
template void QcepImageData< T >::multiply< double > ( QSharedPointer< QcepImageData< T2 > >  image)

Definition at line 874 of file qcepimagedata.cpp.

References QcepImageData< T >::data(), and QcepImageData< T >::multiplyValue().

875 {
876  if (image) {
877  int ncols = this -> get_Width();
878  int nrows = this -> get_Height();
879 
880  this->prop_SummedExposures()->incValue(image->get_SummedExposures());
881 
882  if (ncols == image->get_Width() && nrows == image->get_Height()) {
883  int npix = ncols*nrows;
884 
885  T *srcp = this -> data();
886  T2 *destp = image -> data();
887 
888  for (int i=0; i<npix; i++) {
889  *srcp++ *= *destp++;
890  }
891  } else {
892  for (int row=0; row<nrows; row++) {
893  for (int col=0; col<ncols; col++) {
894  this -> multiplyValue(col, row, image->value(col, row));
895  }
896  }
897  }
898  }
899 }
void multiplyValue(int x, int y, T val)

Here is the call graph for this function:

template<typename T>
void QcepImageData< T >::multiplyValue ( int  x,
int  y,
val 
)

Definition at line 482 of file qcepimagedata.cpp.

References QcepImageData< T >::m_Image.

Referenced by QcepImageData< T >::multiply().

483 {
484  if (x >= 0 && x < get_Width() && y >= 0 && y < get_Height()) {
485  m_Image[(get_Height()-y-1)*get_Width()+x] *= val;
486  }
487 }
QVector< T > m_Image

Here is the caller graph for this function:

template<typename T >
QSharedPointer< QcepImageData< T > > QcepImageData< T >::newImage ( QcepSettingsSaverWPtr  saver,
QString  name,
int  width,
int  height,
QcepObject parent 
)
static

Definition at line 372 of file qcepimagedata.cpp.

Referenced by QcepDataGroup::newImage(), and QcepDatasetModel::newImage().

374 {
375  QSharedPointer< QcepImageData<T> > res(new QcepImageData<T>(saver, width, height, 0, parent));
376 
377  res->setObjectName(name);
378 
379  return res;
380 }
QString name
Definition: qcepobject.h:49
QcepSettingsSaverWPtr saver()

Here is the caller graph for this function:

template<typename T >
QcepMaskDataPtr QcepImageData< T >::overflow ( ) const

Definition at line 978 of file qcepimagedata.cpp.

References QcepImageData< T >::m_Overflow.

Referenced by QcepImageData< T >::setMask().

979 {
980  return m_Overflow;
981 }
QcepMaskDataPtr m_Overflow

Here is the caller graph for this function:

template<typename T >
QPointF QcepImageData< T >::percentileRange ( double  lowpct,
double  highpct 
)
virtual

Implements QcepImageDataBase.

Definition at line 1080 of file qcepimagedata.cpp.

References QcepImageData< T >::m_Mask, QcepImageData< T >::maxValue(), QcepImageData< T >::minValue(), and QcepImageData< T >::value().

1081 {
1082  const int histSize = 65536;
1083  QVector<int> histogramVec(histSize+1);
1084  histogramVec.fill(0.0);
1085  int *histogram = histogramVec.data();
1086 
1087  int ncols = this -> get_Width();
1088  int nrows = this -> get_Height();
1089 
1090  double minVal = minValue();
1091  double maxVal = maxValue();
1092 
1093  double histStep = (maxVal - minVal + 2)/histSize;
1094  int nAbove = 0, nBelow = 0, nTotal = 0;
1095 
1096  for (int row=0; row<nrows; row++) {
1097  for (int col=0; col<ncols; col++) {
1098  if (m_Mask == NULL || m_Mask->value(col, row)) {
1099  double val = value(col, row);
1100 
1101  if (val==val) {
1102  double bin = (val - minVal)/histStep;
1103 
1104  if (bin < 0) {
1105  nBelow += 1;
1106  } else if (bin >= histSize) {
1107  nAbove += 1;
1108  } else {
1109  histogram[(int) bin] += 1;
1110  }
1111 
1112  nTotal += 1;
1113  }
1114  }
1115  }
1116  }
1117 
1118  double lowCount = ((double) nTotal) * lowpct / 100.0;
1119  double highCount = ((double) nTotal) * highpct / 100.0;
1120  double count = nBelow;
1121 
1122  QPointF res(0,0);
1123 
1124  for (int i=0; i<histSize; i++) {
1125  double binVal = minVal + i*histStep;
1126 
1127  count += histogram[i];
1128 
1129  if (count < lowCount) {
1130  res.setX(binVal);
1131  }
1132 
1133  if (count < highCount) {
1134  res.setY(binVal);
1135  }
1136  }
1137 
1138  if (res.y() <= res.x()) {
1139  res.setY(res.x() + 1);
1140  }
1141 
1142  return res;
1143 }
double maxValue() const
T value(int x, int y) const
QcepMaskDataPtr m_Mask
double minValue() const

Here is the call graph for this function:

template<typename T >
QString QcepImageData< T >::rawFileName ( )

Definition at line 715 of file qcepimagedata.cpp.

References QcepObject::name.

716 {
717  QFileInfo info(QcepImageData<T>::get_FileName());
718 
719  QString name = info.dir().filePath(info.completeBaseName()+".raw.tif");
720 
721  return name;
722 }
QString name
Definition: qcepobject.h:49
template<typename T >
bool QcepImageData< T >::readImage ( QString  filename)

Definition at line 630 of file qcepimagedata.cpp.

References QcepImageDataFormatFactory< T >::factory(), and QcepImageDataBase::fileBase.

631 {
632  QcepImageDataFormat<T> *loader =
634 
635  if (loader) {
636  bool res = loader -> loadFile(path, this);
637 
638  if (res) {
639  QString fileBase = QFileInfo(path).fileName();
640 
641  set_FileBase(fileBase);
642  set_Title(fileBase);
643  set_FileName(path);
644  set_ObjectSaved(true);
645  }
646 
647  return res;
648  } else {
649  return false;
650  }
651 }
static QcepImageDataFormatFactory< T > * factory()

Here is the call graph for this function:

template<typename T >
void QcepImageData< T >::resize ( int  width,
int  height 
)
virtual

Implements QcepImageDataBase.

Definition at line 582 of file qcepimagedata.cpp.

References QcepAllocator::allocate(), QcepImageDataBase::height, QcepImageData< T >::m_Image, QcepImageData< T >::setValue(), QcepImageData< T >::value(), and QcepImageDataBase::width.

Referenced by QcepImageData< T >::copyFrom(), and QcepImageData< T >::copyImage().

583 {
584  QcepImageData<T> temp(QcepSettingsSaverPtr(), get_Width(), get_Height(), 0, this);
585 
586  int oldwidth = get_Width();
587  int oldheight= get_Height();
588 
589  for (int y=0; y<oldheight; y++) {
590  for (int x=0; x<oldwidth; x++) {
591  temp.setValue(x, y, value(x,y));
592  }
593  }
594 
595  set_Width(width);
596  set_Height(height);
597 
598  m_Image.resize(width*height);
599 
600  for (int y=0; y<height; y++) {
601  for (int x=0; x<width; x++) {
602  setValue(x, y, temp.value(x,y));
603  }
604  }
605 
606  set_ByteSize(width*height*sizeof(T));
607 
608  QcepAllocator::allocate((width*height - oldwidth*oldheight)*sizeof(T));
609 }
T value(int x, int y) const
QSharedPointer< QcepSettingsSaver > QcepSettingsSaverPtr
void setValue(int x, int y, T val)
static void allocate(int sz, int width, int height)
QVector< T > m_Image

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename T >
void QcepImageData< T >::saveData ( QString &  name,
QString  filter,
Overwrite  canOverwrite = NoOverwrite 
)
virtual

Reimplemented from QcepDataObject.

Definition at line 1371 of file qcepimagedata.cpp.

References QcepImageDataBase::fileFormatCSV(), QcepImageDataBase::fileFormatTabDelimited(), QcepImageDataBase::fileFormatTIFF(), QcepImageDataBase::fileFormatTransposedCSV(), QcepImageDataBase::fileFormatTransposedTabDelimited(), QcepDataObject::mkPath(), QcepDataObject::NoOverwrite, QcepImageDataBase::saveTextData(), QcepImageData< T >::saveTIFFData(), and QcepDataObject::uniqueFileName().

1372 {
1373  mkPath(name);
1374 
1375  if (canOverwrite == NoOverwrite) {
1377  }
1378 
1379  if (filter == fileFormatTIFF()) {
1380  saveTIFFData(name);
1381  } else if (filter == fileFormatTabDelimited()) {
1382  saveTextData(name, "\t", false);
1383  } else if (filter == fileFormatTransposedTabDelimited()) {
1384  saveTextData(name, "\t", true);
1385  } else if (filter == fileFormatCSV()) {
1386  saveTextData(name, ", ", false);
1387  } else if (filter == fileFormatTransposedCSV()) {
1388  saveTextData(name, ", ", true);
1389  }
1390 }
void saveTextData(QString name, QString sep, bool transp=false)
QString uniqueFileName(QString name)
void mkPath(QString filePath)
QString fileFormatTransposedCSV()
QString fileFormatTIFF()
void saveTIFFData(QString name)
QString fileFormatTabDelimited()
QString name
Definition: qcepobject.h:49
QString fileFormatTransposedTabDelimited()

Here is the call graph for this function:

template<typename T >
void QcepImageData< T >::saveTIFFData ( QString  name)

Definition at line 1241 of file qcepimagedata.cpp.

References QcepImageDataBase::saveMetaData(), TIFFCHECK, and QcepImageData< T >::value().

Referenced by QcepImageData< T >::saveData().

1242 {
1243  int nrows = get_Height();
1244  int ncols = get_Width();
1245 
1246  TIFF* tif = TIFFOpen(qPrintable(name),"w");
1247  int res = 1;
1248 
1249  if (tif) {
1250  int nsum = get_SummedExposures();
1251 
1252  TIFFCHECK(TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, ncols));
1253  TIFFCHECK(TIFFSetField(tif, TIFFTAG_IMAGELENGTH, nrows));
1254  TIFFCHECK(TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1));
1255 
1256  TIFFCHECK(TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG));
1257 
1258  if (nsum == 0) {
1259  TIFFCHECK(TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8));
1260  } else if (nsum == 1) {
1261  TIFFCHECK(TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 16));
1262  } else {
1263  TIFFCHECK(TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 32));
1264  }
1265 
1266  TIFFCHECK(TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT));
1267 
1268  TIFFCHECK(TIFFSetField(tif, TIFFTAG_DOCUMENTNAME, qPrintable(get_FileName())));
1269  TIFFCHECK(TIFFSetField(tif, TIFFTAG_DATETIME, qPrintable(get_DateTime().toString("yyyy:MM:dd hh:mm:ss"))));
1270 
1271  if (nsum == 0) {
1272  QVector<quint8> buffvec(ncols);
1273  quint8* buffer = buffvec.data();
1274 
1275  for (int y=0; y<nrows; y++) {
1276  for (int x=0; x<ncols; x++) {
1277  buffer[x] = value(x,y);
1278  }
1279 
1280  TIFFCHECK(TIFFWriteScanline(tif, buffer, y, 0));
1281  }
1282  } else if (nsum == 1) {
1283  QVector<quint16> buffvec(ncols);
1284  quint16* buffer = buffvec.data();
1285 
1286  for (int y=0; y<nrows; y++) {
1287  for (int x=0; x<ncols; x++) {
1288  buffer[x] = value(x,y);
1289  }
1290 
1291  TIFFCHECK(TIFFWriteScanline(tif, buffer, y, 0));
1292  }
1293  } else {
1294  QVector<quint32> buffvec(ncols);
1295  quint32* buffer = buffvec.data();
1296 
1297  for (int y=0; y<nrows; y++) {
1298  for (int x=0; x<ncols; x++) {
1299  buffer[x] = value(x,y);
1300  }
1301 
1302  TIFFCHECK(TIFFWriteScanline(tif, buffer, y, 0));
1303  }
1304  }
1305 
1306  TIFFClose(tif);
1307 
1308  set_FileName(name);
1309  set_ObjectSaved(true);
1310 
1311  saveMetaData();
1312  }
1313 }
#define TIFFCHECK(a)
T value(int x, int y) const
QString name
Definition: qcepobject.h:49
struct tiff TIFF
Definition: qcepimagedata.h:21

Here is the call graph for this function:

Here is the caller graph for this function:

template<>
void QcepImageData< double >::saveTIFFData ( QString  name)

Definition at line 1200 of file qcepimagedata.cpp.

References QcepImageDataBase::saveMetaData(), TIFFCHECK, and QcepImageData< T >::value().

1201 {
1202  int nrows = get_Height();
1203  int ncols = get_Width();
1204 
1205  TIFF* tif = TIFFOpen(qPrintable(name),"w");
1206  int res = 1;
1207 
1208  if (tif) {
1209  TIFFCHECK(TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, ncols));
1210  TIFFCHECK(TIFFSetField(tif, TIFFTAG_IMAGELENGTH, nrows));
1211  TIFFCHECK(TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1));
1212 
1213  TIFFCHECK(TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG));
1214  TIFFCHECK(TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 32));
1215  TIFFCHECK(TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP));
1216 
1217  TIFFCHECK(TIFFSetField(tif, TIFFTAG_DOCUMENTNAME, qPrintable(get_FileName())));
1218  TIFFCHECK(TIFFSetField(tif, TIFFTAG_DATETIME, qPrintable(get_DateTime().toString("yyyy:MM:dd hh:mm:ss"))));
1219 
1220  QVector<float> buffvec(ncols);
1221  float* buffer = buffvec.data();
1222 
1223  for (int y=0; y<nrows; y++) {
1224  for (int x=0; x<ncols; x++) {
1225  buffer[x] = value(x,y);
1226  }
1227 
1228  TIFFCHECK(TIFFWriteScanline(tif, buffer, y, 0));
1229  }
1230 
1231  TIFFClose(tif);
1232 
1233  set_FileName(name);
1234  set_ObjectSaved(true);
1235 
1236  saveMetaData();
1237  }
1238 }
#define TIFFCHECK(a)
T value(int x, int y) const
QString name
Definition: qcepobject.h:49
struct tiff TIFF
Definition: qcepimagedata.h:21

Here is the call graph for this function:

template<typename T>
void QcepImageData< T >::setDefaultValue ( def)

Definition at line 624 of file qcepimagedata.cpp.

References QcepImageData< T >::m_Default.

625 {
626  m_Default = def;
627 }
template<typename T >
void QcepImageData< T >::setImageData ( int  x,
int  y,
double  v 
)
virtual

Implements QcepImageDataBase.

Definition at line 450 of file qcepimagedata.cpp.

References QcepImageData< T >::m_Image.

451 {
452  if (x >= 0 && x < get_Width() && y >= 0 && y < get_Height()) {
453  m_Image[(get_Height()-y-1)*get_Width()+x] = v;
454  }
455 }
QVector< T > m_Image
template<typename T >
void QcepImageData< T >::setMask ( QcepMaskDataPtr  mask,
QcepMaskDataPtr  overflow 
)

Definition at line 965 of file qcepimagedata.cpp.

References QcepImageData< T >::m_Mask, QcepImageData< T >::m_Overflow, QcepImageData< T >::mask(), and QcepImageData< T >::overflow().

966 {
967  m_Mask = mask;
969 }
QcepMaskDataPtr overflow() const
QcepMaskDataPtr m_Overflow
QcepMaskDataPtr m_Mask
QcepMaskDataPtr mask() const

Here is the call graph for this function:

template<typename T>
void QcepImageData< T >::setValue ( int  x,
int  y,
val 
)

Definition at line 458 of file qcepimagedata.cpp.

References QcepImageData< T >::m_Image.

Referenced by QcepImageData< T >::correctBadBackgroundSubtraction(), QcepImageData< T >::resize(), and QcepImageData< T >::shiftImage().

459 {
460  if (x >= 0 && x < get_Width() && y >= 0 && y < get_Height()) {
461  m_Image[(get_Height()-y-1)*get_Width()+x] = val;
462  }
463 }
QVector< T > m_Image

Here is the caller graph for this function:

template<typename T>
void QcepImageData< T >::shiftImage ( QSharedPointer< QcepImageData< T > >  image,
double  dx,
double  dy 
)

Definition at line 950 of file qcepimagedata.cpp.

References QcepImageData< T >::setValue().

951 {
952  if (image) {
953  int wd = this->get_Width();
954  int ht = this->get_Height();
955 
956  for (int y=0; y<ht; y++) {
957  for (int x=0; x<wd; x++) {
958  this->setValue(x,y, image->value(x+dx,y+dy));
959  }
960  }
961  }
962 }
void setValue(int x, int y, T val)

Here is the call graph for this function:

template<typename T >
template<typename T2 >
template void QcepImageData< T >::subtract< double > ( QSharedPointer< QcepImageData< T2 > >  image)

Definition at line 845 of file qcepimagedata.cpp.

References QcepImageData< T >::data(), and QcepImageData< T >::subtractValue().

846 {
847  if (image) {
848  int ncols = this -> get_Width();
849  int nrows = this -> get_Height();
850 
851  this->prop_SummedExposures()->incValue(image->get_SummedExposures());
852 
853  if (ncols == image->get_Width() && nrows == image->get_Height()) {
854  int npix = ncols*nrows;
855 
856  T *srcp = this -> data();
857  T2 *destp = image -> data();
858 
859  for (int i=0; i<npix; i++) {
860  *srcp++ -= *destp++;
861  }
862  } else {
863  for (int row=0; row<nrows; row++) {
864  for (int col=0; col<ncols; col++) {
865  this -> subtractValue(col, row, image->value(col, row));
866  }
867  }
868  }
869  }
870 }
void subtractValue(int x, int y, T val)

Here is the call graph for this function:

template<typename T >
template<typename T2 >
template void QcepImageData< T >::subtractDark ( const QSharedPointer< QcepImageData< T2 > >  dark)

Definition at line 655 of file qcepimagedata.cpp.

References QcepImageData< T >::data(), QcepImageDataBase::height, QcepImageDataBase::mutex(), QcepImageDataBase::printMessage(), QcepImageDataBase::SubtractedData, and QcepImageDataBase::width.

656 {
657  // if (get_PerformDarkSubtraction()) {
658  if (dark->get_ExposureTime() != this->get_ExposureTime()) {
659  printMessage("Exposure times of acquired data and dark image are different, skipping");
660  return;
661  }
662 
663  if (dark->get_Width() != this->get_Width() ||
664  dark->get_Height() != this->get_Height()) {
665  printMessage("Dimensions of acquired data and dark image are different, skipping");
666  return;
667  }
668 
669  if (dark->get_CameraGain() != this->get_CameraGain()) {
670  printMessage("Gains of acquired data and dark image are different, skipping");
671  return;
672  }
673 
674  // if (!(image->get_DataType() == QcepDoubleImageData::Raw16Data ||
675  // image->get_DataType() == QcepDoubleImageData::Raw32Data)) {
676  // printMessage("Acquired data is not a raw image, skipping background subtraction");
677  // return;
678  // }
679 
680  QcepMutexLocker lock1(__FILE__, __LINE__, dark->mutex());
681  QcepMutexLocker lock2(__FILE__, __LINE__, this->mutex());
682 
683  int height = this->get_Height();
684  int width = this->get_Width();
685  int nres = this -> get_SummedExposures();
686  int ndrk = dark -> get_SummedExposures();
687  int npixels = width*height;
688 
689  if (nres <= 0) nres = 1;
690 
691  double ratio = ((double) nres)/((double) ndrk);
692 
693  // printf("Dark subtraction nres=%d, ndrk=%d, npixels=%d, ratio=%g\n",
694  // nres, ndrk, npixels, ratio);
695 
696  double *result = this->data();
697  T2 *dk = dark->data();
698  double avgraw = 0;
699  // double avgdark = 0;
700 
701  for (int i=0; i<npixels; i++) {
702  // avgdark += dk[i];
703  avgraw += result[i];
704  result[i] = result[i]-ratio*dk[i];
705  }
706 
707  // set_AverageDark(avgdark/npixels/ndrk);
708 // set_AverageRaw(avgraw/npixels/nres);
709 // set_Average(get_AverageRaw() - get_AverageDark());
710 
711  this -> set_DataType(SubtractedData);
712 }
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const

Here is the call graph for this function:

template<typename T>
void QcepImageData< T >::subtractValue ( int  x,
int  y,
val 
)

Definition at line 474 of file qcepimagedata.cpp.

References QcepImageData< T >::m_Image.

Referenced by QcepImageData< T >::subtract().

475 {
476  if (x >= 0 && x < get_Width() && y >= 0 && y < get_Height()) {
477  m_Image[(get_Height()-y-1)*get_Width()+x] -= val;
478  }
479 }
QVector< T > m_Image

Here is the caller graph for this function:

template<typename T >
double QcepImageData< T >::sumInEllipse ( QRectF  rect)
virtual

Implements QcepImageDataBase.

Definition at line 1549 of file qcepimagedata.cpp.

References QcepImageData< T >::m_Mask, and QcepImageData< T >::value().

1550 {
1551  QPointF c = rect.center();
1552  double a = rect.width()/2;
1553  double b = rect.height()/2;
1554 
1555  int bt = qRound(rect.bottom());
1556  int tp = qRound(rect.top());
1557 
1558  int np = 0;
1559  double sum = 0;
1560 
1561  for (int row=tp; row<=bt; row++) {
1562  double y=row - c.y();
1563  double xx = a*sqrt(1 - pow(y/b,2));
1564  int x1 = qRound(c.x() - xx);
1565  int x2 = qRound(c.x() + xx);
1566 
1567  for (int col=x1; col<=x2; col++) {
1568  if (m_Mask == NULL || m_Mask->value(col, row)) {
1569  T val = value(col, row);
1570 
1571  if (val==val) {
1572  np++;
1573  sum += val;
1574  }
1575  }
1576  }
1577  }
1578 
1579  return sum;
1580 }
T value(int x, int y) const
QcepMaskDataPtr m_Mask

Here is the call graph for this function:

template<typename T >
double QcepImageData< T >::sumInPeak ( QRectF  rect)
virtual

Implements QcepImageDataBase.

Definition at line 1693 of file qcepimagedata.cpp.

References QcepImageData< T >::m_Mask, and QcepImageData< T >::value().

1694 {
1695  QPointF c = rect.center();
1696  double w = rect.width()/2;
1697  double h = rect.height()/2;
1698 
1699  int bt = qRound(rect.bottom());
1700  int tp = qRound(rect.top());
1701  int lf = qRound(rect.left());
1702  int rt = qRound(rect.right());
1703 
1704  int ptp = qRound(c.y() - h/2);
1705  int pbt = qRound(c.y() + h/2);
1706  int plf = qRound(c.x() - w/2);
1707  int prt = qRound(c.x() + w/2);
1708 
1709  int np = 0;
1710  double sum = 0;
1711  int npk = 0;
1712  double sumpk = 0;
1713 
1714  for (int row=tp; row<=bt; row++) {
1715  for (int col=lf; col<=rt; col++) {
1716  if (m_Mask == NULL || m_Mask->value(col,row)) {
1717  T val = value(col,row);
1718 
1719  if (val == val) {
1720  if (ptp <= row && row <= pbt && plf <= col && col <= prt) {
1721  npk++;
1722  sumpk += val;
1723  } else {
1724  np++;
1725  sum += val;
1726  }
1727  }
1728  }
1729  }
1730  }
1731 
1732  if (np > 0 && npk > 0) {
1733  double avbk = sum/np;
1734  double avpk = sumpk/npk;
1735 
1736  return (avpk-avbk)*npk;
1737  } else {
1738  return 0;
1739  }
1740 }
T value(int x, int y) const
QcepMaskDataPtr m_Mask

Here is the call graph for this function:

template<typename T >
double QcepImageData< T >::sumInRectangle ( QRectF  rect)
virtual

Implements QcepImageDataBase.

Definition at line 1393 of file qcepimagedata.cpp.

References QcepImageData< T >::m_Mask, and QcepImageData< T >::value().

1394 {
1395  int l = qRound(rect.left());
1396  int t = qRound(rect.top());
1397  int r = qRound(rect.right());
1398  int b = qRound(rect.bottom());
1399 
1400  if (l > r) {
1401  l = qRound(rect.right());
1402  r = qRound(rect.left());
1403  }
1404 
1405  if (b > t) {
1406  b = qRound(rect.top());
1407  t = qRound(rect.bottom());
1408  }
1409 
1410  int np = 0;
1411  double sum = 0;
1412 
1413  for (int row=b; row<=t; row++) {
1414  for (int col=l; col<=r; col++) {
1415  if (m_Mask == NULL || m_Mask->value(col, row)) {
1416  T val = value(col, row);
1417 
1418  if (val==val) {
1419  np++;
1420  sum += val;
1421  }
1422  }
1423  }
1424  }
1425 
1426  return sum;
1427 }
T value(int x, int y) const
QcepMaskDataPtr m_Mask

Here is the call graph for this function:

template<typename T>
QScriptValue QcepImageData< T >::toScriptValue ( QScriptEngine *  engine,
const QSharedPointer< QcepImageData< T > > &  data 
)
static

Definition at line 1170 of file qcepimagedata.cpp.

References QcepImageData< T >::data().

1171 {
1172  return engine->newQObject(data.data());
1173 }

Here is the call graph for this function:

template<typename T >
T QcepImageData< T >::value ( int  x,
int  y 
) const
template<typename T >
T QcepImageData< T >::value ( double  x,
double  y 
) const

Definition at line 399 of file qcepimagedata.cpp.

References QcepImageData< T >::value().

400 {
401  int ix = ((int) x), iy = ((int) y);
402  double dx = x-ix, dy = y-iy;
403 
404  double f00 = value((ix) , (iy));
405  double f10 = value((ix+1) , (iy));
406  double f01 = value((ix) , (iy+1));
407  double f11 = value((ix+1) , (iy+1));
408 
409  double f0 = f00*(1-dx)+f10*dx;
410  double f1 = f01*(1-dx)+f11*dx;
411 
412  double f = f0*(1-dy)+f1*dy;
413 
414  return f;
415 }
T value(int x, int y) const

Here is the call graph for this function:

Member Data Documentation

template<typename T>
T QcepImageData< T >::m_Default
protected
template<typename T>
QVector<T> QcepImageData< T >::m_Image
protected
template<typename T>
QcepMaskDataPtr QcepImageData< T >::m_Mask
protected
template<typename T>
T QcepImageData< T >::m_MaxValue
protected
template<typename T>
T QcepImageData< T >::m_MinValue
protected
template<typename T>
QcepMaskDataPtr QcepImageData< T >::m_Overflow
protected

Definition at line 352 of file qcepimagedata.h.

Referenced by QcepImageData< T >::overflow(), and QcepImageData< T >::setMask().


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