赞
踩
1、ROI概念与操作;
2、Mask概念与操作;
1、ROI 区域为感兴趣区域,一般为矩形区域,能够快速确定图像分析的重点,减少图像处理时间,提高精度;
2、使用Rectangle类表示矩形区域或用Range类设定行列范围;
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Emgu.CV; using Emgu.Util; using Emgu.CV.CvEnum; using Emgu.CV.Structure; using System.Drawing; namespace lesson11 { class Program { static void Main(string[] args) { Mat src = CvInvoke.Imread("c:/users/hello/desktop/picture/lena.tiff"); if(src.IsEmpty) { Console.WriteLine("could not load the image..."); return; } CvInvoke.Imshow("input image", src); //Mat ROI = new Mat(src, new Rectangle(229, 211, 132, 172)); //提取感兴趣区域(浅拷贝) //进行深拷贝,防止ROI区域修改原图像 Mat ROI = new Mat(src, new Range(211, 211 + 172), new Range(229, 229 + 132)).Clone(); CvInvoke.MedianBlur(ROI, ROI, 9); CvInvoke.Imshow("input image2", src); CvInvoke.Imshow("ROI image", ROI); Mat logo = CvInvoke.Imread("C:/users/hello/desktop/20.jpg"); Mat src1 = CvInvoke.Imread("c:/users/hello/desktop/picture/lena.tiff"); Mat ROI1 = new Mat(src1,new Rectangle(10, 10, logo.Width, logo.Height)); //设置感兴趣区域 logo.CopyTo(ROI1); CvInvoke.Imshow("change image", src1); CvInvoke.WaitKey(0); } } }
贴图与提取感兴趣区域:
1、mask掩膜是一个8位单通道图像(灰度图,二值图);掩膜矩阵为0的位置表示对原图像不进行操作、为1表示在此位置上进行操作;
2、掩膜可以作一些高级的图像融合操作;
/**************Mask掩码融合*******************/ //Mat img = CvInvoke.Imread("c:/users/hello/desktop/picture/lena.tiff"); //Mat logo = CvInvoke.Imread("c:/users/hello/desktop/20.jpg"); //Mat mask = new Mat(); //CvInvoke.CvtColor(logo, mask, ColorConversion.Bgr2Gray); //CvInvoke.BitwiseNot(mask, mask); //CvInvoke.Imshow("Bitwise not", mask); //CvInvoke.Threshold(mask, mask, 100, 255, ThresholdType.Binary); //非目标区像素值为0 //CvInvoke.Imshow("threshold image", mask); //Mat ROI = new Mat(img, new Rectangle(10, 10, logo.Width, logo.Height)); //logo.CopyTo(ROI, mask); //通过mask掩码提取特定的非0区域图像 //CvInvoke.Imshow("final result", img); //自定义掩码 //Mat src = CvInvoke.Imread("c:/users/hello/desktop/picture/2.jpg"); //Mat logo = CvInvoke.Imread("c:/users/hello/desktop/picture/lena.tiff"); //Mat mask = Mat.Zeros(logo.Rows,logo.Cols, DepthType.Cv8U, 1); //创建一个黑色图像 //CvInvoke.Circle(mask, new Point(298, 295), 100, new MCvScalar(255), -1);//绘制一个白色圆 //CvInvoke.Imshow("mask image", mask); //Mat ROI = new Mat(src, new Rectangle(10, 10,logo.Width,logo.Height)); //logo.CopyTo(ROI, mask); //CvInvoke.Imshow("final image", src); //加载图像作为掩码 Mat src = CvInvoke.Imread("c:/users/hello/desktop/picture/2.jpg"); Mat logo = CvInvoke.Imread("c:/users/hello/desktop/picture/lena.tiff"); Mat mask = CvInvoke.Imread("c:/users/hello/desktop/mask.jpg",ImreadModes.Grayscale); //掩膜必须是灰度图 CvInvoke.Threshold(mask, mask, 100, 255, ThresholdType.Binary); //阈值化处理一下 Mat ROI = new Mat(src, new Rectangle(20, 20, logo.Width, logo.Height)); logo.CopyTo(ROI,mask); CvInvoke.Imshow("final image", src); CvInvoke.WaitKey(0);
高级图像融合:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。