示例#1
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;
}
示例#2
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;
}
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;
            }
         }
      }
   }
}