/******************************************************************************* * Function: doubleThresholdByValue * Description: performs double local thresholding using Otsu's method * Arguments: percentage - parameter for amount of lowering Otsu threshold roiMask - ROI binary mask * Returns: void * Comments: * Revision: *******************************************************************************/ void FGExtraction::doubleThresholdByValue(double percentage, Mat roiMask) { int u = 0; int thresh = getOtsuThreshold(0, 255, &u, roiMask); int highThresh = thresh - int(percentage*(thresh - u)); int lowThresh = thresh - int(1.4*percentage*(thresh - u)); #ifdef DEBUG //cout << "th_H = " << highThresh << "; th_L = " << lowThresh << "; \n"; #endif Mat maskedFG; bitwise_and(_inImg, roiMask, maskedFG); // generate high and low look-up tables Mat highLUT(1, 256, CV_8U); Mat lowLUT(1, 256, CV_8U); uchar* highData = highLUT.data; uchar* lowData = lowLUT.data; for(int i = 0; i < 256; ++i){ highData[i] = i <= highThresh ? 0 : 255; lowData[i] = i <= lowThresh ? 0 : 255; } // threshold by using look-up tables LUT(maskedFG, highLUT, _highMask); LUT(maskedFG, lowLUT, _lowMask); bitwise_or(_fgHighImg, _highMask, _fgHighImg, roiMask); bitwise_or(_fgLowImg, _lowMask, _fgLowImg, roiMask); }
int ImageProcessor::getHigherThreshold() { switch (thresholdPolicy) { case ImagePolicy::OTSU: return getOtsuThreshold(); case ImagePolicy::ENTROPY: return getEntropyThreshold(); case ImagePolicy::COSTUMED: return higherThreshold; } return 0; }