EmguCV二进制图像!!!!!!!!!!!! [英] EmguCV binary image!!!!!!!!!!!!
问题描述
如何使用EmguCV制作黑白图像
从彩色图像还是灰色图像?
How to use EmguCV to make Black and White image
from colored or gray image ?
推荐答案
您提出了类似的问题,但是如果您想这样做,则是相反的做法,请让我知道,我可以提供帮助.无论如何,要在EMGU中对二进制图像进行阈值处理,您都可以简单地使用.ThresholdBinary语法.
对于灰度图像,这很简单:
Hi,
You asked a similar question however it was the opposite way round if you want to do this let me know and I can help. Anyway to threshold to a binary image in EMGU you can simply use .ThresholdBinary syntax.
For a grayscale image this is simple:
OpenFileDialog open = new OpenFileDialog();
open.Filter = "Image Files (*.tif; *.dcm; *.jpg; *.jpeg; *.bmp)|*.tif; *.dcm; *.jpg; *.jpeg; *.bmp";
int threshold_value = 50; //0-255
if (open.ShowDialog() == DialogResult.OK)
{
Image<Gray,Byte> img = new Image<Gray,Byte>(open.FileName);
pictureBox1.Image = img.ToBitmap(); //Display if you want
img = img.ThresholdBinary(new Gray(threshold_value), new Gray(255));
pictureBox2.Image = img .ToBitmap(); //display results in different picturebox
}
如果您希望保留原始图像,可以随时执行以下操作
You can always do the following if you wish to keep the original image
Image<Gray,Byte> Binary_Image = img.ThresholdBinary(new Gray(threshold_value), new Gray(255));
如果您想稍微玩些东西,可以在表单中添加一个轨迹栏,将最小值设置为0,将最大值设置为255,然后使用此代码.
If you want to play with things a little you can add a trackbar to your form put the minimum to 0 and maximum to 255 and use this code.
private void trackBar1_Scroll(object sender, EventArgs e)
{
int trackbar = trackBar1.Value;
label1.Text = trackbar.ToString(); //use a label to display trackbar value
if (img != null)
{
using (Image<Gray,Byte> Gray = img.ThresholdBinary(new Gray(trackbar), new Gray(255)))
{
pictureBox2.Image = Gray.ToBitmap();
}
}
}
尽管从技术上讲这不是二进制图像,而是1或0,但会产生预期的黑白效果.
对于彩色图像,情况有所不同:
Although this is not technically a binary image as that would be 1 or 0 it will produce the expected black and white effect.
For a colour image things are a little different:
OpenFileDialog open = new OpenFileDialog();
open.Filter = "Image Files (*.tif; *.dcm; *.jpg; *.jpeg; *.bmp)|*.tif; *.dcm; *.jpg; *.jpeg; *.bmp";
int Blue_threshold = 50; //0-255
int Green_threshold = 50; //0-255
int Red_threshold = 50; //0-255
if (open.ShowDialog() == DialogResult.OK)
{
Image<bgr,Byte> img_colour = new Image<bgr,Byte>(open.FileName);
pictureBox1.Image = img_colour.ToBitmap(); //Display if you want
img_colour = img_colour.ThresholdBinary(new Bgr(Blue_threshold, Green_threshold, Red_threshold), new Bgr(255, 255, 255));
pictureBox2.Image = img_colour.ToBitmap();//display results in different picturebox
}
希望这对您有所帮助,
干杯,
克里斯
I hope this helps you out if you need any help feel free to ask,
Cheers,
Chris
尝试一下 [^ ]
这篇关于EmguCV二进制图像!!!!!!!!!!!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!