Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 2 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 133 additions and 72 deletions.
  1. +133 −72 cloud-recognition.cpp
View
205 cloud-recognition.cpp
@@ -28,9 +28,9 @@
#define MODIS_DIR "modisdata/"
#define MODIS_TYPE1 "MOD021KM"
-#define MODIS_TYPEQ "MOD021Q"
+#define MODIS_TYPEQ "MOD02QKM"
-#define MODIS_NAME ".A2010213.0845.005.2010213163715"
+#define MODIS_NAME ".A2005152.0750.005.2010153063845"
#define MODIS_EXT ".hdf"
#define TEMP_PATH "tmp/"
@@ -39,20 +39,24 @@
#define Y_LENGTH 1000
//for colored picture
-#define REDBAND 4
-#define GREENBAND 3
-#define BLUEBAND 2
+#define REDBAND 3
+#define GREENBAND 2
+#define BLUEBAND 1
#define INFRAREDBAND 14
#define ULTRAVIOLETBAND 0
+#define WATER250THRESHOLD1 4000
+
#define DEPTH 20
#define INFRARED_THRESHOLD 430
-#define ULTRAVIOLET_THRESHOLD 10000
-#define HIGHT_CLOUD_THRESHOLD 470 //430
+#define ULTRAVIOLET_THRESHOLD 8000
+#define HIGHT_CLOUD_THRESHOLD 500 //430
#define THRESHOLD_STABLE 1000
-
+#define THRESHOLD250LOW 0.75
+#define THRESHOLD250HIGH 1.10
+#define QKM true
using namespace std;
@@ -153,8 +157,8 @@ int main(int argc, char *argv[])
intn status;
int height, width, depth;
float data[Y_LENGTH][X_LENGTH];
- //unsigned short pic[Y_LENGTH][X_LENGTH];
- unsigned short **pic; //full picture
+
+
unsigned short ***colorpic;
unsigned short **specialpic;
@@ -177,8 +181,7 @@ int main(int argc, char *argv[])
log.open(LOG);
sprintf(temppicname, "./png");
- png::image<png::rgb_pixel> tempimage(1,1);
- png::image<png::rgb_pixel> colorimage(1,1);
+ png::image<png::rgb_pixel> image(1,1);
status = 0;
sds_index = 0;
@@ -205,20 +208,16 @@ int main(int argc, char *argv[])
height = dimsizes[rank[0] - 2];
width = dimsizes[rank[0] -1];
colorpic = (unsigned short ***)malloc(sizeof(unsigned short **)*15);
- log << "allocating colorimage array " << width << "x" << height << "... ";
+ log << "allocating image array " << width << "x" << height << "... ";
log.flush();
- colorimage.resize(width, height);
+ image.resize(width, height);
log << "done\n";
log.flush();
+
+
for (depth = 0; depth < 15; depth++)
{
- log << "allocating pic array " << width << "x" << height << "... ";
- log.flush();
- pic = (unsigned short **)malloc(height*sizeof(unsigned short *));
- for (i = 0; i < height; i++)
- {
- pic[i] = (unsigned short *)malloc(width*sizeof(unsigned short));
- }
+
colorpic[depth] = (unsigned short **)malloc(height*sizeof(unsigned short *));
for (i = 0; i < height; i++)
{
@@ -230,16 +229,12 @@ int main(int argc, char *argv[])
log << "reading data array... ";
log.flush();
- readarray(sds_id, pic, rank, dimsizes, datatype, numattr, log, depth);
+
readarray(sds_id, colorpic[depth], rank, dimsizes, datatype, numattr, log, depth);
log << "done\n";
log.flush();
- log << "allocating image array " << width << "x" << height << "... ";
- log.flush();
- tempimage.resize(width, height);
- log << "done\n";
- log.flush();
+
sprintf(temppath, "./img/%s", TEMP_PATH);
if (!exists(temppath))
{
@@ -251,27 +246,11 @@ int main(int argc, char *argv[])
{
for (j = 0 ; j < width; j++)
{
- tempimage[i][j] = png::rgb_pixel((pic[i][j]*255)/32768,(pic[i][j]*255)/32768,(pic[i][j]*255)/32768 );
-
- /*
- if (pic[i][j] < THRESHOLD_UNSTABLE)
- {
- image[i][j] = png::rgb_pixel(255,0,0);
- }
- else
- if (pic[i][j] < THRESHOLD_STABLE)
- {
- image[i][j] = png::rgb_pixel(0,0, int((pic[i][j]*pic[i][j]/(65535.0*65535.0))*255.0));
- }
- else
- {
- image[i][j] = png::rgb_pixel(0,255,0);
- }
- */
+ image[i][j] = png::rgb_pixel((colorpic[depth][i][j]*255)/32768,(colorpic[depth][i][j]*255)/32768,(colorpic[depth][i][j]*255)/32768 );
}
}
- tempimage.write(temppicname);
+ image.write(temppicname);
}
}
else
@@ -280,7 +259,7 @@ int main(int argc, char *argv[])
height = dimsizes[rank[0] - 2];
width = dimsizes[rank[0] -1];
- colorimage.resize(width, height);
+ image.resize(width, height);
specialpic = (unsigned short **)malloc(height*sizeof(unsigned short *));
for (i = 0; i < height; i++)
{
@@ -289,7 +268,7 @@ int main(int argc, char *argv[])
readarray(sds_id, specialpic, rank, dimsizes, datatype, numattr, log, 0);
- tempimage.resize(width, height);
+ image.resize(width, height);
sprintf(temppath, "./img/%s", TEMP_PATH);
if (!exists(temppath))
{
@@ -300,14 +279,13 @@ int main(int argc, char *argv[])
{
for (j = 0 ; j < width; j++)
{
- tempimage[i][j] = png::rgb_pixel((specialpic[i][j]*255)/32768,(specialpic[i][j]*255)/32768,(specialpic[i][j]*255)/32768 );
+ image[i][j] = png::rgb_pixel((specialpic[i][j]*255)/32768,(specialpic[i][j]*255)/32768,(specialpic[i][j]*255)/32768 );
}
}
- tempimage.write(temppicname);
+ image.write(temppicname);
- colorimage.resize(width, height);
bool clouddetected = false;
sprintf(colorpicname, "./img/combo:clouds.png");
log << "\n begin detecting...";
@@ -321,61 +299,144 @@ int main(int argc, char *argv[])
if (colorpic[INFRAREDBAND][i][j] > INFRARED_THRESHOLD)
{
clouddetected = true;
- colorimage[i][j] = png::rgb_pixel(255,50,50);
+ image[i][j] = png::rgb_pixel(255,50,50);
}
if (colorpic[ULTRAVIOLETBAND][i][j] > ULTRAVIOLET_THRESHOLD)
{
clouddetected = true;
- colorimage[i][j] = png::rgb_pixel(50, 0, 150);
+ image[i][j] = png::rgb_pixel(50, 0, 150);
}
if (specialpic[i][j] > HIGHT_CLOUD_THRESHOLD)
{
clouddetected = true;
- colorimage[i][j] = png::rgb_pixel(100,100,255);
+ image[i][j] = png::rgb_pixel(100,100,255);
}
if (!clouddetected)
{
- colorimage[i][j] = png::rgb_pixel((colorpic[REDBAND][i][j]*255)/32768,(colorpic[GREENBAND][i][j]*255)/32768,(colorpic[BLUEBAND][i][j]*255)/32768);
+ image[i][j] = png::rgb_pixel((colorpic[REDBAND][i][j]*255)/32768,(colorpic[GREENBAND][i][j]*255)/32768,(colorpic[BLUEBAND][i][j]*255)/32768);
}
}
log<<" done";
log.flush();
- colorimage.write(colorpicname);
+ image.write(colorpicname);
}
sprintf(colorpicname, "./img/%s:color.png", MODIS_TYPE1);
for (i = 0; i < height; i ++)
for (j = 0; j < width; j++)
{
- colorimage[i][j] = png::rgb_pixel((colorpic[REDBAND][i][j]*255)/32768,(colorpic[GREENBAND][i][j]*255)/32768,(colorpic[BLUEBAND][i][j]*255)/32768);
+ //0.013130542, 0.008167851, 0.004951446, 0.0033423917, 0.002928792, 0.0011045014, 8.184314E-4, 0.0012381239, 6.842502E-4, 9.4946625E-4, 8.9297467E-4, 0.0071642217, 0.008927347, 0.0068932013, 0.0030190486
+ image[i][j] = png::rgb_pixel(int((colorpic[REDBAND][i][j]*255)/32768.0),
+ int((colorpic[GREENBAND][i][j]*255)/32768.0),
+ int((colorpic[BLUEBAND][i][j]*255)/32768.0));
}
- colorimage.write(colorpicname);
+ image.write(colorpicname);
+
+ }
+ sds_index++;
+ }
+
+
+
+ status = 0;
+ sds_index = 0;
+
+ sprintf(modisfilepath, "%s%s%s%s", MODIS_DIR, MODIS_TYPEQ, MODIS_NAME, MODIS_EXT);
+ if (QKM)
+ while (status == 0)
+ {
+ sd_id = SDstart (modisfilepath, DFACC_READ);
+ sds_id = SDselect (sd_id, sds_index);
+
+ status = SDgetinfo(sds_id, sdsname, rank, dimsizes, datatype, numattr);
+ if (status == 0)
+ {
+ for (i = 0; i < *rank; i++)
+ {
+ log << dimsizes[i] << ", ";
+ }
+ log << endl;
+ //SDattrinfo(sds_id, )
+ if (strcmp(sdsname, "EV_250_RefSB") == 0)
+ {
+
+ height = dimsizes[rank[0] - 2];
+ width = dimsizes[rank[0] -1];
+ colorpic = (unsigned short ***)malloc(sizeof(unsigned short **)*15);
+ log << "allocating image array " << width << "x" << height << "... ";
+ log.flush();
+ image.resize(width, height);
+ log << "done\n";
+ log.flush();
- /*
- for (int rr = 14; rr < 15; rr++)
- for (int gg = 0; gg < 15; gg++)
- for (int bb = 0; bb < 15; bb++)
+
+ for (depth = 0; depth < 2; depth++)
+ {
+
+ colorpic[depth] = (unsigned short **)malloc(height*sizeof(unsigned short *));
+ for (i = 0; i < height; i++)
{
+ colorpic[depth][i] = (unsigned short *)malloc(width*sizeof(unsigned short));
+ }
+
+ readarray(sds_id, colorpic[depth], rank, dimsizes, datatype, numattr, log, depth);
- sprintf(colorpicname, "./img/colortest/%s:%d:%d:%d:color.png", sdsname, rr, gg, bb);
- //color picture
- for (i = 0; i < height; i++)
+
+ sprintf(temppath, "./img/%s", TEMP_PATH);
+ if (!exists(temppath))
+ {
+ mkdir(temppath, 0777);
+ }
+ sprintf(temppicname, "%s%s:%d:%d.png",temppath, sdsname, sds_index, depth);
+ //picture of one band
+ for (i = 0; i < height; i++)
+ {
+ for (j = 0 ; j < width; j++)
{
- for (j = 0 ; j < width; j++)
- {
- colorimage[i][j] = png::rgb_pixel((colorpic[rr][i][j]*255)/32768,(colorpic[gg][i][j]*255)/32768,(colorpic[bb][i][j]*255)/32768 );
- }
+ image[i][j] = png::rgb_pixel((colorpic[depth][i][j]*255)/32768,
+ (colorpic[depth][i][j]*255)/32768,
+ (colorpic[depth][i][j]*255)/32768 );
}
- colorimage.write(colorpicname);
+
}
- */
+ image.write(temppicname);
+ }
+ }
+
+
+ }
+ sds_index++;
}
- sds_index++;
- }
+ sprintf(colorpicname, "./img/%s:color.png", MODIS_TYPEQ);
+ for (i = 0; i < height; i ++)
+ for (j = 0; j < width; j++)
+ {
+ image[i][j] = png::rgb_pixel((colorpic[1][i][j]*255)/32768,
+ ((colorpic[0][i][j]*255)+3*(colorpic[1][i][j]*255))/(32768*4),
+ ((colorpic[0][i][j]*255)+(colorpic[1][i][j]*255))/(32768*2));
+ }
+ image.write(colorpicname);
+ sprintf(colorpicname, "./img/%s:cloud.png", MODIS_TYPEQ);
+ for (i = 0; i < height; i ++)
+ for (j = 0; j < width; j++)
+ {
+ if ((colorpic[1][i][j]/colorpic[0][i][j] < THRESHOLD250HIGH)&&(colorpic[1][i][j]/colorpic[0][i][j] > THRESHOLD250LOW))
+ {
+ if (colorpic[1][i][j] > WATER250THRESHOLD1)
+ {
+ image[i][j] = png::rgb_pixel(255, 0, 255);
+ }
+ else
+ {
+ image[i][j] = png::rgb_pixel(60, 60, 255);
+ }
+ }
+ }
+ image.write(colorpicname);
printf("done\n");
status = SDendaccess (sds_id);

No commit comments for this range

Something went wrong with that request. Please try again.