REPAIR_IMAGE.sml

  Download

More scripts: Scripts By Jack

Syntax Highlighing:

comments, key words, predefined symbols, class members & methods, functions & classes
            
# ------------------------------------------------------------
# REPAIR_IMAGE.sml
# ------------------------------------------------------------
# SET WARNING LEVEL: Refer to B5 & B6.
  $warnings 3
# ------------------------------------------------------------
# DEFINE VARIABLES FOR GENERAL CHARACTER STRINGS:
# Refer to B7.
  string t$,p$,p1$,p2$,p3$,p4$,p5$,p6$,p7$,p8$,p9$;
  string p10$,p11$,p12$,p13$,p14$,p15$,p16$,p17$,p18$,p19$;
  string p20$,p21$;
# ------------------------------------------------------------
# CLEAR CONSOLE WINDOW & REQUEST REPOSITIONING:
# Refer to B7, B8 & B9.
  clear();
  p1$ = "CONSOLE-WINDOW ADJUSTMENT\n";
  p2$ = "* REPOSITION the CONSOLE WINDOW.\n";
  p3$ = "* Then, CLICK the OK Button.";
  p$  = p1$ + p2$ + p3$;
  PopupMessage(p$);
# ------------------------------------------------------------
# DEFINE PROCEDURE writeTitle: Refer to B13 & B14.
# PURPOSE: WRITES TITLE & AUTHOR INFO TO CONSOLE WINDOW.
  proc writeTitle() begin
     printf("REPAIR_IMAGE.sml:\n\n");
     printf("         VERSION: October 12, 2005\n");
     printf("         PURPOSE: FINDS & FIXES ");
     printf("ERRONEOUS DN VALUES.\n");
     printf("       RATIONALE: Valid Image DNs Are Not ");
     printf("Equal to the Fill Value.\n");
     printf("     NOT CHANGED: CB, BL GL (if Exists)\n");
     printf("         DETAILS: FAQs_by_Jack A & B\n");
     printf("          AUTHOR: Dr. Jack F. Paris\n");
     printf("    CONTACT INFO: [email protected] ");
     printf(" 303-775-1195\n");
     printf("     ALLOWED USE: ONLY NON-COMMERCIAL\n\n");
  end
# ------------------------------------------------------------
# WRITE TITLE & AUTHOR INFORMATION: Refer to B14.
  writeTitle();
# ------------------------------------------------------------
# DECLARE USER-INPUT VARIABLE:
  numeric imager,dnfill,dnfillm1;
# ------------------------------------------------------------
# DECLARE VARIABLES RELATED TO DATA TYPES OF RASTERS:
# Refer to B15 & B16.
  string dntype$;
# ------------------------------------------------------------
# DECLARE VARIABLES RELATED TO USER-INPUT VARIABLES:
# Refer to B15 & B16.
  string imager$;
# ------------------------------------------------------------
# DECLARE VARIABLES RELATED TO BOOLEAN ENABLERS: 
# Refer to B15 & B16.
  numeric pYL,pRE,pNA,pNB;
  numeric pMA,pMB,pMC,pMD,pME,pMF,pMG;
# ------------------------------------------------------------
# DECLARE LIST OF POSSIBLE INPUT RASTERS: Refer to B15 & B16.
  raster GL,YL,RL,RE,NA,NB,MA,MB,MC,MD,ME,MF,MG;
# ------------------------------------------------------------
# DECLARE VARIABLES RELATED TO LOOPS: Refer to B15 & B16.
  numeric nlins,ncols;
# ------------------------------------------------------------
# DECLARE VARIABLES RELATED TO INPUT RASTERS: 
# Refer to B15 & B16.
  numeric dnGL,dnYL,dnRL,dnRE,dnNA,dnNB;
  numeric dnMA,dnMB,dnMC,dnMD,dnME,dnMF,dnMG,dnsub;
  numeric fpYL,fpRL,fpRE,fpNA,fpNB;
  numeric fpMA,fpMB,fpMC,fpMD,fpME,fpMF,fpMG;
  numeric isnGL,isnYL,isnRL,isnRE;
  numeric isnNA,isnNB,isnMA,isnMB,isnMC,isnMD,isnME;
  numeric isnMF,isnMG;
