Skip to content

Commit

Permalink
Bug in recalculateCLAHE() for GOES_16 and FengYun
Browse files Browse the repository at this point in the history
  • Loading branch information
hvanruys committed Oct 6, 2017
1 parent 7c474ba commit 8d77574
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 11 deletions.
4 changes: 2 additions & 2 deletions core/avhrrsatellite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions core/formgeostationary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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")
{
Expand Down
92 changes: 89 additions & 3 deletions core/formimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1837,6 +1837,11 @@ void FormImage::recalculateCLAHE(QVector<QString> spectrumvector, QVector<bool>
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;
Expand All @@ -1853,7 +1858,6 @@ void FormImage::recalculateCLAHE(QVector<QString> spectrumvector, QVector<bool>
npixHRV = 0;
}


QApplication::setOverrideCursor( Qt::WaitCursor ); // this might take time

quint16 *pixelsRed;
Expand Down Expand Up @@ -1930,6 +1934,27 @@ void FormImage::recalculateCLAHE(QVector<QString> spectrumvector, QVector<bool>
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];
Expand Down Expand Up @@ -1977,10 +2002,19 @@ void FormImage::recalculateCLAHE(QVector<QString> spectrumvector, QVector<bool>
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)
{
Expand Down Expand Up @@ -2013,6 +2047,15 @@ void FormImage::recalculateCLAHE(QVector<QString> spectrumvector, QVector<bool>
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)
Expand Down Expand Up @@ -2050,10 +2093,13 @@ void FormImage::recalculateCLAHE(QVector<QString> spectrumvector, QVector<bool>
}
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 ))
{
Expand Down Expand Up @@ -2102,6 +2148,27 @@ void FormImage::recalculateCLAHE(QVector<QString> spectrumvector, QVector<bool>
}
}
}
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)
{

Expand Down Expand Up @@ -2268,6 +2335,25 @@ void FormImage::recalculateCLAHE(QVector<QString> spectrumvector, QVector<bool>
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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <QMutex>

#define APPVERSION "1.2.6"
#define APPVERSION "1.2.6 beta"
using namespace std;

QMutex g_mutex;
Expand Down
4 changes: 4 additions & 0 deletions core/segmentimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ SegmentImage::SegmentImage()
{
ptrHRV[i] = NULL;
}
for( int i = 0; i < 3; i++)
{
fillvalue[i] = 0;
}

}

Expand Down
2 changes: 2 additions & 0 deletions core/segmentimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 29 additions & 1 deletion core/segmentlistgeostationary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1647,33 +1647,40 @@ 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]);
if (retval != NC_NOERR)
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]);
if (retval != NC_NOERR)
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]);
if (retval != NC_NOERR)
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]);
}


Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion core/segmentlistgeostationary.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 8d77574

Please sign in to comment.