void ossimLasReader::initTile() { const ossim_uint32 BANDS = getNumberOfOutputBands(); m_tile = new ossimImageData(this, getOutputScalarType(), BANDS, getTileWidth(), getTileHeight()); for(ossim_uint32 band = 0; band < BANDS; ++band) { m_tile->setMinPix(getMinPixelValue(band), band); m_tile->setMaxPix(getMaxPixelValue(band), band); m_tile->setNullPix(getNullPixelValue(band), band); } m_tile->initialize(); }
template <class T> void ossimHistogramRemapper::buildAutoLinearMinMaxTableTemplate(T /* dummy */) { const ossim_uint32 BANDS = getNumberOfInputBands(); // Sanity check. if (theNormalizedLowClipPoint.size() != BANDS || !getHistogram(0).valid()) { if(traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << "ossimHistogramRemapper::buildAutoLinearMinMaxTableTemplate ERROR!" << " Line: " << __LINE__ << endl; } return; } for (ossim_uint32 band = 0; band < BANDS; ++band) { ossimRefPtr<ossimHistogram> h = getHistogram(band); T nullPix = static_cast<T>(getNullPixelValue(band)); if(h.valid()) { ossim_uint32 n = h->GetRes(); ossim_float64 low = h->GetMinVal(); ossim_float64 high = h->GetMaxVal(); if(n > 0) { double newCount = 0.0; double nextPercentage = 0.0; double percentage = 0.0; int idx = 0; float * counts = h->GetCounts(); double count = h->ComputeArea(); for(idx = 0; idx < (ossim_int32)(n-1); ++idx) { if(nullPix != idx) { newCount += counts[idx]; } percentage = newCount / count; nextPercentage = (newCount + counts[idx+1]) / count; if (std::fabs(percentage - 0.006) < std::fabs(nextPercentage - 0.006)) { low = idx+1; break; } } newCount = 0.0; for (idx = n-1; idx > 0; idx--) { newCount += counts[idx]; percentage = newCount / count; nextPercentage = (newCount + counts[idx-1]) / count; if (std::fabs(percentage - 0.006) < std::fabs(nextPercentage - 0.006)) { high=idx-1; break; } } if(low > high) { low = 0; high = n - 1; } setLowClipPoint(low, band); setHighClipPoint(high, band); } } } buildLinearTable(); }
template <class T> void ossimHistogramRemapper::buildLinearTable(T /* dummy */) { // This builds a native table. theTableType = ossimTableRemapper::NATIVE; const ossim_uint32 BANDS = getNumberOfInputBands(); // Sanity check. if (theNormalizedLowClipPoint.size() != BANDS || !getHistogram(0).valid()) { if(traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << "ossimHistogramRemapper::buildTable ERROR!" << " Line: " << __LINE__ << endl; } return; } T* table = reinterpret_cast<T*>(&theTable.front()); ossim_uint32 index = 0; // Finally, build the table... for (ossim_uint32 band = 0; band < BANDS; ++band) { ossimRefPtr<ossimHistogram> h = getHistogram(band); if (h.get()) { if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimHistogramRemapper::buildLinearTable DEBUG:" << "\nband: " << band << "\nmean: " << h->GetMean() << "\nstddev: " << h->GetStandardDev() << endl; } } else { if(traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << "ossimHistogramRemapper::buildTable ERROR!" << " Line: " << __LINE__ << endl; } return; } const T NULL_PIX = static_cast<T>(getNullPixelValue(band)); const T MIN_PIX = static_cast<T>(theMinOutputValue[band]); const T MAX_PIX = static_cast<T>(theMaxOutputValue[band]); ossim_float64 min_clip_value = h->LowClipVal(theNormalizedLowClipPoint[band]); ossim_float64 max_clip_value = h->HighClipVal(1.0-theNormalizedHighClipPoint[band]); min_clip_value = floor(min_clip_value); max_clip_value = ceil(max_clip_value); ossim_float64 gain = (MAX_PIX-MIN_PIX+1)/(max_clip_value-min_clip_value); table[index] = NULL_PIX; ++index; for (ossim_uint32 pix = 1; pix < theTableBinCount; ++pix) { ossim_float64 p = pix; if (p <= min_clip_value) { p = MIN_PIX; } else if (p >= max_clip_value) { p = MAX_PIX; } else { p = ((p - min_clip_value) * gain) + MIN_PIX - 1.0; } if(p == NULL_PIX) { p = MIN_PIX; } table[index] = static_cast<T>(p+0.5); ++index; } } // End of band loop. // Clear the dirty flag so the table's not rebuilt on the next getTile. theDirtyFlag = false; }
bool ossimH5Reader::getTile(ossimImageData* result, ossim_uint32 resLevel) { bool status = false; m_mutex.lock(); //--- // Not open, this tile source bypassed, or invalid res level, // return a blank tile. //--- if( isOpen() && isSourceEnabled() && isValidRLevel(resLevel) && result && (result->getNumberOfBands() == getNumberOfOutputBands()) ) { result->ref(); // Increment ref count. //--- // Check for overview tile. Some overviews can contain r0 so always // call even if resLevel is 0. Method returns true on success, false // on error. //--- status = getOverviewTile(resLevel, result); if (!status) // Did not get an overview tile. { status = true; ossimIrect tile_rect = result->getImageRectangle(); if ( ! tile_rect.completely_within(getImageRectangle(0)) ) { // We won't fill totally so make blank first. result->makeBlank(); } if (getImageRectangle(0).intersects(tile_rect)) { // Make a clip rect. ossimIrect clipRect = tile_rect.clipToRect(getImageRectangle(0)); if (tile_rect.completely_within( clipRect) == false) { // Not filling whole tile so blank it out first. result->makeBlank(); } // Create buffer to hold the clip rect for a single band. ossim_uint32 clipRectSizeInBytes = clipRect.area() * ossim::scalarSizeInBytes( m_entries[m_currentEntry].getScalarType() ); vector<char> dataBuffer(clipRectSizeInBytes); // Get the data. for (ossim_uint32 band = 0; band < getNumberOfInputBands(); ++band) { // Hdf5 file to buffer: m_entries[m_currentEntry].getTileBuf(&dataBuffer.front(), clipRect, band); if ( m_entries[m_currentEntry].getScalarType() == OSSIM_FLOAT32 ) { //--- // NPP VIIRS data has null of "-999.3". // Scan and fix non-standard null value. //--- const ossim_float32 NP = getNullPixelValue(band); const ossim_uint32 COUNT = clipRect.area(); ossim_float32* float_buffer = (ossim_float32*)&dataBuffer.front(); for ( ossim_uint32 i = 0; i < COUNT; ++i ) { if ( float_buffer[i] <= -999.0 ) float_buffer[i] = NP; } } // Buffer to tile: result->loadBand((void*)&dataBuffer.front(), clipRect, band); } // Validate the tile, i.e. full, partial, empty. result->validate(); } else // No intersection... { result->makeBlank(); } } result->unref(); // Decrement ref count. } m_mutex.unlock(); return status; }
template<class T> void ossimCFARFilter::convolvePartial( 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 = (ossim_int32)inputData->getWidth(); ossim_int32 outputW = (ossim_int32)outputData->getWidth(); ossim_int32 outputH = (ossim_int32)outputData->getHeight(); ossim_int32 numberOfBands = (ossim_int32)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_int32 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)); T nullPix = static_cast<T>(inputData->getNullPix(band)); T oNullPix = static_cast<T>(getNullPixelValue(band)); if(inputBuf&&outputBuf) { for(ossim_int32 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_int32 col = 0; col < outputH; ++col) { //TODO: Need to have an efficient means of detecting nulls if((ulKernelStartBuf[0] != nullPix)&& (ulKernelStartBuf[1] != nullPix)&& (ulKernelStartBuf[2] != nullPix)&& (leftKernelStartBuf[0] != nullPix)&& (leftKernelStartBuf[1] != nullPix)&& (leftKernelStartBuf[2] != nullPix)&& (llKernelStartBuf[0] != nullPix)&& (llKernelStartBuf[1] != nullPix)&& (llKernelStartBuf[2] != nullPix)) { //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); } } else { *outputBuf = oNullPix; } // // Need to implement the convolution here // ++ulKernelStartBuf; ++ul1KernelStartBuf; ++leftKernelStartBuf; ++ll1KernelStartBuf; ++llKernelStartBuf; ++outputBuf; } } } } }
template<class T> void rspf3x3ConvolutionFilter::convolvePartial( T, rspfRefPtr<rspfImageData> inputData, rspfRefPtr<rspfImageData> 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; rspf_int32 inputW = (rspf_int32)inputData->getWidth(); rspf_int32 outputW = (rspf_int32)outputData->getWidth(); rspf_int32 outputH = (rspf_int32)outputData->getHeight(); rspf_int32 numberOfBands = (rspf_int32)inputData->getNumberOfBands(); rspfIpt outputOrigin = outputData->getOrigin(); rspfIpt inputOrigin = inputData->getOrigin(); rspf_int32 startInputOffset = std::abs(outputOrigin.y - inputOrigin.y)* inputW + std::abs(outputOrigin.x - inputOrigin.x); rspf_int32 ulKernelStart = -inputW - 1; rspf_int32 leftKernelStart = -1; rspf_int32 llKernelStart = inputW - 1; T* ulKernelStartBuf = NULL; T* leftKernelStartBuf = NULL; T* llKernelStartBuf = NULL; for(rspf_int32 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)); T nullPix = static_cast<T>(inputData->getNullPix(band)); T oNullPix = static_cast<T>(getNullPixelValue(band)); if(inputBuf&&outputBuf) { for(rspf_int32 row = 0; row < outputW; ++row) { rspf_int32 rowOffset = inputW*row; ulKernelStartBuf = inputBuf + (rowOffset + ulKernelStart); leftKernelStartBuf = inputBuf + (rowOffset + leftKernelStart); llKernelStartBuf = inputBuf + (rowOffset + llKernelStart); for(rspf_int32 col = 0; col < outputH; ++col) { if((ulKernelStartBuf[0] != nullPix)&& (ulKernelStartBuf[1] != nullPix)&& (ulKernelStartBuf[2] != nullPix)&& (leftKernelStartBuf[0] != nullPix)&& (leftKernelStartBuf[1] != nullPix)&& (leftKernelStartBuf[2] != nullPix)&& (llKernelStartBuf[0] != nullPix)&& (llKernelStartBuf[1] != nullPix)&& (llKernelStartBuf[2] != nullPix)) { 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); } } else { *outputBuf = oNullPix; } // // Need to implement the convolution here // ++ulKernelStartBuf; ++leftKernelStartBuf; ++llKernelStartBuf; ++outputBuf; } } } } }