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;
         }
      }
   }
}
Exemplo n.º 2
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();
}
Exemplo n.º 3
0
ossimRefPtr<ossimImageData> ossimMaskFilter::executeMaskFilter(ossimRefPtr<ossimImageData> imageSourceData,
                                                               ossimRefPtr<ossimImageData> maskSourceData)
{
   if(!theTile)
   {
      theTile = (ossimImageData*)imageSourceData->dup();
      if(!theTile->getBuf())
      {
         theTile->initialize();
      }
   }
   else
   {
      ossim_uint32 tw = theTile->getWidth();
      ossim_uint32 th = theTile->getHeight();
      ossim_uint32 dw = imageSourceData->getWidth();
      ossim_uint32 dh = imageSourceData->getHeight();
      
      theTile->setWidthHeight(imageSourceData->getWidth(),
			      imageSourceData->getHeight());
      theTile->setOrigin(imageSourceData->getOrigin());
      if((tw*th) != (dw*dh))
      {
         theTile->initialize();
      }
     theTile->setDataObjectStatus(imageSourceData->getDataObjectStatus());
   }
   theTile->loadTile(imageSourceData.get());
   theTile->setDataObjectStatus(imageSourceData->getDataObjectStatus());
  switch(theMaskType)
  {
  case OSSIM_MASK_TYPE_SELECT:
  {
     return executeMaskFilterSelect(theTile,
                                    maskSourceData);
  }
  case OSSIM_MASK_TYPE_INVERT:
  {
     return executeMaskFilterInvertSelect(theTile,
                                          maskSourceData);
  }
  case OSSIM_MASK_TYPE_WEIGHTED:
  {
     return executeMaskFilterWeighted(theTile,
                                      maskSourceData);
  }
  }
  
  return imageSourceData;
}
Exemplo n.º 4
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;
}
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;
            }
         }
      }
   }
}
Exemplo n.º 8
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;
};
Exemplo n.º 9
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();
}
Exemplo n.º 10
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();
}
Exemplo n.º 11
0
bool ossimCodecFactory::encodeJpeg( ossim_uint32 quality,
                                    const ossimRefPtr<ossimImageData>& in,
                                    std::vector<ossim_uint8>& out ) const
{
   bool result = false;

   if ( in.valid() && (in->getDataObjectStatus() != OSSIM_NULL) )
   {
      if ( in->getScalarType() == OSSIM_UINT8 )
      {
         // Open a memory stream up to put the jpeg image in memory:
         std::stringstream jpegStreamBuf;
         
         //---
         // Initialize JPEG compression library:
         // NOTE: JDIMENSION is an "unsigned int"
         //---
         struct jpeg_compress_struct cinfo;
         struct jpeg_error_mgr jerr;
         cinfo.err = jpeg_std_error( &jerr );
         jpeg_create_compress(&cinfo);
      
         // Define a custom stream destination manager for jpeglib to write compressed block:
         jpeg_cpp_stream_dest(&cinfo, jpegStreamBuf);
      
         /* Setting the parameters of the output file here */
         cinfo.image_width = in->getWidth();
         cinfo.image_height = in->getHeight();
   
         // Bands must be one or three for this writer.
         const ossim_uint32 INPUT_BANDS = in->getNumberOfBands();
         if ( (INPUT_BANDS == 1) || (INPUT_BANDS == 3) )
         {
            cinfo.input_components = INPUT_BANDS;
         }
         else
         {
            if ( INPUT_BANDS < 3 )
            {
               cinfo.input_components = 1; // Use first band.
            }
            else
            {
               cinfo.input_components = 3; // Use the first 3 bands.
            }
         }
      
         // colorspace of input image 
         if ( cinfo.input_components == 3)
         {
            cinfo.in_color_space = JCS_RGB;
         }
         else
         {
            cinfo.in_color_space = JCS_GRAYSCALE;
         }
      
         // Default compression parameters, we shouldn't be worried about these.
         jpeg_set_defaults( &cinfo );
      
         jpeg_set_quality(&cinfo, quality, TRUE); //limit to baseline-JPEG values
      
         // Now do the compression...
         jpeg_start_compress( &cinfo, TRUE );
      
         // Line buffer:
         ossim_uint32 buf_size = cinfo.input_components*cinfo.image_width;
         std::vector<ossim_uint8> buf(buf_size);
      
         // Compress the tile on line at a time:
      
         JSAMPROW row_pointer[1]; // Pointer to a single row.
         row_pointer[0] = (JSAMPLE*)&buf.front();

         // Get pointers to the input data:
         std::vector<const ossim_uint8*> inBuf(cinfo.input_components);
         for ( ossim_int32 band = 0; band < cinfo.input_components; ++band )
         {
            inBuf[band] = in->getUcharBuf(band);
         }

         ossim_uint32 inIdx = 0;
         for (ossim_uint32 line=0; line< cinfo.image_height; ++line)
         {
            // Convert from band sequential to band interleaved by pixel.
            ossim_uint32 outIdx = 0;
            for ( ossim_uint32 p = 0; p < cinfo.image_width; ++p )
            {
               for ( ossim_int32 band = 0; band < cinfo.input_components; ++band )
               {
                  buf[outIdx++] = inBuf[band][inIdx];
               }
               ++inIdx;
            }

            // Write it...
            jpeg_write_scanlines( &cinfo, row_pointer, 1 );
         }
      
         // Similar to read file, clean up after we're done compressing.
         jpeg_finish_compress( &cinfo );
         jpeg_destroy_compress( &cinfo );

         // Copy the memory stream to output vector.
         out.resize(jpegStreamBuf.str().size());
         jpegStreamBuf.seekg(0, std::ios_base::beg);
         jpegStreamBuf.read((char*)&out.front(), jpegStreamBuf.str().size());

         result = true;
      }
      else // Scalar type check...
      {
         ossimNotify(ossimNotifyLevel_WARN)
            << "ossimCodecFactory::encodeJpeg ERROR:"
            << "\nPassing non-eight bit data to eight bit encoder!" << std::endl;
      }
      
   } // Matches: if ( in.valid() ... )
   
   return result;
}