ossimRefPtr<ossimImageData> ossimColorNormalizedFusion::getTile( const ossimIrect& rect, ossim_uint32 resLevel) { ossimRefPtr<ossimImageData> inputTile = getNormTile(rect, resLevel); if(!inputTile.valid()) { return NULL; } if(!theInputConnection||!theIntensityConnection) { return NULL; } if((inputTile->getDataObjectStatus() == OSSIM_NULL)|| (inputTile->getDataObjectStatus() == OSSIM_EMPTY)) { return NULL; } if(theTile.valid()) { theTile->setImageRectangleAndBands(rect, inputTile->getNumberOfBands()); } ossim_float32* redBuff = (ossim_float32*)inputTile->getBuf(0); ossim_float32* grnBuff = (ossim_float32*)inputTile->getBuf(1); ossim_float32* bluBuff = (ossim_float32*)inputTile->getBuf(2); if(!redBuff||!grnBuff||!bluBuff) { return 0; } ossimRefPtr<ossimImageData> inputIntensity = getNormIntensity(rect, resLevel); if((!inputIntensity.valid()) || (!inputIntensity->getBuf()) || (inputIntensity->getDataObjectStatus() == OSSIM_EMPTY)) { return 0; } ossim_float32* mono_buff = (ossim_float32*)inputIntensity->getBuf(0); // Since NULL_PIX_VALUE is only used for Pix8 comparisons cast it now. const float NULL_PIX_VALUE = (ossim_float32)inputIntensity->getNullPix(0); const float MIN_PIX_VALUE = (ossim_float32)inputIntensity->getMinPix(0); const float MAX_PIX_VALUE = (ossim_float32)inputIntensity->getMaxPix(0); float rgb_sum; float r_wt; // Weight of red to rgb_sum. float g_wt; // Weight of green to rgb_sum. float b_wt; // Weight of blue to rgb_sum. float iVal; float redVal; float greenVal; float blueVal; int size = theTile->getWidth()*theTile->getHeight(); for (int i = 0; i < size; i++) { //*** // If no intensity source, or, no rgb source make output pixels null. //*** if ( (mono_buff[i] == NULL_PIX_VALUE) || (redBuff[i] == NULL_PIX_VALUE && grnBuff[i] == NULL_PIX_VALUE && bluBuff[i] == NULL_PIX_VALUE) ) { redBuff[i] = NULL_PIX_VALUE; grnBuff[i] = NULL_PIX_VALUE; bluBuff[i] = NULL_PIX_VALUE; } else { redVal = redBuff[i]; greenVal = grnBuff[i]; blueVal = bluBuff[i]; rgb_sum = redVal + greenVal + blueVal + 3; r_wt = 3 * (redVal + 1) / rgb_sum; g_wt = 3 * (greenVal + 1) / rgb_sum; b_wt = 3 * (blueVal + 1) / rgb_sum; iVal = mono_buff[i] + 1; redVal = r_wt * iVal - 1; greenVal = g_wt * iVal - 1; blueVal = b_wt * iVal - 1; // Clip to max pixel value of radiometry. if (redVal > MAX_PIX_VALUE) redVal = MAX_PIX_VALUE; if (greenVal > MAX_PIX_VALUE) greenVal = MAX_PIX_VALUE; if (blueVal > MAX_PIX_VALUE) blueVal = MAX_PIX_VALUE; // Assign chip value, clamp to min pixel value of radiometry if zero. redBuff[i] = (float)(redVal>0.0 ? redVal : MIN_PIX_VALUE); grnBuff[i] = (float)(greenVal>0.0 ? greenVal : MIN_PIX_VALUE); bluBuff[i] = (float)(blueVal>0.0 ? blueVal : MIN_PIX_VALUE); } } // End of loop through pixels in chip. theTile->copyNormalizedBufferToTile((float*)inputTile->getBuf()); theTile->validate(); return theTile; }
rspfRefPtr<rspfImageData> rspfSFIMFusion::getTile(const rspfIrect& rect, rspf_uint32 resLevel) { if(!theInputConnection) { return rspfRefPtr<rspfImageData>(); } if (!theIntensityConnection) { return theInputConnection->getTile(rect, resLevel); } if(!theNormLowPassTile.valid()) { theNormLowPassTile = new rspfImageData(this, RSPF_NORMALIZED_FLOAT, 1, rect.width(), rect.height()); theNormHighPassTile = new rspfImageData(this, RSPF_NORMALIZED_FLOAT, 1, rect.width(), rect.height()); theNormLowPassTile->initialize(); theNormHighPassTile->initialize(); theNormLowPassTile->makeBlank(); theNormHighPassTile->makeBlank(); } theNormLowPassTile->setImageRectangle(rect); theNormHighPassTile->setImageRectangle(rect); theNormLowPassTile->makeBlank(); theNormHighPassTile->makeBlank(); if(!theLowPassFilter->getInput() && getInput()) { initialize(); } rspfRefPtr<rspfImageData> lowTile = theLowPassFilter->getTile(rect, resLevel); rspfRefPtr<rspfImageData> highTile = theHighPassFilter->getTile(rect, resLevel); // rspfRefPtr<rspfImageData> highTile = getNormIntensity(rect, resLevel); // if we don't have valid low and high pass then return the input color tile // in its original format // if(!lowTile.valid()||!highTile.valid()) { // return theInputConnection->getTile(rect, resLevel); return 0; } if((lowTile->getDataObjectStatus() == RSPF_EMPTY)|| (!lowTile->getBuf()) || (highTile->getDataObjectStatus() == RSPF_EMPTY)|| (!highTile->getBuf())) { // return theInputConnection->getTile(rect, resLevel); return 0; } rspfRefPtr<rspfImageData> normColorData = getNormTile(rect, resLevel); rspf_uint32 y = 0; rspf_uint32 x = 0; rspf_uint32 w = theTile->getWidth(); rspf_uint32 h = theTile->getHeight(); theTile->makeBlank(); theTile->setImageRectangle(rect); if(!normColorData.valid()) { return 0; // return theTile; } if((normColorData->getDataObjectStatus() == RSPF_EMPTY)|| !normColorData->getBuf()) { return theTile; } rspfRefPtr<rspfImageData> normColorOutputData = (rspfImageData*)normColorData->dup(); normColorOutputData->setImageRectangle(rect); normColorOutputData->loadTile(normColorData.get()); // rspf_float64 slopeResult = 0.0; rspf_uint32 idx = 0; std::vector<rspf_float32*> bands(normColorData->getNumberOfBands()); lowTile->copyTileToNormalizedBuffer((rspf_float32*)theNormLowPassTile->getBuf()); highTile->copyTileToNormalizedBuffer((rspf_float32*)theNormHighPassTile->getBuf()); theNormLowPassTile->validate(); theNormHighPassTile->validate(); rspfRefPtr<rspfImageData> lowPan = (rspfImageData*)theNormLowPassTile->dup(); lowPan->setImageRectangle(rect); lowPan->loadTile(theNormLowPassTile.get()); rspfRefPtr<rspfImageData> highPan = (rspfImageData*)theNormHighPassTile->dup(); highPan->setImageRectangle(rect); highPan->loadTile(theNormHighPassTile.get()); rspf_float32* panHigh = (rspf_float32*)highPan->getBuf(); rspf_float32* panLow = (rspf_float32*)lowPan->getBuf(); for(idx = 0; idx < bands.size(); ++idx) { bands[idx] = (rspf_float32*)normColorOutputData->getBuf(idx); } // double delta = 0.0; rspf_uint32 bandsSize = (rspf_uint32)bands.size(); double normMinPix = 0.0; for(y = 0; y < h; ++y) { for(x = 0; x < w; ++x) { for(idx = 0; idx < bandsSize; ++idx) { if((*bands[idx] != 0.0)&& (*panLow > FLT_EPSILON) ) // if band is not null and not divide by 0 { normMinPix = (rspf_float32)normColorOutputData->getMinPix(idx); *bands[idx] = ((*bands[idx])*(*panHigh))/ (*panLow); if(*bands[idx] > 1.0) *bands[idx] = 1.0; if(*bands[idx] < normMinPix) *bands[idx] = normMinPix; } // let's comment out the nulling and we will instead just pass the color on // // else // { // *bands[idx] = 0.0; // } ++bands[idx]; } ++panHigh; ++panLow; } } theTile->copyNormalizedBufferToTile((rspf_float32*)normColorOutputData->getBuf()); theTile->validate(); return theTile; }