Threshold
代码如下
static void Main(String[] args)
{
Mat img = CvInvoke.Imread(@"C:\Users\dell\Pictures\facesGray.png", ImreadModes.Grayscale);
Mat dst = new Mat();
double thresholdValue = ;
double max = ;
CvInvoke.Threshold(img, dst, thresholdValue, max, ThresholdType.Binary);
CvInvoke.Imshow("src", img);
CvInvoke.Imshow("Binary", dst);
CvInvoke.Threshold(img, dst, thresholdValue, max, ThresholdType.BinaryInv);
CvInvoke.Imshow("BinaryInv", dst);
CvInvoke.Threshold(img, dst, thresholdValue, max, ThresholdType.Otsu);
CvInvoke.Imshow("Otsu", dst); CvInvoke.Threshold(img, dst, thresholdValue, max, ThresholdType.ToZero);
CvInvoke.Imshow("ToZero", dst); CvInvoke.Threshold(img, dst, thresholdValue, max, ThresholdType.ToZeroInv);
CvInvoke.Imshow("ToZeroInv", dst); CvInvoke.Threshold(img, dst, thresholdValue, max, ThresholdType.Trunc);
CvInvoke.Imshow("Trunc", dst);
CvInvoke.WaitKey();
}
例子
class Program
{
static void Main(String[] args)
{
Mat img = CvInvoke.Imread(@"C:\Users\dell\Pictures\faces.png");
Mat dst = new Mat();
Mat weighted = new Mat();
weighted = sum_rgb(img, dst).Clone();
CvInvoke.Imshow("src", img);
CvInvoke.Imshow("weighted", weighted);
CvInvoke.Imshow("dst", dst);
CvInvoke.WaitKey();
}
static Mat sum_rgb(Mat src,Mat dst)
{
int ch = src.NumberOfChannels;
VectorOfMat vMat = new VectorOfMat(ch);
CvInvoke.Split(src, vMat);
Mat b = vMat[];
Mat g = vMat[];
Mat r= vMat[];
Mat s = new Mat();
CvInvoke.AddWeighted(r, 1.0 / , g, 1.0 / , 0.0,s);
CvInvoke.AddWeighted(s, 1.0, b, 1.0 / , 0.0, s);
CvInvoke.Threshold(s, dst, , , ThresholdType.Trunc);
return s;
}
}
自适应Threshold
代码
static void Main(String[] args)
{
Mat img = CvInvoke.Imread(@"C:\Users\dell\Pictures\faces.png",);
Mat Gaussian = new Mat();
Mat Mean = new Mat();
CvInvoke.AdaptiveThreshold(img, Gaussian, , AdaptiveThresholdType.GaussianC, ThresholdType.Binary, , );
CvInvoke.AdaptiveThreshold(img, Mean, , AdaptiveThresholdType.MeanC, ThresholdType.Binary, , );
CvInvoke.Imshow("src", img);
CvInvoke.Imshow("Gaussian", Gaussian);
CvInvoke.Imshow("Mean", Mean);
CvInvoke.WaitKey();
}
代码
static void Main(String[] args)
{
Mat img = CvInvoke.Imread(@"C:\Users\dell\Pictures\faces.png"); Mat dst = new Mat();
CvInvoke.BoxFilter(img, dst, DepthType.Default, new Size(, ), new Point(-, -));
CvInvoke.Imshow("src", img);
CvInvoke.Imshow("boxFilter", dst);
CvInvoke.Blur(img, dst, new Size(, ), new Point(-, -));
CvInvoke.Imshow("blur", dst);
CvInvoke.GaussianBlur(img, dst, new Size(, ), );
CvInvoke.Imshow("Gaussian", dst);
CvInvoke.MedianBlur(img, dst, );
CvInvoke.Imshow("median", dst);
CvInvoke.BilateralFilter(img, dst, , 30.0, 2.0);
CvInvoke.Imshow("Bilateral", dst);
CvInvoke.WaitKey();
}
效果如下