# ------------------------------------------------------------
# GET IMAGER NUMBER FROM THE USER: Refer to B17.
  p1$  = "IMAGER-NUMBER SELECTION\n";
  p2$  = "  IMAGER\n";
  p3$  = "  NUMBER:  SYSTEM NAME\n";
  p4$  = "       1:  QuickBird 2 MS\n";
  p5$  = "       2:  Ikonos 2 MS\n";
  p6$  = "       3:  OrbView 3 MS\n";
  p7$  = "       4:  Landsat 7 ETM+\n";
  p8$  = "       5:  Landsat 5 TMAvailable\n";
  p9$  = "       6:  Landsat 5 MSS";
  p10$ = "       7:  Landsat 4 TM\n";
  p11$ = "       8:  Landsat 4 MSS\n";
  p12$ = "       9:  Landsat 3 MSS\n";
  p13$ = "      10:  Landsat 2 MSS\n";
  p14$ = "      11:  Landsat 1 MSS\n";
  p15$ = "      12:  Terra ASTER\n";
  p16$ = "      13:  Terra MODIS\n";
  p17$ = "      14:  Aqua MODIS\n";
  p18$ = "* Either ACCEPT the Default NUMBER,\n";
  p19$ = "* Or, SELECT a Different NUMBER.\n";
  p20$ = "* Then, CLICK the OK Button.\n\n";
  p21$ = "IMAGER-NUMBER SELECTED:";
  p$   = p1$ + p2$ + p3$ + p4$ + p5$ + p6$ + p7$ + p8$ + p9$;
  p$   = p$ + p10$ + p11$ + p12$ + p13$ + p14$ + p15$ + p16$;
  p$   = p$ + p17$ + p18$ + p19$ + p20$ + p21$;
  imager = PopupNum(p$,4,14,1,0);  
# ------------------------------------------------------------
# GENERATE IMAGER-SPECIFIC PARAMETERS: Refer to B25.
# GL Raster is Used with Other Rasters to Detection Errors.
  dnfill = 0;
  if (imager == 1) then begin
     imager$ = "QuickBird 2 MS"; pNA=1;
  end
  if (imager == 2) then begin
     imager$ = "Ikonos 2 MS"; pNA=1;
  end
  if (imager == 3) then begin
     imager$ = "OrbView 3 MS"; pNA=1;
  end
  if (imager == 4) then begin
     imager$ = "Landsat 7 ETM+"; pNA=1; pMB=1; pMC=1;
  end
  if (imager == 5) then begin
     imager$ = "Landsat 5 TM"; pNA=1; pMB=1; pMC=1;
  end
  if (imager == 6) then begin
     imager$ = "Landsat 5 MSS"; pRE=1; pNB=1;
  end
  if (imager == 7) then begin
     imager$ = "Landsat 4 TM"; pNA=1; pMB=1;
  end
  if (imager == 8) then begin
     imager$ = "Landast 4 MSS"; pRE=1; pNB=1;
  end
  if (imager == 9) then begin
     imager$ = "Landsat 3 MSS"; pRE=1; pNB=1;
  end
  if (imager == 10) then begin
     imager$ = "Landsat 2 MSS"; pRE=1; pNB=1;
  end
  if (imager == 11) then begin
     imager$ = "Landsat 1 MSS"; pRE=1; pNB=1;
  end
  if (imager == 12) then begin
     imager$ = "Terra ASTER"; pNA=1; pMB=1; pMC=1;
     pMD=1; pME=1; pMF=1; pMG=1;
  end
  if (imager == 13) then begin
     imager$ = "Terra MODIS"; pNA=1; pMA=1; pMB=1; pMC=1;
  end
  if (imager == 14) then begin
     imager$ = "Aqua MODIS"; pNA=1; pMA=1; pMB=1; pMC=1;
  end
  dnsub = dnfill - 1;
  if (dnfill == 0) then dnsub = 1;
  printf("          IMAGER: %s\n",imager$);
  printf("      FILL VALUE: %d\n",dnfill);
  printf("SUBSTITUTE VALUE: %d\n\n",dnsub);
