void calculateIntegralImage( const ChannelT<T> &channel, typename CHANTRAIT<T>::Accum *integralImage ) { int32_t imageWidth = channel.getWidth(), imageHeight = channel.getHeight(); ptrdiff_t srcRowBytes = channel.getRowBytes(); uint8_t srcInc = channel.getIncrement(); const T *src = channel.getData(); /*for( int32_t i = 0; i < imageWidth; i++ ) { // reset this column sum typename CHANTRAIT<T>::Accum sum = 0; for( int32_t j = 0; j < imageHeight; j++ ) { uint32_t index = j * imageWidth + i; sum += src[j*srcRowBytes+i*srcInc]; if( i == 0 ) integralImage[index] = sum; else integralImage[index] = integralImage[index-1] + sum; } }*/ for( int32_t j = 0; j < imageHeight; j++ ) { // reset this column sum typename CHANTRAIT<T>::Accum sum = 0; for( int32_t i = 0; i < imageWidth; i++ ) { uint32_t index = j * imageWidth + i; sum += src[j*srcRowBytes+i*srcInc]; if( j == 0 ) integralImage[index] = sum; else integralImage[index] = integralImage[index-imageWidth] + sum; } } }
ImageSourceChannel( const ChannelT<T> &channel ) : ImageSource() { mWidth = channel.getWidth(); mHeight = channel.getHeight(); setColorModel( ImageIo::CM_GRAY ); setChannelOrder( ImageIo::Y ); if( channel.getIncrement() != 1 ) setCustomPixelInc( channel.getIncrement() ); if( boost::is_same<T,uint8_t>::value ) { setDataType( ImageIo::UINT8 ); mChannel8u = *reinterpret_cast<const Channel8u*>( &channel ); // register reference to 'channel' } else if( boost::is_same<T,uint16_t>::value ) { setDataType( ImageIo::UINT16 ); mChannel16u = *reinterpret_cast<const Channel16u*>( &channel ); // register reference to 'channel' } else if( boost::is_same<T,float>::value ) { setDataType( ImageIo::FLOAT32 ); mChannel32f = *reinterpret_cast<const Channel32f*>( &channel ); // register reference to 'channel' } else throw; // this channel seems to be a type we've never met mRowBytes = channel.getRowBytes(); mData = reinterpret_cast<const uint8_t*>( channel.getData() ); }
void adaptiveThresholdZero( const ChannelT<T> &srcChannel, int32_t windowSize, ChannelT<T> *dstChannel ) { typedef typename CHANTRAIT<T>::Accum SUMT; int32_t imageWidth = srcChannel.getWidth(); int32_t imageHeight = srcChannel.getHeight(); SUMT *integralImage; // create the integral image integralImage = (SUMT*)malloc( imageWidth * imageHeight * sizeof( typename CHANTRAIT<T>::Accum ) ); calculateIntegralImage( srcChannel, integralImage ); calculateAdaptiveThresholdZero( &srcChannel, integralImage, windowSize, dstChannel ); free( integralImage ); }