Ejemplo n.º 1
0
ossimRefPtr<ossimImageData> ossimMaskFilter::executeMaskFilterInvertSelection(
   inputT /* dummyInput */,
   maskT  /* dummyMask */,
   ossimRefPtr<ossimImageData> imageSourceData,
   ossimRefPtr<ossimImageData> maskSourceData)
{
   ossimDataObjectStatus maskDataStatus  = maskSourceData->getDataObjectStatus();
   ossimDataObjectStatus inputDataStatus = imageSourceData->getDataObjectStatus();

   if((maskDataStatus == OSSIM_NULL) ||
      (maskDataStatus == OSSIM_EMPTY))
   {
      return theTile;
   }
   if( (inputDataStatus == OSSIM_NULL)||
       (inputDataStatus == OSSIM_EMPTY))
   {
      return theTile;
   }
      
   if(maskDataStatus == OSSIM_FULL)
   {
      theTile->makeBlank();
      
      return theTile;
   }
   
   ossim_uint32 maskBands  = maskSourceData->getNumberOfBands();
   ossim_uint32 inputBands = imageSourceData->getNumberOfBands();
   if(maskBands&&inputBands)
   {
      ossim_uint32 maxOffset = theTile->getWidth()*theTile->getHeight();
      for(ossim_uint32 band = 0; band < inputBands; ++band)
      {
         maskT*    bufMask = (maskT*)maskSourceData->getBuf();
         inputT* bufIn     = (inputT*)imageSourceData->getBuf(band);
         inputT* bufOut    = (inputT*)theTile->getBuf(band);
         inputT  np        = (inputT)theTile->getNullPix(band);
         ossim_uint32 offset = 0;
         for(offset = 0; offset < maxOffset; ++offset)
         {
            if(!*bufMask)
            {
               *bufOut = *bufIn;
            }
            else
            {
               *bufOut = np;
            }
            ++bufOut;
            ++bufIn;
            ++bufMask;
         }
      }
      theTile->validate();
   }
   
   return theTile;
}
template <class T> void ossimTiledElevationDatabase::fillGrid(T /* dummyTemplate */,
                                                              ossimRefPtr<ossimImageData> data)
{
   if ( data.valid() )
   {
      // Copy to grid reversing the lines as the ossimDblGrid's origin is the SW corner.
      const ossim_float64 NP  = data->getNullPix(0);
      const T* buf = static_cast<T*>(data->getBuf(0));
      if ( buf )
      {
         const ossimIpt SIZE( data->getWidth(), data->getHeight() );
         ossim_int32 bufIdx = (SIZE.y-1) * data->getWidth();
         ossim_int32 grdY = 0;
         for (ossim_int32 y = SIZE.y-1; y >= 0; --y)
         {
            for (ossim_int32 x = 0; x < SIZE.x; ++ x)
            {
               ossim_float64 v = static_cast<ossim_float64>(buf[bufIdx+x]);
               m_grid->setNode(x, grdY, (v!=NP?v:ossim::nan()) );
            }
            bufIdx -= data->getWidth();
            ++grdY;
         }
      }
   }
}
void ossimQtScrollingImageWidget::fillImage(ossimRefPtr<ossimImageData>& data,
                                            QImage* tempImage)
{
   if(data.valid() && data->getBuf() && !tempImage->isNull())
   {
      ossim_uint8* buf[3];
      int numberOfBands = data->getNumberOfBands();
      int aWidth        = tempImage->size().width();
      int aHeight       = tempImage->size().height();
      int maxPixels     = aWidth*aHeight;
      int offset;
      
      if(numberOfBands >= 3)
      {
         buf[0] = static_cast<ossim_uint8*>(data->getBuf(0));
         buf[1] = static_cast<ossim_uint8*>(data->getBuf(1));
         buf[2] = static_cast<ossim_uint8*>(data->getBuf(2));
      }
      else 
      {
         buf[0] = static_cast<ossim_uint8*>(data->getBuf(0));
         buf[1] = static_cast<ossim_uint8*>(data->getBuf(0));
         buf[2] = static_cast<ossim_uint8*>(data->getBuf(0));
      }
      QRgb *bits = (QRgb*)tempImage->bits();
      if(tempImage->bits())
      {
         for(offset = 0; offset < maxPixels;++offset)
         {
            *bits = qRgb(*buf[0], *buf[1], *buf[2]);
            ++buf[0];++buf[1];++buf[2];
            ++bits;
         }
      }
      else
      {
         tempImage->fill(0);
      }
   }
   else
   {
      tempImage->fill(0);
   }
}
Ejemplo n.º 4
0
void ossimEdgeFilter::runLocalMax8Filter(T /* dummyVariable */,
                                         ossimRefPtr<ossimImageData> inputData)
{
   ossim_uint32 bandIdx = 0;
   ossim_uint32 numberOfBands = inputData->getNumberOfBands();
  
   ossim_uint32 x = 0;
   ossim_uint32 y = 0;
   ossim_uint32 width  = theTile->getWidth();
   ossim_uint32 height = theTile->getHeight();
   ossim_int32 rowIncrement  = inputData->getWidth();
   ossim_int32 rowIncrement2 = 2*inputData->getWidth(); 
         
   for(bandIdx = 0; bandIdx < numberOfBands; ++bandIdx)
   {
      //inputBuf has a 1 pixel edge compared to outputBuf
      T* inputBuf  = static_cast<T*>(inputData->getBuf(bandIdx));
      T* outputBuf = static_cast<T*>(theTile->getBuf(bandIdx));
      T np         = static_cast<T>(inputData->getNullPix(bandIdx)); //changed to input Null            

      if(inputBuf&&outputBuf)
      {
         //one pass: maybe faster if changed to two passes
         T* outB;
         T* inB;
         
      	outB = outputBuf;         
         inB  = inputBuf;         
         for(y = 0; y < height; ++y)
         {
            for(x = 0; x < width; ++x)
            {
               if (inB[1+rowIncrement] != np)
               {
                  *outB = max<T>(
                           max<T>(
                            max<T>(inB[0],inB[1]),
                            max<T>(inB[2],inB[rowIncrement])),
                           max<T>(
                            max<T>(inB[rowIncrement+2],inB[rowIncrement2]),
                            max<T>(inB[rowIncrement2+1],inB[rowIncrement2+2])
                            ));
               }
               else
               {
                  *outB = np;
               }
               ++outB;
               ++inB;
            }
            inB+=2; //go to next line, jump due to edge
         }       
      }      
   }
   theTile->validate();
}
Ejemplo n.º 5
0
ossimRefPtr<ossimImageData> ossimFixedTileCache::addTile(ossimRefPtr<ossimImageData> imageData,
                                                         bool duplicateData)
{
   OpenThreads::ScopedLock<OpenThreads::Mutex> lock(theMutex);
   ossimRefPtr<ossimImageData> result = NULL;
   if(!imageData.valid())
   {
      return result;
   }
   if(!imageData->getBuf())
   {
      return result;
   }
   
   ossim_int32 id = computeId(imageData->getOrigin());
   if(id < 0)
   {
      return result;
   }
   
   std::map<ossim_int32, ossimFixedTileCacheInfo>::iterator tileIter =
      theTileMap.find(id);

   if(tileIter==theTileMap.end())
   {
      if(duplicateData)
      {
         result = (ossimImageData*)imageData->dup();
      }
      else
      {
         result = imageData;
      }
      ossimFixedTileCacheInfo cacheInfo(result, id);
       
      theCacheSize += imageData->getDataSizeInBytes();
      theTileMap.insert(make_pair(id, cacheInfo));
      if(theUseLruFlag)
      {
         theLruQueue.push_back(id);
      }
   }
   
   return result;
}
Ejemplo n.º 6
0
void ossimFftFilter::runFft(ossimRefPtr<ossimImageData>& input,
                            ossimRefPtr<ossimImageData>& output)
{

   NEWMAT::Matrix* realIn = new NEWMAT::Matrix(input->getHeight(),
                                               input->getWidth());
   NEWMAT::Matrix* imgIn = new NEWMAT::Matrix(input->getHeight(),
                                              input->getWidth());
   NEWMAT::Matrix* realOut = new NEWMAT::Matrix(input->getHeight(),
                                                input->getWidth());
   NEWMAT::Matrix* imgOut = new NEWMAT::Matrix(input->getHeight(),
                                               input->getWidth());
   ossim_uint32 bandIdx = 0;
   ossim_uint32 w = input->getWidth();
   ossim_uint32 h = input->getHeight();
   ossim_uint32 x = 0;
   ossim_uint32 y = 0;
   if(theDirectionType == FORWARD)
   {
      ossim_uint32 bands = input->getNumberOfBands();
      for(bandIdx = 0; bandIdx < bands; ++bandIdx)
      {
         ossim_float64* bandReal = 0;
         ossim_float64* bandImg  = 0;
         fillMatrixForward((ossim_float64*)input->getBuf(bandIdx),
                           (ossim_float64)input->getNullPix(bandIdx),
                           *realIn,
                           *imgIn);
         NEWMAT::FFT2(*realIn, *imgIn, *realOut, *imgOut);
         bandReal = (ossim_float64*)output->getBuf(2*bandIdx);
         bandImg  = (ossim_float64*)output->getBuf(2*bandIdx + 1);
         if(bandReal&&bandImg)
         {
            for(y = 0; y < h; ++y)
            {
               for(x = 0; x < w; ++x)
               {
                  *bandReal = (ossim_float64)((*realOut)[y][x]);
                  *bandImg  = (ossim_float64)((*imgOut)[y][x]);
                  ++bandReal;
                  ++bandImg;
               }
            }
         }
      }
   }
   else
   {
      ossim_float64* bandReal = 0;
      ossim_uint32 bands = input->getNumberOfBands();
      for(bandIdx = 0; bandIdx < bands; bandIdx+=2)
      {
         bandReal = (ossim_float64*)output->getBuf(bandIdx/2);
         if(input->getBuf(bandIdx)&&
            input->getBuf(bandIdx+1))
         {
            fillMatrixInverse((double*)input->getBuf(bandIdx),
                              (double*)input->getBuf(bandIdx+1),
                              *realIn,
                              *imgIn);
            NEWMAT::FFT2I(*realIn, *imgIn, *realOut, *imgOut);
            for(y = 0; y < h; ++y)
            {
               for(x = 0; x < w; ++x)
               {
                  *bandReal = (ossim_float64)((*realOut)[y][x]);
//                  if(*bandReal > 1.0)
//                  {
//                     *bandReal = 1.0;
//                  }
//                  if(*bandReal < 0.0)
//                  {
//                     *bandReal = 0.0;
//                  }
                  ++bandReal;
               }
            }
         }
      }
   }
   
   delete realIn;
   delete imgIn;
   delete realOut;
   delete imgOut;
}
ossimRefPtr<ossimImageData> ossimHistogramEqualization::runEqualizationAlgorithm(T, ossimRefPtr<ossimImageData> tile)
{
   
   if(!theAccumulationHistogram ||
      !getHistogram())
   {
      return tile;
   }

   // for now we will always pull from res 0 information
   ossimRefPtr<ossimMultiBandHistogram> histo = getHistogram()->getMultiBandHistogram(0);

   if(histo.valid())
   {
      ossim_uint32 maxBands = ( (histo->getNumberOfBands() >
                                 tile->getNumberOfBands())?
                                tile->getNumberOfBands():
                                histo->getNumberOfBands());
      
      long offsetUpperBound = tile->getHeight()*tile->getWidth();

      for(ossim_uint32 band = 0; band < maxBands; ++band)
      {
         ossimRefPtr<ossimHistogram> bandHisto = histo->getHistogram(band);
         T* buf = static_cast<T*>(tile->getBuf(band));
         double *histoLut = band<theForwardLut.size()?theForwardLut[band]:NULL;
         ossim_uint32 actualBand = theBandList[band];
         if(bandHisto.valid())
         {
            if(buf&&histoLut&&(actualBand <  histo->getNumberOfBands()))
            {
               if(theInverseFlag)
               {
                  histoLut = theInverseLut[actualBand];
               }
               if(histoLut)
               {
                  if(tile->getDataObjectStatus() == OSSIM_FULL)
                  {
                     T minPix = (T)tile->getMinPix(actualBand);
                     T maxPix = (T)tile->getMaxPix(actualBand);
                     for(long offset = 0; offset < offsetUpperBound; ++offset)
                     {
                        ossim_int32 idx = bandHisto->GetIndex(buf[offset]);
                           
                        if(idx>=0)
                        {
                           T value = (T)(histoLut[idx]);

                           //---
                           // Assign clamping to min max.
                           // 
                           // ESH 03/2009 -- Clamping to within min-max fixed
                           //--- 
                           buf[offset] = value < minPix ? minPix :
                              (value > maxPix ? maxPix : value);
                        }
                     }
                  }
                  else
                  {
                     T minPix  = (T)tile->getMinPix(actualBand);
                     T maxPix  = (T)tile->getMaxPix(actualBand);
                     T nullPix = (T)tile->getNullPix(actualBand);
                     for(long offset = 0; offset < offsetUpperBound; ++offset)
                     {
                        ossim_int32 idx = bandHisto->GetIndex(buf[offset]);
                        
                        if((buf[offset]!=nullPix)&&(idx>=0))
                        {
                           T value = (T)(histoLut[idx]);

                           //---
                           // Assign clamping to min max.
                           // 
                           // ESH 03/2009 -- Clamping to within min-max fixed
                           //--- 
                           buf[offset] = value < minPix ? minPix :
                              (value > maxPix ? maxPix : value);
                        }
                        else
                        {
                           buf[offset] = nullPix;
                        }
                     }
                  }
               }
            }
         }
      }
      
      tile->validate();
   }
   
   return tile;
}
Ejemplo n.º 8
0
template <class T> void ossimTableRemapper::remapFromNativeTable(
   T /* dummy */,
   ossimRefPtr<ossimImageData>& inputTile)
{
   
   const ossim_uint32 BANDS = theTile->getNumberOfBands();
   const ossim_uint32 PPB   = theTile->getSizePerBand(); // pixels per band
   //---
   // NOTE:
   // If (theTableBandCount == one) that means we only have one band; or,
   // the user wanted to remap all bands using the same table...
   //---
   const ossim_uint32 BAND_OFFSET =
      (theTableBandCount != 1) ? theTableBinCount: 0;



   const T* rt = reinterpret_cast<T*>(&theTable.front()); // remap table (rt)
   ossimRefPtr<ossimImageData> id;
   if (theInputScalarType == theOutputScalarType)
   {
      id = theTile;
   }
   else
   {
      id = theTmpTile;
   }
   if(theTable.size() >= (BANDS*BAND_OFFSET))
   {
      for (ossim_uint32 band = 0; band < BANDS; ++band)
      {
         const T NULL_PIX = static_cast<T>(id->getNullPix(band));
         //const T MIN_PIX  = static_cast<T>(id->getMinPix(band));

         const T* s = static_cast<T*>(inputTile->getBuf(band)); // source (s)
         T*       d = static_cast<T*>(id->getBuf(band));   // destination (d)

         if(s&&d)
         {
            for (ossim_uint32 pixel = 0; pixel < PPB; ++pixel)
            {
               //---
               // Get the source pixel and use it as an index to the table.
               // Note Null is always the "0" index, min always the "1".
               //---
               T p = s[pixel];
               if (p == NULL_PIX)  // Null is not always zero (dted).
               {
                  d[pixel] = NULL_PIX;
                 // p = 0;
               }
               else
               {
      //         else
      //         {
      //            p = (p+1-MIN_PIX);  // If min == 1 we want that to map to index 1.
      //         }

                  ossim_uint32 table_index = static_cast<ossim_uint32>(p);
                  
                  //---
                  // If within range use to index the remap table; else, null.
                  // Note:
                  // There is no min, max range checking on value retrieved from table.
                  // Range checking should be performed when the table is built.
                  //---
                  if(table_index < theTableBinCount)
                  {
                     d[pixel] = rt[table_index];
                  }
      //            else if(table_index < 0)
      //            {
      //               if(theTableBinCount > 1)
      //               {
      //                  d[pixel] = rt[1];
      //               }
      //               else
      //               {
      //                  d[pixel] = table_index;
       //              }
       //           }
                  else
                  {
                     if(theTableBinCount>0)
                     {
                        d[pixel] = rt[theTableBinCount-1];
                     }
                     else
                     {
                        d[pixel] = p;
                    }
                  }
               }
            }

         }

         rt += BAND_OFFSET; // Go to next band in the table.
      }

   }

   if (theInputScalarType != theOutputScalarType)
   {
      // Normalize and copy the temp tile to a buffer.
      id->copyTileToNormalizedBuffer(theNormBuf);

      // Un-normalize and copy the buffer to the destination tile.
      theTile->copyNormalizedBufferToTile(theNormBuf);
   }
}
void ossimTileToIplFilter::CopyIplImageToTile(T dummyVariable, ossimRefPtr<ossimImageData> inputTile, IplImage *output)
{
    // Determine if tile is full or partially filled
    ossimDataObjectStatus status = inputTile->getDataObjectStatus();

    uchar *outputData = (uchar *)output->imageData;
    int outputStep = output->widthStep/sizeof(uchar);

    int pixVal;
    long outputOffset = 0;

    T maxPix = static_cast<T>(getMaxPixelValue(0));
    T minPix = static_cast<T>(getMinPixelValue(0));
    T np = static_cast<T>(inputTile->getNullPix(0));

    if (status == OSSIM_PARTIAL)
    {
        for (ossim_uint32 bandIdx = 0; bandIdx < inputTile->getNumberOfBands(); ++bandIdx)
        {
            T* outBuf = static_cast<T*>(inputTile->getBuf(bandIdx));

            if (outBuf)
            {
                outputOffset = 0;
                for (long y = 0; y < output->height; ++y)
                {
                    for (long x = 0; x < output->width; ++x)
                    {
                        if (!inputTile->isNull(outputOffset))
                        {
                            pixVal = (int)round(outputData[y * outputStep + x]);

                            if (pixVal > maxPix)
                                *outBuf = maxPix;
                            else if (pixVal < 0)
                                *outBuf = minPix;
                            else
                                *outBuf = static_cast<T>(pixVal);
                        }
                        else
                            inputTile->setNull(outputOffset);

                        ++outBuf;
                        ++outputOffset;
                    }
                }
            }
        }
    }
    else
    {
        for (ossim_uint32 bandIdx = 0; bandIdx < inputTile->getNumberOfBands(); ++bandIdx)
        {
            T* outBuf = (T*)(inputTile->getBuf(bandIdx));

            if (outBuf)
            {
                for (int y = 0; y < output->height; ++y)
                {
                    for (int x = 0; x < output->width; ++x)
                    {
                        pixVal = (int)round(outputData[y * outputStep + x]);

                        if (pixVal > maxPix)
                            *outBuf = (maxPix);
                        else if (pixVal < 0)
                            *outBuf = (minPix);
                        else
                            *outBuf = static_cast<T>(pixVal);

                        // Increment the output buffer to the next pixel value
                        ++outBuf;
                    }
                }
            }
            else
                *outBuf = np;
        }
    }
}
template <class T> void ossimImageToPlaneNormalFilter::computeNormalsTemplate(
   T /* inputScalarTypeDummy */,
   ossimRefPtr<ossimImageData>& inputTile,
   ossimRefPtr<ossimImageData>& outputTile)
{
   T inputNull = (T)inputTile->getNullPix(0);
   T* inbuf = (T*)inputTile->getBuf();

   double* normX = (double*)outputTile->getBuf(0);
   double* normY = (double*)outputTile->getBuf(1);
   double* normZ = (double*)outputTile->getBuf(2);
   ossim_int32 inbuf_width = inputTile->getWidth();
   ossim_int32 normbuf_width = outputTile->getWidth();
   ossim_int32 normbuf_height = outputTile->getHeight();
   ossimColumnVector3d normal;

   for (ossim_int32 y=0; y<normbuf_height; y++)
   {
      // Establish offsets into the image and output normals buffers given row:
      ossim_uint32 n = y*normbuf_width;
      ossim_uint32 i = (y+1)*inbuf_width + 1;
      
      // Loop to compute the gradient (normal) vector [dh/dx, dh/dy, 1]:
      for (ossim_int32 x=0; x<normbuf_width; x++)
      {
         // Default in case of null inputs is a flat earth:
         normal[0] = 0;
         normal[1] = 0;
         normal[2] = 1.0;

         // Compute the x-direction differential:
         if (inbuf[i+1] != inputNull)
         {
            if (inbuf[i-1] != inputNull)
               normal[0] = theXScale*theSmoothnessFactor*(inbuf[i+1] - inbuf[i-1]) / 2.0;
            else if (inbuf[i] != inputNull)
               normal[0] = theXScale*theSmoothnessFactor*(inbuf[i+1] - inbuf[i]);
         }
         else if ((inbuf[i] != inputNull) && (inbuf[i-1] != inputNull))
         {
            normal[0] = theXScale*theSmoothnessFactor*(inbuf[i] - inbuf[i-1]);
         }

         // Compute the y-direction differential:
         if (inbuf[i+inbuf_width] != inputNull)
         {
            if (inbuf[i-inbuf_width] != inputNull)
               normal[1] = theYScale*theSmoothnessFactor*(inbuf[i+inbuf_width] - inbuf[i-inbuf_width]) / 2.0;
            else if (inbuf[i] != inputNull)
               normal[1] = theYScale*theSmoothnessFactor*(inbuf[i+inbuf_width] - inbuf[i]);
         }
         else if ((inbuf[i] != inputNull) && (inbuf[i-inbuf_width] != inputNull))
         {
            normal[1] = theYScale*theSmoothnessFactor*(inbuf[i] - inbuf[i-inbuf_width]);
         }

         // Stuff the normalized gradient vector into the output buffers:
         normal = normal.unit();
         normX[n] = normal[0];
         normY[n] = normal[1];
         normZ[n] = normal[2];
         
         ++n;
         ++i;
      }
   }
}
template<class T> void ossimCFARFilter::convolveFull(
   T,
   ossimRefPtr<ossimImageData> inputData,
   ossimRefPtr<ossimImageData> outputData)
{
   // let's set up some temporary variables so we don't
   // have to call the functions in loops.  Iknow that compilers
   // typically optimize this out but if we are in debug mode 
   // with no optimization it will still run fast
   //
   double sum = 0.0,sqrsum = 0.0,variance = 0.0;
   ossim_int32 inputW = static_cast<ossim_int32>(inputData->getWidth());
   ossim_uint32 outputW       = outputData->getWidth();
   ossim_uint32 outputH       = outputData->getHeight();
   ossim_uint32 numberOfBands = inputData->getNumberOfBands();
   ossimIpt outputOrigin = outputData->getOrigin();
   ossimIpt inputOrigin  = inputData->getOrigin();
   
   ossim_int32 startInputOffset = std::abs(outputOrigin.y - inputOrigin.y)*
      inputW + std::abs(outputOrigin.x - inputOrigin.x);
   
   ossim_int32 ulKernelStart    = -(2*inputW) - 2;
   ossim_int32 ul1KernelStart    = -inputW - 1;
   ossim_int32 leftKernelStart  = -2;
   ossim_int32 ll1KernelStart    = inputW  - 1;
   ossim_int32 llKernelStart    = (2*inputW)  - 2;
   
   //populate kernel offset indices
   
   ossim_int32 KernelStart[BOXSIZE];
   T* KernelStartBuf[BOXSIZE];
   
   for(ossim_uint16 i=0;i<BOXSIZE;i++)
   {
   	int offset = i-(BOXSIZE/2);
   	KernelStart[i] = offset*inputW + offset;
   	KernelStartBuf[i] = NULL;
   }
   
   T* ulKernelStartBuf   = NULL;
   T* ul1KernelStartBuf   = NULL;
   T* leftKernelStartBuf = NULL;
   T* ll1KernelStartBuf   = NULL;   
   T* llKernelStartBuf   = NULL;
   
   for(ossim_uint32 band = 0; band < numberOfBands; ++band)
   {
      T* inputBuf  = static_cast<T*>(inputData->getBuf(band))+startInputOffset;
      T* outputBuf = static_cast<T*>(outputData->getBuf(band));
      T maxPix     = static_cast<T>(getMaxPixelValue(band));
      T minPix     = static_cast<T>(getMinPixelValue(band));
      
      if(inputBuf&&outputBuf)
      {
         for(ossim_uint32 row = 0; row < outputW; ++row)
         {
            ossim_int32 rowOffset    = inputW*row;
            ulKernelStartBuf   = inputBuf + (rowOffset + ulKernelStart);
            ul1KernelStartBuf   = inputBuf + (rowOffset + ul1KernelStart);
            leftKernelStartBuf = inputBuf + (rowOffset + leftKernelStart);
            ll1KernelStartBuf   = inputBuf + (rowOffset + ll1KernelStart);
            llKernelStartBuf   = inputBuf + (rowOffset + llKernelStart);
            
            for(ossim_uint16 i=0;i<BOXSIZE;i++)
            {
            	KernelStartBuf[i] = inputBuf + (rowOffset + KernelStart[i]);
            }
            
            for(ossim_uint32 col = 0; col < outputH; ++col)
            {
            	//calculate mean
            	sum = 0.0;
            	sqrsum = 0.0;
            	
            	for(ossim_uint32 r=0; r<5; ++r)
            		sum += theKernel[0][r]*(double)ulKernelStartBuf[r];
            	for(ossim_uint32 r=0; r<5; ++r)
            		sum += theKernel[1][r]*(double)ul1KernelStartBuf[r];
            	for(ossim_uint32 r=0; r<5; ++r)
            		sum += theKernel[2][r]*(double)leftKernelStartBuf[r];
            	for(ossim_uint32 r=0; r<5; ++r)
            		sum += theKernel[3][r]*(double)ll1KernelStartBuf[r];
            	for(ossim_uint32 r=0; r<5; ++r)
            		sum += theKernel[4][r]*(double)llKernelStartBuf[r];
            	/*
            	for(ossim_uint16 i=0;i<BOXSIZE;i++)
	   	      {
	   	         for(ossim_uint32 r=0; r<5; ++r)
	   	         {
							sum += theKernel[i][r]*(double)KernelStartBuf[i][r];
							sqrsum += theKernel[i][r]*(double)KernelStartBuf[i][r]
         	   		*(double)KernelStartBuf[i][r];
         	   	}
   	      	}
   	      	*/
            	
            	//calculate mean of squares
            	
            	for(ossim_uint32 r=0; r<5; ++r)
            		sqrsum += theKernel[0][r]*(double)ulKernelStartBuf[r]
            		*(double)ulKernelStartBuf[r];
            	for(ossim_uint32 r=0; r<5; ++r)
            		sqrsum += theKernel[1][r]*(double)ul1KernelStartBuf[r]
            		*(double)ul1KernelStartBuf[r];
            	for(ossim_uint32 r=0; r<5; ++r)
            		sqrsum += theKernel[2][r]*(double)leftKernelStartBuf[r]
            		*(double)leftKernelStartBuf[r];
            	for(ossim_uint32 r=0; r<5; ++r)
            		sqrsum += theKernel[3][r]*(double)ll1KernelStartBuf[r]
            		*(double)ll1KernelStartBuf[r];
            	for(ossim_uint32 r=0; r<5; ++r)
            		sqrsum += theKernel[4][r]*(double)llKernelStartBuf[r]
            		*(double)llKernelStartBuf[r];
					
					//calculate variance
					variance = sqrsum - (sum*sum);
					
					//calculate k-value
					sum = ((double)leftKernelStartBuf[2] - sum)/sqrt(variance);
					
					//Threshold k-value
					if(sum < theThreshold)
						sum = minPix;
					else
						sum = maxPix;
					
					/*            
               sum = theKernel[0][0]*(double)ulKernelStartBuf[0] +
                     theKernel[0][1]*(double)ulKernelStartBuf[1] +
                     theKernel[0][2]*(double)ulKernelStartBuf[2] +
                     theKernel[1][0]*(double)leftKernelStartBuf[0] +
                     theKernel[1][1]*(double)leftKernelStartBuf[1] +
                     theKernel[1][2]*(double)leftKernelStartBuf[2] +
                     theKernel[2][0]*(double)llKernelStartBuf[0] +
                     theKernel[2][1]*(double)llKernelStartBuf[1] +
                     theKernel[2][2]*(double)llKernelStartBuf[2];
               */
               if(sum > maxPix)
               {
                  *outputBuf = maxPix;
               }
               else if(sum < minPix)
               {
                  *outputBuf = minPix;
               }
               else
               {
                  *outputBuf = static_cast<T>(sum);
               }
               //
               // Need to implement the convolution here.
               //

               
               ++ulKernelStartBuf;
               ++ul1KernelStartBuf;
               ++leftKernelStartBuf;
               ++ll1KernelStartBuf;
               ++llKernelStartBuf;
               ++outputBuf;
            }
         }
      }
   }
}
Ejemplo n.º 12
0
//*****************************************************************************
//  METHOD: ossimHsvGridRemapEngine::remapTile
//  
//*****************************************************************************
void ossimHsvGridRemapEngine::remapTile(const ossimDpt&       origin,
                                        ossimGridRemapSource* remapper,
                                        ossimRefPtr<ossimImageData>& tile)
{
   static const char MODULE[] = "ossimHsvGridRemapEngine::remapTile";
   if (traceExec())  CLOG << "entering..." << endl;

   //***
   // Fetch tile size and NULL pixel value:
   //***
   int    width         = tile->getWidth();
   int    height        = tile->getHeight();
   int    offset        = 0;
   
   void* red_buf = tile->getBuf(0);
   void* grn_buf = tile->getBuf(1);
   void* blu_buf = tile->getBuf(2);

   ossimDblGrid& gridH = *(remapper->getGrid(0));
   ossimDblGrid& gridS = *(remapper->getGrid(1));
   ossimDblGrid& gridV = *(remapper->getGrid(2));
      
   //---
   // Remap according to pixel type:
   //---
   switch(tile->getScalarType())
   {
      case OSSIM_UINT8:
      {
         for (double line=origin.line; line<origin.line+height; line+=1.0)
         {
            for (double samp=origin.samp; samp<origin.samp+width; samp+=1.0)
            {
               //---
               // Fetch pixel from the input tile band buffers and convert
               // to HSV:
               //---
               ossimRgbVector rgb_pixel (((ossim_uint8*)red_buf)[offset],
                                         ((ossim_uint8*)grn_buf)[offset],
                                         ((ossim_uint8*)blu_buf)[offset]);
               ossimHsvVector hsv_pixel (rgb_pixel);
               
               //---
               // Remap pixel HSV  with spatially variant bias value:
               //---
               hsv_pixel.setH(hsv_pixel.getH() + gridH(samp,line));
               hsv_pixel.setS(hsv_pixel.getS() + gridS(samp,line));
               hsv_pixel.setV(hsv_pixel.getV() + gridV(samp,line));
               
               //---
               // Convert back to RGB and write to the tile:
               //---
               rgb_pixel = hsv_pixel;  // auto-clamped
               ((ossim_uint8*)red_buf)[offset] = rgb_pixel.getR();
               ((ossim_uint8*)grn_buf)[offset] = rgb_pixel.getG();
               ((ossim_uint8*)blu_buf)[offset] = rgb_pixel.getB();
               
               offset++;
            }
         }
         break;
      }
      
      case OSSIM_USHORT11:
         break;
         
      case OSSIM_UINT16:
         break;
         
      case OSSIM_SINT16:
         break;	

      case OSSIM_FLOAT64:
         break;	

      case OSSIM_NORMALIZED_DOUBLE:
         break;	

      case OSSIM_FLOAT32:
         break;	

      case OSSIM_NORMALIZED_FLOAT:
         break;	

      case OSSIM_SCALAR_UNKNOWN:
      default:
         break;

   }   // end switch statement

   if (traceExec())  CLOG << "returning..." << endl;
   return;
};
void ossimTileToIplFilter::CopyTileToIplImage(T dummyVariable, ossimRefPtr<ossimImageData> inputTile, IplImage *output, ossimIrect neighborhoodRect)
{
    ossimDataObjectStatus status = inputTile->getDataObjectStatus();

    uchar *outputData = (uchar *)output->imageData;
    int outputStep = output->widthStep/sizeof(uchar);
    int outputChannels = output->nChannels;

    ossimScalarType inputType = inputTile->getScalarType();
    double scFactor;

    if (inputType == OSSIM_UINT16)
        scFactor = 0.0039; // 255 / 65535
    else if (inputType == OSSIM_USHORT11)
        scFactor = 0.1246; //255 / 2047
    else if (inputType == OSSIM_UINT8)
        scFactor = 1;
    else
        scFactor = 1;

    int pixVal;

    if (status == OSSIM_PARTIAL)
    {
        for( int band = 0; band < outputChannels; band++) {
            T* inBuf = static_cast<T*>(inputTile->getBuf(band));
            for (long y = 0; y < output->height; ++y)
            {
                for (long x = 0; x < output->width; ++x)
                {

                    pixVal = (int)(*inBuf);

                    if ((int)round(pixVal * scFactor) > 255)
                        outputData[y * outputStep + x*outputChannels + band] = 255;
                    else if ((int)round(pixVal * scFactor) < 0)
                        outputData[y * outputStep + x*outputChannels + band] = 0;
                    else
                        outputData[y * outputStep + x*outputChannels + band] = (uchar)round(pixVal * scFactor);

                    ++inBuf;
                }
            }
        }
    }
    else
    {
        for(int band = 0; band < outputChannels; band++) {
            T* inBuf = static_cast<T*>(inputTile->getBuf(band));
            for (int y = 0; y < output->height; ++y)
            {
                for (int x = 0; x < output->width; ++x)
                {
                    pixVal = (int)(*inBuf);

                    if ((int)round(pixVal * scFactor) > 255)
                        outputData[y * outputStep + x*outputChannels + band] = 255;
                    else if ((int)round(pixVal * scFactor) < 0)
                        outputData[y * outputStep + x*outputChannels + band] = 0;
                    else
                        outputData[y * outputStep + x*outputChannels + band] = (uchar)round(pixVal * scFactor);

                    ++inBuf;
                }
            }
        }
    }
}
Ejemplo n.º 14
0
void ossimEdgeFilter::runLaplacianFilter(T /* dummyVariable */,
                                         ossimRefPtr<ossimImageData> inputData)
{
   ossim_uint32 bandIdx = 0;
   ossim_uint32 numberOfBands = inputData->getNumberOfBands();
   // double horizontalValue = 0.0;
   // double verticalValue = 0.0;
   double value = 0.0;
   // ossim_uint32 valueIdx = 0;
   ossim_uint32 x = 0;
   ossim_uint32 y = 0;
   ossim_uint32 width  = theTile->getWidth();
   ossim_uint32 height = theTile->getHeight();
   ossim_int32 rowIncrement  = inputData->getWidth();
   ossim_int32 rowIncrement2 = 2*inputData->getWidth();
   
   for(bandIdx = 0; bandIdx < numberOfBands; ++bandIdx)
   {
      T* inputBuf  = static_cast<T*>(inputData->getBuf(bandIdx));
      T* outputBuf = static_cast<T*>(theTile->getBuf(bandIdx));
      T np         = static_cast<T>(theTile->getNullPix(bandIdx));
      T minP       = static_cast<T>(theTile->getMinPix(bandIdx));
      T maxP       = static_cast<T>(theTile->getMaxPix(bandIdx));

      if(inputBuf&&outputBuf)
      {
         for(y = 0; y < height; ++y)
         {
            for(x = 0; x < width; ++x)
            {
               if( (*(inputBuf + rowIncrement + 1) != np))
               {
                  
                  value = fabs(((double)inputBuf[rowIncrement + 1]*4.0) -
                               ((double)inputBuf[1] + (double)inputBuf[rowIncrement] + (double)inputBuf[rowIncrement + 2] + (double)inputBuf[rowIncrement2+1]));

                  if((value == np) ||
                     (value < minP))
                  {
                     *outputBuf = (static_cast<T>(minP));
                  }
                  else if(value > maxP)
                  {
                     *outputBuf = (static_cast<T>(maxP));
                  }
                  else
                  {
                     *outputBuf = (static_cast<T>(value));
                  }
                  
               }
               else
               {
                  *outputBuf = np;
               }
               ++outputBuf;
               ++inputBuf;
            }
            inputBuf+=2;
         }
      }
   }
   theTile->validate();
}
Ejemplo n.º 15
0
void ossimEdgeFilter::runRobertsFilter(T /* dummyVariable */,
                                       ossimRefPtr<ossimImageData> inputData)
{
   ossim_uint32 bandIdx = 0;
   ossim_uint32 numberOfBands = inputData->getNumberOfBands();
   double v1 = 0.0;
   double v2 = 0.0;
   double value = 0.0;
   // ossim_uint32 valueIdx = 0;
   ossim_uint32 x = 0;
   ossim_uint32 y = 0;
   ossim_uint32 width  = theTile->getWidth();
   ossim_uint32 height = theTile->getHeight();
   ossim_int32 rowIncrement  = inputData->getWidth();
   
   for(bandIdx = 0; bandIdx < numberOfBands; ++bandIdx)
   {
      T* inputBuf  = static_cast<T*>(inputData->getBuf(bandIdx));
      T* outputBuf = static_cast<T*>(theTile->getBuf(bandIdx));
      T np         = static_cast<T>(theTile->getNullPix(bandIdx));
      T minP       = static_cast<T>(theTile->getMinPix(bandIdx));
      T maxP       = static_cast<T>(theTile->getMaxPix(bandIdx));

      if(inputBuf&&outputBuf)
      {
         for(y = 0; y < height; ++y)
         {
            for(x = 0; x < width; ++x)
            {
               if( (*inputBuf) != np)
               {
                  v1 = (double)inputBuf[0] - (double)(inputBuf[rowIncrement+1]);

                  v2   = (double)inputBuf[1] - (double)inputBuf[rowIncrement];
                  
                  value = sqrt(v1*v1 +  v2*v2);

                  if((value == np) ||
                     (value < minP))
                  {
                     *outputBuf = (static_cast<T>(minP));
                  }
                  else if(value > maxP)
                  {
                     *outputBuf = (static_cast<T>(maxP));
                  }
                  else
                  {
                     *outputBuf = (static_cast<T>(value));
                  }
                  
               }
               else
               {
                  *outputBuf = np;
               }
               ++outputBuf;
               ++inputBuf;
            }
            ++inputBuf;
         }
      }
   }
   theTile->validate();
}
Ejemplo n.º 16
0
//**************************************************************************************************
template <class T> void ossimScaleFilter::runVerticalFilterTemplate(
   T /* dummy */,
   const ossimRefPtr<ossimImageData>& input,
   ossimRefPtr<ossimImageData>& output)
{
   ossimIrect viewRect  = output->getImageRectangle();
   ossimIrect imageRect = input->getImageRectangle();
   ossim_int32 vw = viewRect.width();
   ossim_int32 vh = viewRect.height();
   ossim_int32 iw = imageRect.width();
   ossimIpt origin(viewRect.ul());
   ossimIpt imageOrigin(imageRect.ul());
   ossimIpt inputUl = m_InputRect.ul();
   ossimIpt inputLr = m_InputRect.lr();
   double scale = 0.0;
   double support = 0.0;
   ossim_int32 x = 0;
   ossim_int32 y = 0;
   ossim_int32 start = 0;
   ossim_int32 stop  = 0;
   ossim_int32 kernelIdx = 0;
   const ossimFilter* filter = getVerticalFilter();
   ossim_float64 center = 0.0;
   ossim_int32 bandIdx = 0;
   ossim_int32 numberOfBands = m_Tile->getNumberOfBands();
   
   scale = m_BlurFactor*ossim::max(1.0/m_ScaleFactor.y, 1.0);
   
   support=scale*filter->getSupport();
   if (support <= 0.5)
   {
      support = .5 + FLT_EPSILON;
      scale = 1.0;
   }
   scale=1.0/scale;

   for(bandIdx = 0; bandIdx < numberOfBands; ++bandIdx)
   {
      T* imageBuf = (T*)input->getBuf(bandIdx);
      T* viewBuf  = (T*)output->getBuf(bandIdx);
      T np        = (T)input->getNullPix(bandIdx);
      T outNp     = (T)output->getNullPix(bandIdx);
      T outMinPix = (T)output->getMinPix(bandIdx);
      T outMaxPix = (T)output->getMaxPix(bandIdx);
     
      for(y = 0; y < vh; ++y)
      {
         center=(double) ((y + origin.y+0.5)/m_ScaleFactor.y);
         start=ossim::max((ossim_int32)ossim::round<int>(center-support), (ossim_int32)inputUl.y);
         stop=ossim::min((ossim_int32)ossim::round<int>(center+support), (ossim_int32)inputLr.y);
         ossim_int32 delta = stop-start;
         if (delta <= 0)
         {
            break;
         }
         vector<double> kernel(delta);
         double density = 0.0;
         for(kernelIdx = 0; kernelIdx < delta; ++kernelIdx)
         {
            kernel[kernelIdx] = filter->filter(scale*(start + kernelIdx - center + .5),
                                               filter->getSupport());
            density += kernel[kernelIdx];
         }
         if ((density != 0.0) && (density != 1.0))
         {
            /*
              Normalize.
            */
            density=1.0/density;
            for (kernelIdx=0; kernelIdx < delta; kernelIdx++)
               kernel[kernelIdx]*=density;
         }

         ossim_int32 offset       = ((start  - imageOrigin.y)*iw);
         ossim_int32 offsetCenter = ((((ossim_int32)center) - imageOrigin.y)*iw);
        
         for(x = 0; x < vw; ++x)
         {
            T* yptr         = imageBuf + offset       + x;
            T* yCenterptr   = imageBuf + offsetCenter + x;
            double result = 0.0;
            density = 0.0;

            if((*yCenterptr) == np)
            {
               *viewBuf = outNp;
            }
            else
            {
               for(kernelIdx = 0; kernelIdx < delta; ++kernelIdx)
               {
                  if((*yptr != np)&&
                     (kernel[kernelIdx] != 0.0))
                  {
                     result  += ((*yptr)*kernel[kernelIdx]);
                     density += kernel[kernelIdx];
                  }
                  yptr += iw;
               }
               if(density != 0.0)
               {
                  result /= density;
                 
                  if(result < outMinPix) result = outMinPix;
                  if(result > outMaxPix) result = outMaxPix;
                 
                  *viewBuf = (T)result;
               }
               else
               {
                  *viewBuf = outNp;
               }
            }
            ++viewBuf;
         }
      }
   }
}
Ejemplo n.º 17
0
ossimRefPtr<ossimImageData> ossimMaskFilter::executeMaskFilterWeighted(
   inputT /* dummyInput */,
   maskT  /* dummyMask */,
   ossimRefPtr<ossimImageData> imageSourceData,
   ossimRefPtr<ossimImageData> maskSourceData)
{
   ossimDataObjectStatus maskDataStatus  = maskSourceData->getDataObjectStatus();
   ossimDataObjectStatus inputDataStatus = imageSourceData->getDataObjectStatus();

   if( (maskDataStatus == OSSIM_NULL)||
       (maskDataStatus == OSSIM_EMPTY))
   {
      theTile->makeBlank();
      return theTile;
      
   }
   if( (inputDataStatus == OSSIM_NULL)||
       (inputDataStatus == OSSIM_EMPTY))
   {
      return theTile;
   }
   
   ossim_uint32 maskBands  = maskSourceData->getNumberOfBands();
   ossim_uint32 inputBands = imageSourceData->getNumberOfBands();
   if(maskBands&&inputBands)
   {
      ossim_uint32 maxOffset = theTile->getWidth()*theTile->getHeight();
      for(ossim_uint32 band = 0; band < inputBands; ++band)
      {
         maskT*    bufMask = (maskT*)maskSourceData->getBuf();
         inputT* bufIn     = (inputT*)imageSourceData->getBuf(band);
         inputT* bufOut    = (inputT*)theTile->getBuf(band);
         inputT  np        = (inputT)theTile->getNullPix(band);
         inputT  minp      = (inputT)theTile->getMinPix(band);
         ossim_uint32 offset = 0;

         if(inputDataStatus == OSSIM_PARTIAL)
         {
            for(offset = 0; offset < maxOffset; ++offset)
            {
               if(*bufIn != np)
               {
                  *bufOut = (inputT)((*bufIn)*((double)(*bufMask)/255.0));
                  if((*bufOut != np)&&
                     (*bufOut < minp))
                  {
                     *bufOut = minp;
                  }
               }
               else
               {
                  *bufOut = np;
               }
               ++bufOut;
               ++bufIn;
               ++bufMask;
            }
         }
         else
         {
            for(offset = 0; offset < maxOffset; ++offset)
            {
               *bufOut = (inputT)((*bufIn)*((double)(*bufMask)/255.0));
               if((*bufOut != np)&&
                  (*bufOut < minp))
               {
                  *bufOut = minp;
               }
               ++bufOut;
               ++bufIn;
               ++bufMask;
            }
         }
      }
      theTile->validate();
   }
   
   return theTile;
}