MCPcopy Create free account
hub / github.com/creatale/node-dv / threshold

Method threshold

deps/opencv/modules/imgproc/src/thresh.cpp:710–788  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

708}
709
710double cv::threshold( InputArray _src, OutputArray _dst, double thresh, double maxval, int type )
711{
712 Mat src = _src.getMat();
713 bool use_otsu = (type & THRESH_OTSU) != 0;
714 type &= THRESH_MASK;
715
716 if( use_otsu )
717 {
718 CV_Assert( src.type() == CV_8UC1 );
719 thresh = getThreshVal_Otsu_8u(src);
720 }
721
722 _dst.create( src.size(), src.type() );
723 Mat dst = _dst.getMat();
724
725 if( src.depth() == CV_8U )
726 {
727 int ithresh = cvFloor(thresh);
728 thresh = ithresh;
729 int imaxval = cvRound(maxval);
730 if( type == THRESH_TRUNC )
731 imaxval = ithresh;
732 imaxval = saturate_cast<uchar>(imaxval);
733
734 if( ithresh < 0 || ithresh >= 255 )
735 {
736 if( type == THRESH_BINARY || type == THRESH_BINARY_INV ||
737 ((type == THRESH_TRUNC || type == THRESH_TOZERO_INV) && ithresh < 0) ||
738 (type == THRESH_TOZERO && ithresh >= 255) )
739 {
740 int v = type == THRESH_BINARY ? (ithresh >= 255 ? 0 : imaxval) :
741 type == THRESH_BINARY_INV ? (ithresh >= 255 ? imaxval : 0) :
742 /*type == THRESH_TRUNC ? imaxval :*/ 0;
743 dst.setTo(v);
744 }
745 else
746 src.copyTo(dst);
747 return thresh;
748 }
749 thresh = ithresh;
750 maxval = imaxval;
751 }
752 else if( src.depth() == CV_16S )
753 {
754 int ithresh = cvFloor(thresh);
755 thresh = ithresh;
756 int imaxval = cvRound(maxval);
757 if( type == THRESH_TRUNC )
758 imaxval = ithresh;
759 imaxval = saturate_cast<short>(imaxval);
760
761 if( ithresh < SHRT_MIN || ithresh >= SHRT_MAX )
762 {
763 if( type == THRESH_BINARY || type == THRESH_BINARY_INV ||
764 ((type == THRESH_TRUNC || type == THRESH_TOZERO_INV) && ithresh < SHRT_MIN) ||
765 (type == THRESH_TOZERO && ithresh >= SHRT_MAX) )
766 {
767 int v = type == THRESH_BINARY ? (ithresh >= SHRT_MAX ? 0 : imaxval) :

Callers 1

image.test.jsFile · 0.80

Calls 13

getThreshVal_Otsu_8uFunction · 0.85
cvFloorFunction · 0.85
cvRoundFunction · 0.85
RangeClass · 0.85
ThresholdRunnerClass · 0.85
getMatMethod · 0.45
typeMethod · 0.45
createMethod · 0.45
sizeMethod · 0.45
depthMethod · 0.45
setToMethod · 0.45
copyToMethod · 0.45

Tested by

no test coverage detected