# ------------------------------------------------------------
# OPEN APPROPRIATE INPUT RASTERS:
  printf("OPEN INPUT RASTERS:\n");
  printf(" GL");
  GetInputRaster(GL);
  nlins = NumLins(GL); ncols = NumCols(GL);
  dntype$ = RastType(GL);
  printf(" RL");
  if (pYL) then begin
     printf(" YL");
     GetInputRaster(YL,nlins,ncols,dntype$);
     DeleteHistogram(YL); DeletePyramid(YL);
  end
  GetInputRaster(RL,nlins,ncols,dntype$);
  DeleteHistogram(RL); DeletePyramid(RL);
  if (pRE) then begin
     printf(" RE");
     GetInputRaster(RE,nlins,ncols,dntype$);
     DeleteHistogram(RE); DeletePyramid(RE);
  end
  if (pNA) then begin
     printf(" NA");
     GetInputRaster(NA,nlins,ncols,dntype$);
     DeleteHistogram(NA); DeletePyramid(NA);
  end
  if (pNB) then begin
     printf(" NB");
     GetInputRaster(NB,nlins,ncols,dntype$);
     DeleteHistogram(NB); DeletePyramid(NB);
  end
  if (pMA) then begin
     printf(" MA");
     GetInputRaster(MA,nlins,ncols,dntype$);
     DeleteHistogram(MA); DeletePyramid(MA);
  end
  if (pMB) then begin
     printf(" MB");
     GetInputRaster(MB,nlins,ncols,dntype$);
     DeleteHistogram(MB); DeletePyramid(MB);
  end
  if (pMC) then begin
     printf(" MC");
     GetInputRaster(MC,nlins,ncols,dntype$);
     DeleteHistogram(MC); DeletePyramid(MC);
  end
  if (pMD) then begin
     printf(" MD");
     GetInputRaster(MD,nlins,ncols,dntype$);
     DeleteHistogram(MD); DeletePyramid(MD);
  end
  if (pME) then begin
     printf(" ME");
     GetInputRaster(ME,nlins,ncols,dntype$);
     DeleteHistogram(ME); DeletePyramid(ME);
  end
  if (pMF) then begin
     printf(" MF");
     GetInputRaster(MF,nlins,ncols,dntype$);
     DeleteHistogram(MF); DeletePyramid(MF);
  end
  if (pMG) then begin
     printf(" MG");
     GetInputRaster(MG,nlins,ncols,dntype$);
     DeleteHistogram(MG); DeletePyramid(MG);
  end
  printf("\n\n");
