本文整理汇总了C#中Image.ThresholdBinary方法的典型用法代码示例。如果您正苦于以下问题:C# Image.ThresholdBinary方法的具体用法?C# Image.ThresholdBinary怎么用?C# Image.ThresholdBinary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Image
的用法示例。
在下文中一共展示了Image.ThresholdBinary方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExtractContour
public List<LineSegment2D> ExtractContour(Image<Bgr, byte> img,out Image<Bgr, byte> temp )
{
List<LineSegment2D> ListOfLines = new List<LineSegment2D>();
Image<Gray, byte> gray = new Image<Gray, byte>(img.ToBitmap());
gray.ThresholdBinary(new Gray(149), new Gray(255));
gray._Dilate(1);
gray._Erode(1);
img.ROI = new Rectangle(new Point(0, Img_Height - Roi_Height), new Size(Img_Width, Roi_Height));
gray.ROI = new Rectangle(new Point(0, Img_Height - Roi_Height), new Size(Img_Width, Roi_Height));
Image<Gray, byte> canny = gray.Canny(150, 50);
//canny.Save("D:\\temp\\canny.jpg");
Image<Bgr, byte> lineimage = img;
lines = canny.HoughLines(1, 2, 3, Math.PI / 180, 150, 80, 400);
foreach (LineSegment2D line in lines[0])
{
float theta = line.Direction.Y / line.Direction.X;
float c = line.P1.Y - theta * line.P1.X;
if (Math.Abs(theta) > 0.1 && Math.Abs(theta) < 0.9&&c<300)
{
lineimage.Draw(line, new Bgr(0, 0, 255), 1);
ListOfLines.Add(line);
}
}
temp = lineimage;
//lineimage.Save("D:\\temp\\HoughLines.jpg");
return ListOfLines;
}
示例2: ImagePreprocessing
public ImagePreprocessing(Image<Gray, Byte> image)
{
this.img = image;
this.rects = new List<Rectangle>();
this.images = new List<Image<Gray, Byte>>();
this.img = image.ThresholdBinary(new Gray(127), new Gray(255));
CvInvoke.cvNot(this.img, this.img);
}
示例3: binaryThresholdNiBlack
//:::::::::::::::::fin variables::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//:::::::::::::Method for make the image binary::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//the binarization is inspired in NiBlanck banarization, but in this case, we use just the average of the image.
//openinOperation() remove the noise of the binarized image, using morphological operation, we use opening.
private Image<Gray, Byte> binaryThresholdNiBlack(Image<Gray, Byte> handImage)
{
Gray media;
MCvScalar desest;
handImage.AvgSdv(out media, out desest);
handImage = handImage.ThresholdBinary(media, new Gray(255));
handImage = closeOperation(handImage);
handImage = openingOperation(handImage);
return handImage;
}//end BinaryThresholdNiBlack
示例4: TestThreshold2
public void TestThreshold2()
{
using (Image<Gray, short> image = new Image<Gray, short>(1024, 960))
{
image.SetRandUniform(new MCvScalar(short.MinValue), new MCvScalar(short.MaxValue));
image.ThresholdBinary(new Gray((short.MinValue + short.MaxValue) / 2), new Gray(short.MaxValue));
}
}
示例5: GetMoving
public Image<Bgr, Byte> GetMoving(Image<Bgr, Byte> source)
{
//var sub = currentImage.AbsDiff(_prevImage).Convert<Gray, Byte>();
var difference = MovingDetection(source).Convert<Gray, Byte>();
_prevImage = source.Copy();
difference = difference.ThresholdBinary(new Gray(50), new Gray(255));
var distTransformed = new Image<Gray, float>(source.Width, source.Height);
CvInvoke.cvDistTransform(difference.Ptr, distTransformed.Ptr, DIST_TYPE.CV_DIST_L2, 3, new[] { 1f, 1f }, IntPtr.Zero);
var byteDist = distTransformed.ThresholdBinary(new Gray(2), new Gray(255)).Convert<Gray, byte>();
Image<Gray, byte> mask = new Image<Gray, byte>(byteDist.Width + 2, byteDist.Height + 2);
mask.ROI = new Rectangle(1, 1, byteDist.Width, byteDist.Height);
CvInvoke.cvCopy(byteDist, mask, IntPtr.Zero);
mask.ROI = new Rectangle(0, 0, byteDist.Width + 2, byteDist.Height + 2);
mask = mask.Not();
//return mask.Convert<Bgr, Byte>();
var result = mask.Convert<Bgr, Byte>();
for (int i = 0; i < difference.Width; i++)
{
for (int j = 0; j < difference.Height; j++)
{
if (mask.Data[j, i, 0] == 0)
{
var comp = new MCvConnectedComp();
CvInvoke.cvFloodFill(
difference.Ptr,
new Point(i, j),
new MCvScalar(200, 200, 200, 0), // Color
new MCvScalar(0, 0, 0), // Lo
new MCvScalar(0, 0, 0), // Up
out comp,
Emgu.CV.CvEnum.CONNECTIVITY.EIGHT_CONNECTED,
Emgu.CV.CvEnum.FLOODFILL_FLAG.DEFAULT,
mask.Ptr
);
if (comp.area > 500 && comp.area < 2500
&& comp.rect.Size.Height > 10 && comp.rect.Size.Height < 230
&& comp.rect.Size.Width > 10 && comp.rect.Size.Width < 230)
{
ReplaceColors(result, comp.rect);
}
}
}
}
return result.Convert<Bgr, Byte>();
}
示例6: CountContours
public int CountContours(Bitmap temp)
{
///<summary>return the number of contours in the image</summary>
/// <param name="temp">bitmap image, contains only the contour.</param>
///
var contourNumber = 0;
var gray = new Image<Gray, byte>(temp);
gray.ThresholdBinary(new Gray(149), new Gray(255));
gray._Dilate(1);
gray._Erode(1);
Contour<Point> contours;
using (var canny = gray.Canny(150, 50))
{
var stor = new MemStorage();
contours = canny.FindContours(CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, RETR_TYPE.CV_RETR_CCOMP, stor);
}
if (contours == null) return 0;
for (; contours != null; contours = contours.HNext)
{
contourNumber++;
}
return contourNumber;
}
示例7: _testSobelParameters
public void _testSobelParameters(Image<Gray, Single> img, int threshold, int maxGrayVal, int closingIteration, int cols, int rows, int anchorX, int anchorY, int shape)
{
int xOrder = 0, yOrder = 0, appetureSize = 1;
for (appetureSize = 3; appetureSize < 8; appetureSize += 2)
{
for (xOrder = 0; xOrder < appetureSize-1; xOrder++)
for (yOrder = 0; yOrder < appetureSize-1; yOrder++)
{
img = img.Sobel(xOrder, yOrder, appetureSize);
StructuringElementEx element;
if (shape == 0)
element = new StructuringElementEx(cols, rows, anchorX, anchorY, Emgu.CV.CvEnum.CV_ELEMENT_SHAPE.CV_SHAPE_RECT);
else if (shape == 1)
element = new StructuringElementEx(cols, rows, anchorX, anchorY, Emgu.CV.CvEnum.CV_ELEMENT_SHAPE.CV_SHAPE_CROSS);
else
element = new StructuringElementEx(cols, rows, anchorX, anchorY, Emgu.CV.CvEnum.CV_ELEMENT_SHAPE.CV_SHAPE_ELLIPSE);
img = img.MorphologyEx(element, Emgu.CV.CvEnum.CV_MORPH_OP.CV_MOP_CLOSE, closingIteration);
img = img.Rotate(90.0, new Gray(255), false);
img = img.MorphologyEx(element, Emgu.CV.CvEnum.CV_MORPH_OP.CV_MOP_CLOSE, closingIteration);
img = img.Rotate(-90.0, new Gray(255), false);
if (threshold >= 0 && threshold <= maxGrayVal)
{
img = img.ThresholdBinary(new Gray(threshold), new Gray(255));
}
else
{
MessageBox.Show("Threshold is not appropriate, please choose another!");
}
img.Bitmap.Save(@"Sobel\" + xOrder + " " + yOrder + " " + appetureSize + ".png");
}
}
}
示例8: GaitAnalysis
private void GaitAnalysis(Image<Bgr, byte> image, bool captureAngles)
{
Contour<System.Drawing.Point> contours = null;
List<System.Drawing.PointF> markers = null ;
MCvScalar markerColor;
original_Frame = image.Copy();
umbral_frame = null;
umbral_frame = image.Convert<Gray, Byte>();
umbral_frame = umbral_frame.ThresholdBinary(new Gray((int)sliderMin.Value), new Gray(255));
//umbral_frame._SmoothGaussian(7 );
//umbral_frame.SmoothBlur(1,1);
using (MemStorage stor = new MemStorage())
{
//Find contours with no holes try CV_RETR_EXTERNAL to find holes
contours = umbral_frame.FindContours(
Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE,
Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_EXTERNAL,
stor);
markers = new List<System.Drawing.PointF>();
blobCount = 0;
for (int i = 0; contours != null; contours = contours.HNext)
{
i++;
float markerPosX = contours.GetMinAreaRect().center.X;
float markerPosY = contours.GetMinAreaRect().center.Y;
//if ((contours.Area > Math.Pow(sliderMinSize.Value, 2)) && (contours.Area < Math.Pow(sliderMaxSize.Value, 2)))
if ((contours.Area > Math.Pow(sliderMinSize.Value, 2)) && (contours.Area < Math.Pow(sliderMaxSize.Value, 2))
&& 40 < markerPosY && markerPosY < original_Frame.Height - 60
&& 50 < markerPosX && markerPosX < original_Frame.Width - 50)
//if ((contours.Area > Math.Pow(sliderMinSize.Value, 2)) && (contours.Area < Math.Pow(sliderMaxSize.Value, 2)))
//if ((contours.Area > Math.Pow(sliderMinSize.Value, 2)) && (contours.Area < Math.Pow(sliderMaxSize.Value, 2))
// && 70 < markerPosY && markerPosY < ym
// && xm < markerPosX && markerPosX < original_Frame.Width - 50)
{
MCvBox2D box = contours.GetMinAreaRect();
//openCVImg.Draw(box, new Bgr(System.Drawing.Color.Red), 2);
//umbral_frame.Draw(box, new Gray(88), 2);
blobCount++;
markerColor = new MCvScalar(0, 0, 255);
//if (blobCount == 3) // Marcador del tobillo
//{
// double actualMarkerInitialContact = box.center.Y;
// if (actualMarkerInitialContact > markerInitialContact)
// {
// markerInitialContact = actualMarkerInitialContact;
// markerColor = new MCvScalar(255, 0, 0);
// }
//}
CvInvoke.cvCircle(original_Frame,
new System.Drawing.Point((int)box.center.X, (int)box.center.Y),
2,
markerColor,
-1,
LINE_TYPE.CV_AA,
0);
System.Drawing.PointF pointF = new System.Drawing.PointF(box.center.X, box.center.Y);
//CircleF c = new CircleF(pointF, 20);
//original_Frame.Draw(c,
// new Bgr(System.Drawing.Color.Orange),
// 3);
markers.Add(pointF);
}
}
}
if (markers.Count == 3)
{
DrawLines(markers, original_Frame,captureAngles);
markersHistory.Add(markers);
}
//DrawLinesHoriontal(markers, original_Frame, captureAngles);
IImageFormat.Source = ToBitmapSource(original_Frame);
IImage_umbral.Source = ToBitmapSource(umbral_frame);
txtBlobCount.Text = blobCount.ToString();
//.........这里部分代码省略.........
示例9: _imageProcessing
/// <summary>
///
/// </summary>
/// <param name="img">Input Image</param>
/// <param name="threshold">Threshold value (with 8-bit image is from 0 to 255)</param>
/// <param name="maxGrayVal">Maximum Gray Value</param>
/// <param name="closingIteration">number of Iterations</param>
/// <returns>Processed Image</returns>
public Image<Gray, Single> _imageProcessing(Image<Gray, Single> img, int threshold, int maxGrayVal, int closingIteration)
{
img = img.Sobel(0, 1, 3);
StructuringElementEx element = new StructuringElementEx(3, 3, -1, -1, Emgu.CV.CvEnum.CV_ELEMENT_SHAPE.CV_SHAPE_ELLIPSE);
img = img.MorphologyEx(element, Emgu.CV.CvEnum.CV_MORPH_OP.CV_MOP_CLOSE, closingIteration);
img = img.Rotate(-90.0, new Gray(255), false);
img = img.MorphologyEx(element, Emgu.CV.CvEnum.CV_MORPH_OP.CV_MOP_CLOSE, closingIteration);
img = img.Rotate(90.0, new Gray(255), false);
if (threshold >= 0 && threshold <= maxGrayVal)
{
img = img.ThresholdBinary(new Gray(threshold), new Gray(maxGrayVal));
}
else
{
//MessageBox.Show("Threshold is not appropriate, please choose another!");
throw new ArgumentOutOfRangeException("Threshold is not appropriate, please choose another threshold value!");
}
return img;
}
示例10: _imageProcessing
/// <summary>
///
/// </summary>
/// <param name="img">Input Image</param>
/// <param name="threshold">Threshold value (with 8-bit image is from 0 to 255)</param>
/// <param name="maxGrayVal">Maximum Gray Value</param>
/// <param name="closingIteration">number of Iterations</param>
/// <returns></returns>
private Image<Gray, Single> _imageProcessing(Image<Gray, Single> img, int threshold, int maxGrayVal, int closingIteration)
{
img = img.Sobel(0, 1, 4);
StructuringElementEx element = new StructuringElementEx(4, 4, 1, 1, Emgu.CV.CvEnum.CV_ELEMENT_SHAPE.CV_SHAPE_RECT);
//MessageBox.Show((int)Emgu.CV.CvEnum.CV_ELEMENT_SHAPE.CV_SHAPE_ELLIPSE + "");
img = img.MorphologyEx(element, Emgu.CV.CvEnum.CV_MORPH_OP.CV_MOP_CLOSE, closingIteration);
img = img.Rotate(90.0, new Gray(maxGrayValue), false);
img = img.MorphologyEx(element, Emgu.CV.CvEnum.CV_MORPH_OP.CV_MOP_CLOSE, closingIteration);
img = img.Rotate(-90.0, new Gray(maxGrayValue), false);
if (threshold >= 0 && threshold <= maxGrayVal)
{
img = img.ThresholdBinary(new Gray(threshold), new Gray(maxGrayValue));
}
else
{
MessageBox.Show("Threshold is not appropriate, please choose another!");
}
return img;
}
示例11: _testMorphological
private Image<Gray, Single> _testMorphological(Image<Gray, Single> img, int threshold, int maxGrayVal, int closingIteration, int cols, int rows, int anchorX, int anchorY, int shape)
{
int xOrder = Int32.Parse(txtXorder.Text), yOrder = Int32.Parse(txtYorder.Text),
appetureSize = Int32.Parse(txtAppetureSize.Text);
//img = img.Sobel(0, 1, 5);
//img = img.Sobel(xOrder, yOrder, appetureSize);
img = sobel_Filter(img);
StructuringElementEx element;
if(shape==0)
element = new StructuringElementEx(cols, rows, anchorX, anchorY, Emgu.CV.CvEnum.CV_ELEMENT_SHAPE.CV_SHAPE_RECT);
else if (shape == 1)
element = new StructuringElementEx(cols, rows, anchorX, anchorY, Emgu.CV.CvEnum.CV_ELEMENT_SHAPE.CV_SHAPE_CROSS);
else
element = new StructuringElementEx(cols, rows, anchorX, anchorY, Emgu.CV.CvEnum.CV_ELEMENT_SHAPE.CV_SHAPE_ELLIPSE);
img = img.MorphologyEx(element, Emgu.CV.CvEnum.CV_MORPH_OP.CV_MOP_CLOSE, closingIteration);
img = img.Rotate(90.0, new Gray(255), false);
img = img.MorphologyEx(element, Emgu.CV.CvEnum.CV_MORPH_OP.CV_MOP_CLOSE, closingIteration);
img = img.Rotate(-90.0, new Gray(255), false);
if (threshold >= 0 && threshold <= maxGrayVal)
{
img = img.ThresholdBinary(new Gray(threshold), new Gray(255));
}
else
{
MessageBox.Show("Threshold is not appropriate, please choose another!");
}
//img.Bitmap.Save(@"Sobel\" + xOrder + " " + yOrder + " " + appetureSize + ".png");
return img;
}
示例12: WearObject
public Image<Bgra, byte> WearObject(Image<Bgra, byte> inputBgra, AccessoryOverlay accessory)
{
var bgraBlack = new Bgra(0, 0, 0, 0);
if (accessory.FinalRectangle == Rectangle.Empty)
{
return inputBgra;
}
ConformRoi(accessory, inputBgra);
var overlayRect = accessory.FinalRectangle;
var resizeOverlayBgra = accessory.Overlay.Resize(overlayRect.Width, overlayRect.Height, Inter.Linear);
var overlayTargetBgra = new Image<Bgra, byte>(inputBgra.Width, inputBgra.Height, bgraBlack);
Log.Info(m => m("Overlay rect {0}", overlayRect));
overlayTargetBgra.ROI = overlayRect;
resizeOverlayBgra.CopyTo(overlayTargetBgra);
overlayTargetBgra.ROI = Rectangle.Empty;
const bool useMask = true;
if (useMask)
{
var overlayMask = new Image<Gray, Byte>(inputBgra.Width, inputBgra.Height);
CvInvoke.CvtColor(overlayTargetBgra, overlayMask, ColorConversion.Bgr2Gray);
overlayMask = overlayMask.ThresholdBinary(new Gray(1), new Gray(1));
inputBgra.SetValue(bgraBlack, overlayMask);
}
var outputBgra = inputBgra.AddWeighted(overlayTargetBgra, 1, 1, 1);
inputBgra.ROI = Rectangle.Empty;
outputBgra.ROI = Rectangle.Empty;
return outputBgra;
}
示例13: FillAndThresholdImage
static Image<Gray, byte> FillAndThresholdImage(Image<Gray, byte> inputImg)
{
//the marker occludes the top left corner of the sticky note and can interfere the drawing extraction
//so needs to be removed by being filled by white color
inputImg.Draw(new System.Drawing.Rectangle(0, 0, MARKER_SIZE*3/4, MARKER_SIZE*3/4), new Gray(255), 0);
double sumGray = inputImg.GetSum().Intensity;
int marker_area = MARKER_SIZE * MARKER_SIZE * 9 / 16;
double whiteRegion = 255 * marker_area;
sumGray -= whiteRegion;
double avgGray = sumGray / (inputImg.Width * inputImg.Height - marker_area);
Image<Gray, Byte> subToMean = inputImg.Sub(new Gray(avgGray));
double variance = 0;
for (int x = 0; x < inputImg.Width; x++)
{
for(int y=0; y < inputImg.Height; y++)
{
if (x >= 0 && x < MARKER_SIZE * 3 / 4
&& y >= 0 && y < MARKER_SIZE * 3 / 4)
{
continue;
}
Point p = new Point(x, y);
double dif = subToMean[p].Intensity;
variance += dif * dif;
}
}
double stdev = Math.Sqrt(variance / (inputImg.Width * inputImg.Height - marker_area));
inputImg = inputImg.ThresholdBinary(new Gray(avgGray - 1.1*stdev), new Gray(255));
return inputImg;
}
示例14: processFrame
private Image<Gray, byte> processFrame(Image<Gray, byte> image)
{
// image._Flip(Emgu.CV.CvEnum.FLIP.VERTICAL);
image = image.ThresholdBinary(new Gray(250), new Gray(255)); //Show just the very bright things
Contour<System.Drawing.Point> contours = image.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE,
Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_LIST);
contourCircles = FindPossibleCircles(contours);
/*Testing blob detection.
*
*if (contourCircles != null)
*{
* foreach (CircleF circle in contourCircles)
* {
* image.Draw(circle, new Gray(100), 1);
* }
*}
*
*/
return image;
}
示例15: preProcessImage
private static Image<Gray, byte> preProcessImage(
Image<Gray, byte> gImage,
int para1,
int para2)
{
//Image<Gray, byte> gImage = frame.Convert<Gray, byte>();
//gImage = gImage.ConvertScale<byte>(0.25, 0);
//Image<Gray, byte> gImage2 = gImage.Clone();
//gImage2 = gImage2.SmoothBlur((int)para2, (int)para2);
//gImage2 = gImage2.Not();
//gImage = gImage.AddWeighted(gImage2, 1, 0.5, 0);
//gImage._EqualizeHist();
gImage = gImage.Resize(0.25, INTER.CV_INTER_NN);
gImage = gImage.SmoothBlur(11, 11);
gImage = gImage.ThresholdBinary(new Gray(para1), new Gray(255));
//gImage = gImage.ThresholdAdaptive(
// new Gray(255),
// Emgu.CV.CvEnum.ADAPTIVE_THRESHOLD_TYPE.CV_ADAPTIVE_THRESH_MEAN_C,
// Emgu.CV.CvEnum.THRESH.CV_THRESH_BINARY,
// para1,
// new Gray(para2)
//);
gImage = gImage.MorphologyEx(
new StructuringElementEx(
3,
(int)para2,
1,
(int)para2 / 2,
Emgu.CV.CvEnum.CV_ELEMENT_SHAPE.CV_SHAPE_ELLIPSE),
Emgu.CV.CvEnum.CV_MORPH_OP.CV_MOP_OPEN,
1);
gImage = gImage.Resize(4, INTER.CV_INTER_NN);
return gImage;
}