From 8d7757408cabb2af155302883bfe49cf7be37bf1 Mon Sep 17 00:00:00 2001 From: hvanruys Date: Fri, 6 Oct 2017 13:55:13 +0200 Subject: [PATCH] Bug in recalculateCLAHE() for GOES_16 and FengYun --- core/avhrrsatellite.cpp | 4 +- core/formgeostationary.cpp | 6 +- core/formimage.cpp | 92 ++++++++++++++++++++++++++++++- core/main.cpp | 2 +- core/segmentimage.cpp | 4 ++ core/segmentimage.h | 2 + core/segmentlistgeostationary.cpp | 30 +++++++++- core/segmentlistgeostationary.h | 4 +- 8 files changed, 133 insertions(+), 11 deletions(-) diff --git a/core/avhrrsatellite.cpp b/core/avhrrsatellite.cpp index 1bf4869..721d639 100755 --- a/core/avhrrsatellite.cpp +++ b/core/avhrrsatellite.cpp @@ -414,7 +414,7 @@ void AVHRRSatellite::AddSegmentsToList(QFileInfoList fileinfolist) segmentlistmapgeo[i].insert( strdate, hashspectrum ); } } - //qDebug() << opts.geosatellites.at(i).shortname << " " << fileInfo.fileName() << " " << strdate << " " << strspectrum << " " << QString("%1").arg(filenbr); + qDebug() << opts.geosatellites.at(i).shortname << " " << fileInfo.fileName() << " " << strdate << " " << strspectrum << " " << QString("%1").arg(filenbr); } } @@ -453,7 +453,7 @@ void AVHRRSatellite::getFilenameParameters(int geosatindex, QString filename, Q filenbr = filename.mid(opts.geosatellites.at(geosatindex).indexfilenbr, opts.geosatellites.at(geosatindex).lengthfilenbr).toInt(); strdate = filename.mid(opts.geosatellites.at(geosatindex).indexdate, opts.geosatellites.at(geosatindex).lengthdate); - if( strdate.length() == 11) //convert YYYYDDDHHmm to YYYYMMDDHHmm + if( opts.geosatellites.at(geosatindex).shortname == "GOES_16" ) //convert YYYYDDDHHmm to YYYYMMDDHHmm { QDate fdate = QDate(strdate.mid(0, 4).toInt(), 1, 1).addDays(strdate.mid(4, 3).toInt() - 1); strdate = fdate.toString("yyyyMMdd") + strdate.mid(7, 4); diff --git a/core/formgeostationary.cpp b/core/formgeostationary.cpp index 727b23a..50da4f3 100755 --- a/core/formgeostationary.cpp +++ b/core/formgeostationary.cpp @@ -1120,7 +1120,7 @@ void FormGeostationary::CreateGeoImageXRIT(SegmentListGeostationary *sl, QString filesequence = fileinfo.fileName().mid(opts.geosatellites.at(geoindex).indexfilenbr, opts.geosatellites.at(geoindex).lengthfilenbr).toInt()-1; filespectrum = fileinfo.fileName().mid(opts.geosatellites.at(geoindex).indexspectrum, opts.geosatellites.at(geoindex).spectrumlist.at(0).length()); filedate = fileinfo.fileName().mid(opts.geosatellites.at(geoindex).indexdate, opts.geosatellites.at(geoindex).lengthdate); - filedate.resize(12, '0'); + filedate.leftJustified(12, '0'); sl->InsertPresent( spectrumvector, filespectrum, filesequence); @@ -1139,7 +1139,7 @@ void FormGeostationary::CreateGeoImageXRIT(SegmentListGeostationary *sl, QString filesequence = fileinfo.fileName().mid(opts.geosatellites.at(geoindex).indexfilenbrhrv, opts.geosatellites.at(geoindex).lengthfilenbrhrv).toInt()-1; filespectrum = fileinfo.fileName().mid(opts.geosatellites.at(geoindex).indexspectrumhrv, opts.geosatellites.at(geoindex).spectrumhrv.length()); filedate = fileinfo.fileName().mid(opts.geosatellites.at(geoindex).indexdatehrv, opts.geosatellites.at(geoindex).lengthdatehrv); - filedate.resize(12, '0'); + filedate.leftJustified(12, '0'); sl->InsertPresent( spectrumvector, filespectrum, filesequence); @@ -1283,7 +1283,7 @@ void FormGeostationary::CreateGeoImagenetCDF(SegmentListGeostationary *sl, QStri else return; - sl->InsertPresent( spectrumvector, "", 0); + //sl->InsertPresent( spectrumvector, "", 0); if(type == "VIS_IR" || type == "VIS_IR Color") { diff --git a/core/formimage.cpp b/core/formimage.cpp index ef776a7..31862ec 100755 --- a/core/formimage.cpp +++ b/core/formimage.cpp @@ -1837,6 +1837,11 @@ void FormImage::recalculateCLAHE(QVector spectrumvector, QVector npix = 2816*7*464; npixHRV = 0; } + else if(sl->getGeoSatellite() == eGeoSatellite::GOES_16) + { + npix = 5424*5424; + npixHRV = 0; + } else if(sl->getGeoSatellite() == eGeoSatellite::GOMS2) { npix = 2784*6*464; @@ -1853,7 +1858,6 @@ void FormImage::recalculateCLAHE(QVector spectrumvector, QVector npixHRV = 0; } - QApplication::setOverrideCursor( Qt::WaitCursor ); // this might take time quint16 *pixelsRed; @@ -1930,6 +1934,27 @@ void FormImage::recalculateCLAHE(QVector spectrumvector, QVector memcpy(pixelsBlue + i * 550 * 5500, imageptrs->ptrBlue[i], 550 * 5500 * sizeof(quint16)); } } + else if(sl->getKindofImage() == "VIS_IR Color" && sl->getGeoSatellite() == eGeoSatellite::GOES_16) + { + pixelsRed = new quint16[npix]; + pixelsGreen = new quint16[npix]; + pixelsBlue = new quint16[npix]; + + memcpy(pixelsRed, imageptrs->ptrRed[0], npix * sizeof(quint16)); + memcpy(pixelsGreen, imageptrs->ptrGreen[0], npix * sizeof(quint16)); + memcpy(pixelsBlue, imageptrs->ptrBlue[0], npix * sizeof(quint16)); + + for(int i = 0; i < npix; i++) + { + if(*(pixelsRed+i) == imageptrs->fillvalue[0] ) + *(pixelsRed + i) = 0; + if(*(pixelsGreen+i) == imageptrs->fillvalue[1] ) + *(pixelsGreen + i) = 0; + if(*(pixelsBlue+i) == imageptrs->fillvalue[2] ) + *(pixelsBlue + i) = 0; + } + + } else if(sl->getKindofImage() == "HRV" && (sl->getGeoSatellite() == eGeoSatellite::MET_10 || sl->getGeoSatellite() == eGeoSatellite::MET_9 || sl->getGeoSatellite() == eGeoSatellite::MET_8 )) { pixelsHRV = new quint16[npixHRV]; @@ -1977,10 +2002,19 @@ void FormImage::recalculateCLAHE(QVector spectrumvector, QVector else if(sl->getKindofImage() == "VIS_IR" && (sl->getGeoSatellite() == eGeoSatellite::FY2E || sl->getGeoSatellite() == eGeoSatellite::FY2G )) { pixelsRed = new quint16[npix]; - if(sl->isPresentRed[0]) + memcpy(pixelsRed, imageptrs->ptrRed[0], 2288 * 2288 * sizeof(quint16)); + } + else if(sl->getKindofImage() == "VIS_IR" && (sl->getGeoSatellite() == eGeoSatellite::GOES_16 )) + { + pixelsRed = new quint16[npix]; + memcpy(pixelsRed, imageptrs->ptrRed[0], npix * sizeof(quint16)); + + for(int i = 0; i < npix; i++) { - memcpy(pixelsRed, imageptrs->ptrRed[0], 2288 * 2288 * sizeof(quint16)); + if(*(pixelsRed+i) == imageptrs->fillvalue[0] ) + *(pixelsRed + i) = 0; } + } else if(sl->getKindofImage() == "VIS_IR" && sl->getGeoSatellite() == eGeoSatellite::H8) { @@ -2013,6 +2047,15 @@ void FormImage::recalculateCLAHE(QVector spectrumvector, QVector imageptrs->CLAHE(pixelsGreen, 5500, 5500, 0, 1023, 10, 10, 256, opts.clahecliplimit); imageptrs->CLAHE(pixelsBlue, 5500, 5500, 0, 1023, 10, 10, 256, opts.clahecliplimit); } + else if(sl->getKindofImage() == "VIS_IR Color" && sl->getGeoSatellite() == eGeoSatellite::GOES_16 ) + { + ret = imageptrs->CLAHE(pixelsRed, 5424, 5424, 0, 1023, 16, 16, 256, opts.clahecliplimit); + qDebug() << QString("pixelsRed ret = %1").arg(ret); + ret = imageptrs->CLAHE(pixelsGreen, 5424, 5424, 0, 1023, 16, 16, 256, opts.clahecliplimit); + qDebug() << QString("pixelsGreen ret = %1").arg(ret); + ret = imageptrs->CLAHE(pixelsBlue, 5424, 5424, 0, 1023, 16, 16, 256, opts.clahecliplimit); + qDebug() << QString("pixelsBlue ret = %1").arg(ret); + } else if(sl->getKindofImage() == "HRV" && (sl->getGeoSatellite() == eGeoSatellite::MET_10 || sl->getGeoSatellite() == eGeoSatellite::MET_9 || sl->getGeoSatellite() == eGeoSatellite::MET_8)) { if(sl->bisRSS) @@ -2050,10 +2093,13 @@ void FormImage::recalculateCLAHE(QVector spectrumvector, QVector } else if(sl->getGeoSatellite() == eGeoSatellite::FY2E || sl->getGeoSatellite() == eGeoSatellite::FY2G) imageptrs->CLAHE(pixelsRed, 2288, 2288, 0, 255, 16, 16, 256, opts.clahecliplimit); + else if(sl->getGeoSatellite() == eGeoSatellite::GOES_16) + imageptrs->CLAHE(pixelsRed, 5424, 5424, 0, 1023, 16, 16, 256, opts.clahecliplimit); else if(sl->getGeoSatellite() == eGeoSatellite::H8) imageptrs->CLAHE(pixelsRed, 5500, 5500, 0, 1023, 10, 10, 256, opts.clahecliplimit); } + qDebug() << "---> After CLAHE"; if(sl->getKindofImage() == "VIS_IR Color" && (sl->getGeoSatellite() == eGeoSatellite::MET_10 || sl->getGeoSatellite() == eGeoSatellite::MET_9 || sl->getGeoSatellite() == eGeoSatellite::MET_8 )) { @@ -2102,6 +2148,27 @@ void FormImage::recalculateCLAHE(QVector spectrumvector, QVector } } } + else if(sl->getKindofImage() == "VIS_IR Color" && sl->getGeoSatellite() == eGeoSatellite::GOES_16) + { + + for (int line = 0; line < 5424; line++) + { + row_col = (QRgb*)imageptrs->ptrimageGeostationary->scanLine(line); + for (int pixelx = 0; pixelx < 5424; pixelx++) + { + cred = *(pixelsRed + line * 5424 + pixelx); + cgreen = *(pixelsGreen + line * 5424 + pixelx); + cblue = *(pixelsBlue + line * 5424 + pixelx); + + r = quint8(inversevector[0] ? 255 - (int)(cred/4) : (int)(cred/4)); + g = quint8(inversevector[1] ? 255 - (int)(cgreen/4) : (int)(cgreen/4)); + b = quint8(inversevector[2] ? 255 - (int)(cblue/4) : (int)(cblue/4)); + + row_col[pixelx] = qRgb(r,g,b); + } + } + + } else if(sl->getKindofImage() == "VIS_IR Color" && sl->getGeoSatellite() == eGeoSatellite::GOMS2) { @@ -2268,6 +2335,25 @@ void FormImage::recalculateCLAHE(QVector spectrumvector, QVector g = quint8(inversevector[0] ? 255 - c : c); b = quint8(inversevector[0] ? 255 - c : c); + row_col[pixelx] = qRgb(r,g,b); + } + } + } + else if(sl->getGeoSatellite() == eGeoSatellite::GOES_16) + { + qDebug() << "recalculate CLAHE ; VIS_IR and GOES_16 move to ptrImageGeostationary"; + + for (int line = 0; line < 5424; line++) + { + row_col = (QRgb*)imageptrs->ptrimageGeostationary->scanLine(line); + for (int pixelx = 0; pixelx < 5424; pixelx++) + { + c = *(pixelsRed + line * 5424 + pixelx); + + r = quint8(inversevector[0] ? 255 - (int)(c/4) : (int)(c/4)); + g = quint8(inversevector[0] ? 255 - (int)(c/4) : (int)(c/4)); + b = quint8(inversevector[0] ? 255 - (int)(c/4) : (int)(c/4)); + row_col[pixelx] = qRgb(r,g,b); } } diff --git a/core/main.cpp b/core/main.cpp index 38eb3a7..ad2443a 100755 --- a/core/main.cpp +++ b/core/main.cpp @@ -12,7 +12,7 @@ #include -#define APPVERSION "1.2.6" +#define APPVERSION "1.2.6 beta" using namespace std; QMutex g_mutex; diff --git a/core/segmentimage.cpp b/core/segmentimage.cpp index cff5533..0eaeb7e 100755 --- a/core/segmentimage.cpp +++ b/core/segmentimage.cpp @@ -44,6 +44,10 @@ SegmentImage::SegmentImage() { ptrHRV[i] = NULL; } + for( int i = 0; i < 3; i++) + { + fillvalue[i] = 0; + } } diff --git a/core/segmentimage.h b/core/segmentimage.h index d532d48..71435fe 100755 --- a/core/segmentimage.h +++ b/core/segmentimage.h @@ -114,6 +114,8 @@ class SegmentImage double SigmadistGAC[409]; double fractionGAC[409]; + int fillvalue[3]; //used for GOES_16 + private: void ClipHistogram (unsigned long* pulHistogram, unsigned int diff --git a/core/segmentlistgeostationary.cpp b/core/segmentlistgeostationary.cpp index 5df6329..5bf257f 100755 --- a/core/segmentlistgeostationary.cpp +++ b/core/segmentlistgeostationary.cpp @@ -225,7 +225,7 @@ void SegmentListGeostationary::ResetSegments() } } -bool SegmentListGeostationary::getFilenameParameters(QFileInfo fileinfo, QString &filespectrum, QString &filedate, int &filesequence) +void SegmentListGeostationary::getFilenameParameters(QFileInfo fileinfo, QString &filespectrum, QString &filedate, int &filesequence) { int index = opts.geosatellites.at(this->geoindex).indexspectrumhrv; @@ -1647,8 +1647,10 @@ void SegmentListGeostationary::ComposeSegmentImagenetCDFInThread(QStringList fil qDebug() << QString("add_offset = %1").arg(add_offset[j]); qDebug() << QString("_FillValue = %1").arg(fillvalue[j]); + if(j==0) { + imageptrs->fillvalue[j] = fillvalue[j]; imageptrs->ptrRed[0] = new quint16[xdim * ydim]; memset(imageptrs->ptrRed[0], 0, xdim * ydim * sizeof(quint16)); retval = nc_get_var_ushort(ncfileid[j], varid, imageptrs->ptrRed[0]); @@ -1656,8 +1658,10 @@ void SegmentListGeostationary::ComposeSegmentImagenetCDFInThread(QStringList fil qDebug() << "error reading Rad values"; else CalculateMinMaxGOES16(xdim, ydim, imageptrs->ptrRed[0], stat_min[0], stat_max[0], fillvalue[0]); + normalizeMinMaxGOES16(xdim, ydim, imageptrs->ptrRed[0], stat_min[0], stat_max[0], fillvalue[0]); } else if(j==1) { + imageptrs->fillvalue[j] = fillvalue[j]; imageptrs->ptrGreen[0] = new quint16[xdim * ydim]; memset(imageptrs->ptrGreen[0], 0, xdim * ydim * sizeof(quint16)); retval = nc_get_var_ushort(ncfileid[j], varid, imageptrs->ptrGreen[0]); @@ -1665,8 +1669,10 @@ void SegmentListGeostationary::ComposeSegmentImagenetCDFInThread(QStringList fil qDebug() << "error reading Rad values"; else CalculateMinMaxGOES16(xdim, ydim, imageptrs->ptrGreen[0], stat_min[1], stat_max[1], fillvalue[1]); + normalizeMinMaxGOES16(xdim, ydim, imageptrs->ptrGreen[0], stat_min[1], stat_max[1], fillvalue[1]); } else if(j == 2) { + imageptrs->fillvalue[j] = fillvalue[j]; imageptrs->ptrBlue[0] = new quint16[xdim * ydim]; memset(imageptrs->ptrBlue[0], 0, xdim * ydim * sizeof(quint16)); retval = nc_get_var_ushort(ncfileid[j], varid, imageptrs->ptrBlue[0]); @@ -1674,6 +1680,7 @@ void SegmentListGeostationary::ComposeSegmentImagenetCDFInThread(QStringList fil qDebug() << "error reading Rad values"; else CalculateMinMaxGOES16(xdim, ydim, imageptrs->ptrBlue[0], stat_min[2], stat_max[2], fillvalue[2]); + normalizeMinMaxGOES16(xdim, ydim, imageptrs->ptrBlue[0], stat_min[2], stat_max[2], fillvalue[2]); } @@ -2307,6 +2314,27 @@ void SegmentListGeostationary::CalculateMinMaxGOES16(int width, int height, quin } +void SegmentListGeostationary::normalizeMinMaxGOES16(int width, int height, quint16 *ptr, quint16 &stat_min, quint16 &stat_max, quint16 fillvalue) +{ + + for (int j = 0; j < height; j++) { + for (int i = 0; i < width; i++) + { + quint16 val = ptr[j * height + i]; + if(val != fillvalue) + { + float valfloat = (float)((float)(val - stat_min)/(float)(stat_max - stat_min)); + quint16 valint = (quint16)(valfloat*1023.0); + ptr[j * height + i] = valint; + } + } + } + + stat_min = 0; + stat_max = 1023; + +} + void SegmentListGeostationary::CalculateMinMaxHimawari(int width, int height, quint16 *ptr, quint16 &stat_min, quint16 &stat_max) { stat_min = 65535; diff --git a/core/segmentlistgeostationary.h b/core/segmentlistgeostationary.h index 1fa6784..99eef8d 100755 --- a/core/segmentlistgeostationary.h +++ b/core/segmentlistgeostationary.h @@ -50,6 +50,8 @@ class SegmentListGeostationary : public QObject void CalculateMinMax(int width, int height, quint16 *ptr, quint16 &stat_min, quint16 &stat_max); void CalculateMinMaxGOES16(int width, int height, quint16 *ptr, quint16 &stat_min, quint16 &stat_max, quint16 fillvalue); void CalculateMinMaxHimawari(int width, int height, quint16 *ptr, quint16 &stat_min, quint16 &stat_max); + void normalizeMinMaxGOES16(int width, int height, quint16 *ptr, quint16 &stat_min, quint16 &stat_max, quint16 fillvalue); + QString getKindofImage() { return kindofimage; } QString getImagePath() { return imagepath; } void setImagePath( QString ip) { imagepath = ip; } @@ -110,7 +112,7 @@ class SegmentListGeostationary : public QObject private: void ComposeColorHRV(); - bool getFilenameParameters(QFileInfo fileinfo, QString &filespectrum, QString &filedate, int &filesequence); + void getFilenameParameters(QFileInfo fileinfo, QString &filespectrum, QString &filedate, int &filesequence); quint16 maxvalueRed[10]; quint16 minvalueRed[10];