USGS

Isis 3.0 Application Source Code Reference

Home

vikfixtrx.cpp

Go to the documentation of this file.
00001 #include "Isis.h"
00002 #include "ProcessByLine.h"
00003 #include "SpecialPixel.h"
00004 #include <string>
00005 
00006 using namespace std;
00007 using namespace Isis;
00008 
00009 void fixtrx(Buffer &in, Buffer &out);
00010 static float threshhold;
00011 
00012 void IsisMain() {
00013   // We will be processing by line
00014   ProcessByLine p;
00015 
00016   // Get the user entered threshhold value
00017   UserInterface &ui = Application::GetUserInterface();
00018   threshhold = ui.GetDouble("THRESHLD");
00019 
00020   // Setup the input and output cubes
00021   p.SetInputCube("FROM");
00022   p.SetOutputCube("TO");
00023 
00024   // Start the processing
00025   p.StartProcess(fixtrx);
00026   p.EndProcess();
00027 
00028 }
00029 
00030 void fixtrx(Buffer &in, Buffer &out) {
00031 
00032   static int nsamps = in.SampleDimension();
00033 
00034   // Initialize bad tracks to false
00035   int trk, badtrx[7];
00036   for(trk = 0; trk < 7; trk++) {
00037     badtrx[trk] = false;
00038   }
00039 
00040   // Copy input line to output line
00041   for(int samp = 0; samp < nsamps; samp++) {
00042     out[samp] = in[samp];
00043   }
00044 
00045   // Check for bad tracks in this line
00046   int isamp, nbad, ntrx;
00047   for(trk = 0; trk < 7; trk++) {
00048     for(isamp = trk, nbad = 0, ntrx = 0; isamp < nsamps;
00049         isamp += 7, ntrx++) {
00050       if(in[isamp] <= 0) nbad++;
00051     }
00052     float pcbad = (float) nbad / (float) ntrx * 100.0;
00053     if(pcbad >= threshhold) {
00054       badtrx[trk] = true;
00055     }
00056   }
00057 
00058   // Go fix the bad tracks
00059   int trxflag = 0;
00060   for(trk = 0; trk < 7; trxflag += badtrx[trk++]);
00061   for(trk = 0; trk < 7; trk++) {
00062     if(badtrx[trk] == true) {
00063       for(isamp = trk; isamp < nsamps; isamp += 7) {
00064         if(in[isamp] <= 0) {
00065 
00066           // Get the left sample to average
00067           int lsamp = isamp;
00068           while(in[lsamp] <= 0 || in[lsamp] >= 255) {
00069             lsamp--;
00070             if(lsamp < isamp - 3 || lsamp < 0) {
00071               lsamp = -1;
00072               break;
00073             }
00074           }
00075 
00076           // Get the right sample to average
00077           int rsamp = isamp;
00078           while(in[rsamp] <= 0 || in[rsamp] >= 255) {
00079             rsamp++;
00080             if(rsamp > isamp + 3 || rsamp > nsamps - 1) {
00081               rsamp = -1;
00082               break;
00083             }
00084           }
00085 
00086           // Calculate the output pixel value
00087           double lweight, rweight, value, weight;
00088           if(lsamp >= 0 && rsamp >= 0) {
00089             lweight = rsamp - isamp;
00090             rweight = isamp - lsamp;
00091             weight = rsamp - lsamp;
00092             value = (in[lsamp] * lweight + in[rsamp] * rweight)
00093                     / weight + 0.5;
00094             out[isamp] = (unsigned char) value;
00095           }
00096         }
00097       }
00098     }
00099   }
00100 }
00101