15 #include <QtConcurrentRun>
16 #include <QDirIterator>
23 m_CorrectedImages(prop_CorrectionQueueLength(), this),
24 m_IntegratedData(prop_IntegrationQueueLength(), this),
25 m_ROIData(NULL, this),
26 m_HistogramData(NULL, this)
48 int height = image->get_Height();
49 int width = image->get_Width();
50 int nres = image-> get_SummedExposures();
51 int npixels = width*height;
52 if (nres <= 0) nres = 1;
54 quint16 *img = image->data();
56 for (
int i=0; i<npixels; i++) {
60 set_AverageRaw(avgraw/npixels/nres);
61 set_Average(get_AverageRaw() - get_AverageDark());
71 corrected->copyFrom(image);
119 corrected, image,
darkImage(), overflow, v));
125 QThread::currentThread()->setObjectName(
"correctInt16Image");
128 printMessage(tr(
"QxrdDataProcessorThreaded::correctInt16Image"));
132 if ((image -> get_ImageNumber()) >= 0) {
133 return processAcquiredInt16Image(corrected, image, dark, mask, overflow);
135 if (get_SaveDarkImages()) {
136 saveNamedImageData(image->get_FileName(), image, overflow);
137 set_DarkImagePath(image->get_FileName());
150 QThread::currentThread()->setObjectName(
"correctInt32Image");
153 printMessage(tr(
"QxrdDataProcessorThreaded::correctInt32Image"));
157 if ((image -> get_ImageNumber()) >= 0) {
158 return processAcquiredInt32Image(corrected, image, dark, mask, overflow);
160 if (get_SaveDarkImages()) {
161 saveNamedImageData(image->get_FileName(), image, overflow);
163 set_DarkImagePath(image->get_FileName());
176 QThread::currentThread()->setObjectName(
"correctDoubleImage");
179 printMessage(tr(
"QxrdDataProcessorThreaded::correctDoubleImage"));
183 if ((image -> get_ImageNumber()) >= 0) {
184 return processAcquiredDoubleImage(corrected, image, dark, mask, overflow);
186 if (get_SaveDarkImages()) {
187 saveNamedImageData(image->get_FileName(), image, overflow);
189 set_DarkImagePath(image->get_FileName());
202 QThread::currentThread()->setObjectName(
"correctDoubleImage");
205 printMessage(tr(
"QxrdDataProcessorThreaded::correctDoubleImage"));
209 if ((image -> get_ImageNumber()) >= 0) {
210 return processAcquiredDoubleImage(corrected, image, dark, image->mask(), overflow, v);
212 if (get_SaveDarkImages()) {
213 saveNamedImageData(image->get_FileName(), image, overflow);
215 set_DarkImagePath(image->get_FileName());
249 QThread::currentThread()->setObjectName(
"integrateImage");
252 printMessage(tr(
"QxrdDataProcessorThreaded::integrateImage"));
255 if (image && get_PerformIntegration()) {
259 m_Integrator -> performIntegration(integ, image, mask);
261 updateEstimatedTime(prop_PerformIntegrationTime(), tic.restart());
272 printMessage(tr(
"QxrdDataProcessorThreaded::onIntegratedDataAvailable"));
281 if (get_AccumulateIntegrated2D()) {
282 m_Integrator -> appendIntegration(get_AccumulateIntegratedName(), integ);
290 QThread::currentThread()->setObjectName(
"calculateROI");
293 printMessage(tr(
"QxrdDataProcessorThreaded::calculateROI"));
302 printMessage(tr(
"QxrdDataProcessorThreaded::onROIDataAvailable"));
311 QThread::currentThread()->setObjectName(
"calculateHistogram");
314 printMessage(tr(
"QxrdDataProcessorThreaded::calculateHistogram"));
323 printMessage(tr(
"QxrdDataProcessorThreaded::onHistogramDataAvailable"));
331 int nThreads = QThreadPool::globalInstance()->maxThreadCount();
334 return qMax(estSerialTime, estParallelTime/((
double)nThreads));
336 return estSerialTime + estParallelTime;
345 foreach(QString
name, names) {
349 if (img->readImage(path)) {
353 img -> loadMetaData();
355 int typ = img->get_DataType();
364 summed->copyFrom(img);
367 summed->accumulateImage(img);
387 foreach(QString
name, names) {
391 if (img->readImage(path)) {
395 img -> loadMetaData();
397 int typ = img->get_DataType();
419 foreach(QString
name, names) {
423 if (img->readImage(path)) {
427 img -> loadMetaData();
429 int typ = img->get_DataType();
437 summed->subtract(img);
454 int nImages = names.count();
455 m_Integrator -> prepareAccumulator(get_AccumulateIntegratedName(), nImages);
457 foreach(QString
name, names) {
461 if (img->readImage(path)) {
465 img -> loadMetaData();
467 m_Integrator -> appendIntegration(get_AccumulateIntegratedName(), img,
mask());
474 m_Integrator -> completeAccumulator(get_AccumulateIntegratedName());
487 int wid = image->get_Width();
488 int hgt = image->get_Height();
490 for (
int y=0; y<hgt; y++) {
491 for (
int x=0; x<wid/2; x++) {
492 double val1 = image->getImageData(x,y);
493 double val2 = image->getImageData(wid-x-1, y);
495 image->setValue(wid-x-1, y, val1);
496 image->setValue(x,y, val2);
509 int wid = image->get_Width();
510 int hgt = image->get_Height();
512 for (
int x=0; x<wid; x++) {
513 for (
int y=0; y<hgt/2; y++) {
514 double val1 = image->getImageData(x,y);
515 double val2 = image->getImageData(x, hgt-y-1);
517 image->setValue(x, hgt-y-1, val1);
518 image->setValue(x,y, val2);
532 int nz = names.count();
537 printMessage(tr(
"Projecting %1 images onto X").arg(nz));
542 printMessage(tr(
"Projecting %1 images onto Y").arg(nz));
547 printMessage(tr(
"Projecting %1 images onto Z").arg(nz));
553 expt->commenceWork(nz);
556 for (
int i=0; i<nz; i++) {
560 if (img->readImage(path)) {
565 int typ = img->get_DataType();
574 nx = img->get_Width();
575 ny = img->get_Height();
578 sumx->copyPropertiesFrom(img);
581 sumx->set_SummedExposures(0);
585 sumy->copyPropertiesFrom(img);
588 sumy->set_SummedExposures(0);
592 sumz->copyPropertiesFrom(img);
595 sumz->set_SummedExposures(0);
602 sumx->prop_SummedExposures()->incValue(1);
604 for (
int y=0; y<ny; y++) {
607 for (
int x=0; x<nx; x++) {
608 sum += img->getImageData(x,y);
611 sumx->addValue(i,y, sum);
616 sumy->prop_SummedExposures()->incValue(1);
618 for (
int x=0; x<nx; x++) {
621 for (
int y=0; y<ny; y++) {
622 sum += img->getImageData(x,y);
625 sumy->addValue(i,x, sum);
630 sumz->prop_SummedExposures()->incValue(1);
632 for (
int x=0; x<nx; x++) {
633 for (
int y=0; y<ny; y++) {
634 sumz->addValue(x,y, img->getImageData(x,y));
641 expt->completeWork(1);
658 expt->finishedWork(nz);
666 foreach(QString
name, names) {
670 if (imgb->readImage(path)) {
674 imgb -> loadMetaData();
676 int typ = imgb->get_DataType();
686 for (
int dy = -10; dy<=10; dy++) {
687 for (
int dx = -10; dx<=10; dx++) {
688 double corr = imga->correlate(imgb, dx, dy, 10, 10);
690 printMessage(tr(
"%1\t%2\t%3").arg(dx).arg(dy).arg(corr));
707 shft->shiftImage(img, dx, dy);
715 QThread::currentThread()->setObjectName(
"integrateData");
724 if (img -> readImage(path)) {
730 img -> loadMetaData();
749 if (res -> readImage(path)) {
755 res -> loadMetaData();
759 set_DataPath(res -> get_FileName());
768 QDirIterator iter(path, QStringList(filter));
770 while (iter.hasNext()) {
771 QString path = iter.next();
783 foreach(path, paths) {
792 QDirIterator iter(path, filters);
794 while (iter.hasNext()) {
795 QString path = iter.next();
825 if (res -> readImage(path)) {
829 res -> loadMetaData();
834 set_DataPath(res -> get_FileName());
862 if (res -> readImage(path)) {
868 res -> loadMetaData();
870 res -> set_Normalization(v);
871 res -> saveMetaData(name);
891 printMessage(tr(
"processor.integrateSaveAndDisplay: %1, %2, %3")
906 QDirIterator imagePaths(
dataDirectory(), QStringList(imagePattern));
911 if (dark->readImage(path)) {
912 dark->loadMetaData();
914 int nFileDarkExposures = dark->get_SummedExposures();
916 printMessage(tr(
"Loaded Dark image from %1 (%2 summed)").arg(path).arg(nFileDarkExposures));
918 while (imagePaths.hasNext()) {
919 QString imagePath=imagePaths.next();
924 if (image->readImage(path)) {
925 image->loadMetaData();
927 int nFileImageExposures = image->get_SummedExposures();
929 printMessage(tr(
"Loaded image from %1 (%2 summed)").arg(path).arg(nFileImageExposures));
931 image->correctBadBackgroundSubtraction(dark,nImgExposures,nDarkExposures);
939 printMessage(tr(
"Failed to load image from %1").arg(path));
943 printMessage(tr(
"Failed to load Dark image from %1").arg(path));
952 cf->fitPeakNear(x,y);
QSharedPointer< QxrdExperiment > QxrdExperimentPtr
QcepIntegratedDataPtr slicePolygon(QcepIntegratedDataPtr integ, QcepDoubleImageDataPtr dimg, QVector< QPointF > poly, double width)
QSharedPointer< QxrdCenterFinder > QxrdCenterFinderPtr
void setFileNormalization(QString path, double v1)
void calculateHistogram()
QcepMaskDataPtr mask() const
void shiftImage(int dx, int dy)
void processData(QString name)
void onHistogramDataAvailable()
void addImages(QStringList names)
static QcepIntegratedDataPtr newIntegratedData(AllocationStrategy strat, QcepDoubleImageDataPtr image, QcepObject *parent)
qint64 qcepDebug(int cond)
void subtractDarkImage(QcepDoubleImageDataPtr image, QcepDoubleImageDataPtr dark)
QxrdResultSerializer< QxrdHistogramDataPtr > m_HistogramData
QxrdResultSerializer< QcepIntegratedDataPtr > m_IntegratedData
QcepDoubleImageDataPtr darkImage() const
QxrdCenterFinderPtr m_CenterFinder
void onCorrectedImageAvailable()
void acquiredDoubleImage(QcepDoubleImageDataPtr image, QcepMaskDataPtr overflow)
QxrdResultSerializer< QcepDoubleImageDataPtr > m_CorrectedImages
QcepIntegratedDataPtr performIntegration(QcepIntegratedDataPtr integ, QcepDoubleImageDataPtr dimg, QcepMaskDataPtr mask)
QcepDoubleImageDataPtr takeNextFreeImage(int width, int height)
void processDataSequence(QString path, QString filter="*.tif")
static void newDoubleImageAndIntegratedData(AllocationStrategy strat, int width, int height, QcepObject *parent, QcepDoubleImageDataPtr &img, QcepIntegratedDataPtr &integ)
void fixupBadBackgroundSubtraction(QString imagePattern, int nImgExposures, QString darkPath, int nDarkExposures)
void integrateData(QString name)
void processNormalizedFile(QString path, double v1)
double estimatedProcessingTime(double estSerTime, double estParallelTime)
void newData(QcepDoubleImageDataPtr image, QcepMaskDataPtr overflow)
QxrdDataProcessorThreaded(QcepSettingsSaverWPtr saver, QxrdExperimentWPtr doc, QxrdAcquisitionWPtr acq, QxrdFileSaverWPtr filesaver)
QWeakPointer< QxrdExperiment > QxrdExperimentWPtr
void statusMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const
QSharedPointer< QcepIntegratedData > QcepIntegratedDataPtr
void correlateImages(QStringList names)
virtual ~QxrdDataProcessorThreaded()
void onROIDataAvailable()
void sumImages(QStringList names)
void fitPeakNear(double x, double y)
QcepDoubleImageDataPtr correctInt16Image(QcepDoubleImageDataPtr corrected, QcepInt16ImageDataPtr image, QcepDoubleImageDataPtr dark, QcepMaskDataPtr mask, QcepMaskDataPtr overflow)
void enqueue(QFuture< T > future)
void integrateAndAccumulate(QStringList names)
bool displayIntegratedData
QcepDoubleImageDataPtr data() const
QcepIntegratedDataPtr integrateImage(QcepIntegratedDataPtr integ, QcepDoubleImageDataPtr image, QcepMaskDataPtr mask, double cx, double cy)
QcepDoubleImageDataPtr correctInt32Image(QcepDoubleImageDataPtr corrected, QcepInt32ImageDataPtr image, QcepDoubleImageDataPtr dark, QcepMaskDataPtr mask, QcepMaskDataPtr overflow)
QSharedPointer< QxrdROIData > QxrdROIDataPtr
QcepDoubleImageDataPtr correctDoubleImage(QcepDoubleImageDataPtr corrected, QcepDoubleImageDataPtr image, QcepDoubleImageDataPtr dark, QcepMaskDataPtr mask, QcepMaskDataPtr overflow)
QWeakPointer< QxrdFileSaver > QxrdFileSaverWPtr
void reflectHorizontally()
QList< double > QcepDoubleList
QxrdExperimentWPtr m_Experiment
QcepDoubleImageDataPtr m_Data
void slicePolygon(QVector< QPointF > poly)
void projectImages(QStringList names, int px, int py, int pz)
QxrdIntegratorPtr m_Integrator
void beginAcquisition(int isDark)
void acquiredInt16Image(QcepInt16ImageDataPtr image, QcepMaskDataPtr overflow)
void writeOutputScan(QcepIntegratedDataPtr d)
void idleInt16Image(QcepInt16ImageDataPtr image, bool liveView)
QxrdResultSerializer< QxrdROIDataPtr > m_ROIData
void subtractImages(QStringList names)
QcepDoubleImageDataPtr m_LiveData
QWeakPointer< QxrdAcquisition > QxrdAcquisitionWPtr
QSharedPointer< QcepInt32ImageData > QcepInt32ImageDataPtr
QSharedPointer< QxrdFileSaver > QxrdFileSaverPtr
void integrateSaveAndDisplay()
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const
QString filePathInDataDirectory(QString name) const
QSharedPointer< QxrdHistogramData > QxrdHistogramDataPtr
QxrdCenterFinderPtr centerFinder() const
void acquiredInt32Image(QcepInt32ImageDataPtr image, QcepMaskDataPtr overflow)
QSharedPointer< QcepInt16ImageData > QcepInt16ImageDataPtr
QSharedPointer< QcepMaskData > QcepMaskDataPtr
QxrdFileSaverWPtr m_FileSaver
void onIntegratedDataAvailable()
QWeakPointer< QcepSettingsSaver > QcepSettingsSaverWPtr
QString dataDirectory() const
void saveAccumulator(QString &path, QString filter)
QSharedPointer< QcepDoubleImageData > QcepDoubleImageDataPtr