# ------------------------------------------------------------
# PROCESS RASTERS:
  printf("PROCESS INPUT RASTERS: \n");
  if (pYL) then begin
     printf(" YL");
     fpYL = 0;
     for each GL begin
        isnYL = IsNull(YL);
        if (isnYL) then begin
           isnGL = IsNull(GL);
           if (isnGL == 0) then begin
              YL = dnsub; fpYL = fpYL + 1;
           end
        end
     end
     CreateHistogram(YL,0); CreatePyramid(YL,0);
     CloseRaster(YL);
  end
  printf(" RL");
  fpRL = 0;
  for each GL begin
     isnRL = IsNull(RL);
     if (isnRL) then begin
        isnGL = IsNull(GL);
        if (isnGL == 0) then begin
           RL = dnsub; fpRL = fpRL + 1;
        end
     end
  end
  CreateHistogram(RL,0); CreatePyramid(RL,0);
  CloseRaster(RL);
  if (pRE) then begin
     fpRE = 0;
     printf(" RE");
     for each GL begin
        isnRE = IsNull(RE);
        if (isnRE) then begin
           isnGL = IsNull(GL);
           if (isnGL == 0) then begin
              RE = dnsub; fpRE = fpRE + 1;
           end
        end
     end
     CreateHistogram(RE,0); CreatePyramid(RE,0);
     CloseRaster(RE);
  end
  if (pNA) then begin
     fpNA = 0;
     printf(" NA");
     for each GL begin
        isnNA = IsNull(NA);
        if (isnNA) then begin
           isnGL = IsNull(GL);
           if (isnGL == 0) then begin
              NA = dnsub; fpNA = fpNA + 1;
           end
        end
     end
     CreateHistogram(NA,0); CreatePyramid(NA,0);
     CloseRaster(NA);
  end
  if (pNB) then begin
     fpNB = 0;
     printf(" NB");
     for each GL begin
        isnNB = IsNull(NB);
        if (isnNB) then begin
           isnGL = IsNull(GL);
           if (isnGL == 0) then begin
              NB = dnsub; fpNB = fpNB + 1;
           end
        end
     end
     CreateHistogram(NB,0); CreatePyramid(NB);
     CloseRaster(NB);
  end
  if (pMA) then begin
     fpMA = 0;
     printf(" MA");
     for each GL begin
        isnMA = IsNull(MA);
        if (isnMA) then begin
           isnGL = IsNull(GL);
           if (isnGL == 0) then begin
              MA = dnsub; fpMA = fpMA + 1;
           end
        end
     end
     CreateHistogram(MA,0); CreatePyramid(MA,0);
     CloseRaster(MA);
  end
  if (pMB) then begin
     fpMB = 0;
     printf(" MB");
     for each GL begin
        isnMB = IsNull(MB);
        if (isnMB) then begin
           isnGL = IsNull(GL);
           if (isnGL == 0) then begin
              MB = dnsub; fpMB = fpMB + 1;
           end
        end
     end
     CreateHistogram(MB,0); CreatePyramid(MB,0);
     CloseRaster(MB);
  end
  if (pMC) then begin
     fpMC = 0;
     printf(" MC");
     for each GL begin
        isnMC = IsNull(MC);
        if (isnMC) then begin
           isnGL = IsNull(GL);
           if (isnGL == 0) then begin
              MC = dnsub; fpMC = fpMC + 1;
           end
        end
     end
     CreateHistogram(MC,0); CreatePyramid(MC,0);
  CloseRaster(MC);
  end
  if (pMD) then begin
     fpMD = 0;
     printf(" MD");
     for each GL begin
        isnMD = IsNull(MD);
        if (isnMD) then begin
           isnGL = IsNull(GL);
           if (isnGL == 0) then begin
              MD = dnsub; fpMD = fpMD + 1;
           end
        end
     end
     CreateHistogram(MD,0); CreatePyramid(MD,0);
  CloseRaster(MD);
  end
  if (pME) then begin
     fpME = 0;
     printf(" ME");
     for each GL begin
        isnME = IsNull(ME);
        if (isnME) then begin
           isnGL = IsNull(GL);
           if (isnGL == 0) then begin
              ME = dnsub; fpME = fpME + 1;
           end
        end
     end
     CreateHistogram(ME,0); CreatePyramid(ME,0);
  CloseRaster(ME);
  end
  if (pMF) then begin
     fpMF = 0;
     printf(" MF");
     for each GL begin
        isnMF = IsNull(MF);
        if (isnMF) then begin
           isnGL = IsNull(GL);
           if (isnGL == 0) then begin
              MF = dnsub; fpMF = fpMF + 1;
           end
        end
     end
     CreateHistogram(MF,0); CreatePyramid(MF,0);
  CloseRaster(MF);
  end
  if (pMG) then begin
     fpMG = 0;
     printf(" MG");
     for each GL begin
        isnMG = IsNull(MG);
        if (isnMG) then begin
           isnGL = IsNull(GL);
           if (isnGL == 0) then begin
              MG = dnsub; fpMG = fpMG + 1;
           end
        end
     end
     CreateHistogram(MG,0); CreatePyramid(MG,0);
  CloseRaster(MG);
  end
  CloseRaster(GL);
  printf("\n\n");
  printf("NUMBER OF ERRANT PIXELS FOUND & FIXED:\n");
  printf("   BAND: NUMBER\n");
  printf("     GL: 0\n");
  if (pYL) then printf("     YL: %d\n",fpYL);
  printf("     RL: %d\n",fpRL);
  if (pRE) then printf("     RE: %d\n",fpRE);
  if (pNA) then printf("     NA: %d\n",fpNA);
  if (pNB) then printf("     NB: %d\n",fpNB);
  if (pMA) then printf("     MA: %d\n",fpMA);
  if (pMB) then printf("     MB: %d\n",fpMB);
  if (pMC) then printf("     MC: %d\n",fpMC);
  if (pMD) then printf("     MD: %d\n",fpMD);
  if (pME) then printf("     ME: %d\n",fpME);
  if (pMF) then printf("     MF: %d\n",fpMF);
  if (pMG) then printf("     MG: %d\n",fpMG);
# ------------------------------------------------------------
# END OF SCRIPT
  printf("TO SAVE THE CONSOLE WINDOW TEXT AS A REPORT:\n");
  printf("   1. RIGHT-CLICK IN THE CONSOLE WINDOW.\n");
  printf("   2. SELECT THE Save As... OPTION.\n");
  printf("   3. NAVIGATE TO THE DESIRED LOCATION.\n");
  printf("   4. PROVIDE A REPORT NAME (or OVERWRITE).\n");
  printf("   5. CLICK OK.");