Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <labust/blueview/ThresholdPolicy.hpp>
00035 #include <opencv2/imgproc/imgproc.hpp>
00036
00037 using namespace labust::blueview;
00038
00039 MatPtr SimpleThreshold::threshold(const MatPtr prefiltered, float weight)
00040 {
00041 MatPtr thresholded(new cv::Mat(prefiltered->size(),CV_8UC1));
00042 cv::threshold(*prefiltered, *thresholded, weight, 255, CV_THRESH_BINARY);
00043 thresholded->convertTo(*thresholded,CV_8UC1);
00044 return thresholded;
00045 }
00046
00047 MatPtr HistThreshold::threshold(const MatPtr prefiltered,
00048 float min,float max, unsigned char maxVal)
00049 {
00050 enum {thehoodWidth = 1, thehoodHeight = 1};
00051 MatPtr thresholded(new cv::Mat(prefiltered->size(),CV_8U, cv::Scalar(0)));
00052
00053 size_t width(prefiltered->size().width), height(prefiltered->size().height);
00054
00055 for(int i=1; i<(width-1); ++i)
00056 {
00057 for(int j=1; j<(height-1); ++j)
00058 {
00059 cv::Mat thehood(*prefiltered,
00060 cv::Range(i-thehoodWidth,i+thehoodWidth),
00061 cv::Range(j-thehoodHeight,j+thehoodHeight));
00062 cv::Mat rethood(*prefiltered,
00063 cv::Range(i-thehoodWidth,i+thehoodWidth),
00064 cv::Range(j-thehoodHeight,j+thehoodHeight));
00065
00066 bool flag = false;
00067
00068 for (int k=0; k<(thehoodWidth*2 + 1); ++k)
00069 {
00070 for (int k2=0; k2<(thehoodHeight*2 + 1); ++k2)
00071 {
00072
00073 if ((flag = thehood.at<float>(k,k2) >= max)) break;
00074 }
00075 }
00076
00077 if (flag)
00078 {
00079 for (int k=0; k<(thehoodWidth*2 + 1); ++k)
00080 {
00081 for (int k2=0; k2<(thehoodHeight*2 + 1); ++k2)
00082 {
00083 if (thehood.at<float>(k,k2) >= min)
00084 {
00085 rethood.at<float>(k,k2) = maxVal;
00086 }
00087 else
00088 {
00089 rethood.at<float>(k,k2) = 0;
00090 }
00091 }
00092 }
00093 }
00094 else
00095 {
00096 cv::Mat(3,3,CV_8U,cv::Scalar(0)).copyTo(rethood);
00097 }
00098 }
00099 }
00100
00101 return thresholded;
00102 }
00103
00104
00105