圖像型態學是由一組型態學的代數運算子所組成的,它有四個基本的運算 :
- 膨脹 ( 或擴張 )
- 腐蝕 ( 或傾蝕 )
- 開啟
- 閉合
而數學型態的方法,是利用一個稱為結構元素的”探針”,收集圖像的信息,當探針在圖像中不斷移動時,便可考察圖像各個部分之間的互相關系,從而了解圖像的結構特徵。
腐蝕
腐蝕簡單的來說,就是一種消除邊界點的方法,使邊界向內收縮的過程,可以消除毫無意義的物體。
private void button3_Click(object sender, EventArgs e)
{
var op = new OpenFileDialog();
if (op.ShowDialog() == DialogResult.OK)
{
Mat scr = new Mat(op.FileName);
imageBox1.Image = scr;
Mat dst = new Mat();
Mat element = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Cross,
new Size(3, 3), new Point(-1, -1));
CvInvoke.Erode(scr, dst, element, new Point(-1, -1), 3,
Emgu.CV.CvEnum.BorderType.Default, new MCvScalar(0, 0, 0));
imageBox1.Image = scr;
imageBox2.Image = dst;
}
}
膨脹
膨脹是將物體接觸的所有背景點合併到該物體中,使邊界向內部擴張的過程,可以用來填補物體中的空洞。
private void button4_Click(object sender, EventArgs e)
{
var op = new OpenFileDialog();
if (op.ShowDialog() == DialogResult.OK)
{
Mat scr = new Mat(op.FileName);
imageBox1.Image = scr;
Mat dst = new Mat();
Mat element = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Cross,
new Size(3, 3), new Point(-1, -1));
CvInvoke.Dilate(scr, dst, element, new Point(-1, -1), 3,
Emgu.CV.CvEnum.BorderType.Default, new MCvScalar(0, 0, 0));
imageBox1.Image = scr;
imageBox2.Image = dst;
}
}
閉運算
先膨脹後腐蝕稱為閉(Close),即CLOSE(X) = E (D(X))
一般來說,閉運算能夠填平小孔,彌合小裂縫,而且位置和型狀不變。
private void button5_Click(object sender, EventArgs e)
{
// 先膨脹後腐蝕稱為 必(close) 即 CLOSE(X) = E(D(X))
var op = new OpenFileDialog();
if(op.ShowDialog() == DialogResult.OK)
{
Mat scr = new Mat(op.FileName);
Mat dst = new Mat();
Mat element = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Cross,
new Size(3, 3), new Point(-1, -1));
CvInvoke.MorphologyEx(scr, dst, Emgu.CV.CvEnum.MorphOp.Close, element,
new Point(-1, -1), 3, Emgu.CV.CvEnum.BorderType.Default, new MCvScalar(0, 0, 0));
imageBox1.Image = scr;
imageBox2.Image = dst;
}
}
高帽
原始圖像減去進行開操作的圖像 tophat(x) = x- open(x)
private void button6_Click(object sender, EventArgs e)
{
// 原始圖像減去進行開操作的圖像
var op = new OpenFileDialog();
if (op.ShowDialog() == DialogResult.OK)
{
Mat scr = new Mat(op.FileName);
Mat dst = new Mat();
Mat element = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Cross,
new Size(3, 3), new Point(-1, -1));
CvInvoke.MorphologyEx(scr, dst, Emgu.CV.CvEnum.MorphOp.Tophat,
element, new Point(-1, -1), 3, Emgu.CV.CvEnum.BorderType.Default, new MCvScalar(0, 0, 0));
imageBox1.Image = scr;
imageBox2.Image = dst;
}
}
低帽
進行閉操作的圖像減去原始圖像,Balckhat(x) = close (x)-x
應為產生的效果是圖片大部分面積都是偏黑色的。
private void button7_Click(object sender, EventArgs e)
{
var op = new OpenFileDialog();
if(op.ShowDialog() == DialogResult.OK)
{
Mat scr = new Mat(op.FileName);
Mat dst = new Mat();
Mat element = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Cross,
new Size(3, 3), new Point(-1, -1));
CvInvoke.MorphologyEx(scr, dst, Emgu.CV.CvEnum.MorphOp.Blackhat, element,
new Point(-1, -1), 3, Emgu.CV.CvEnum.BorderType.Default, new MCvScalar(0, 0, 0));
imageBox1.Image = scr;
imageBox2.Image = dst;
}
}
留言列表