public static double callSobel() { DateTime t1 = DateTime.Now, t2 = t1; if (ImageShow.nowFile != null) { ImageShow.source = new Bitmap(ImageShow.nowFile); Rectangle rect = new Rectangle(0, 0, ImageShow.source.Width, ImageShow.source.Height); System.Drawing.Imaging.BitmapData bmpData = ImageShow.source.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, ImageShow.source.PixelFormat); IntPtr ptr = bmpData.Scan0; int bytes = Math.Abs(bmpData.Stride) * ImageShow.source.Height; byte[] rgbValues = new byte[bytes]; System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes); if (sobelOTSU) { sobelThr = -1; } int[] edgeX = new int[bytes]; int[] edgeY = new int[bytes]; int edgeNum = 0; t1 = DateTime.Now; sobel(ImageShow.source.Width, ImageShow.source.Height, bytes, rgbValues, sobelKsize, ref sobelThr, ref edgeNum, edgeX, edgeY); t2 = DateTime.Now; while (ImageShow.edgeDots != null && ImageShow.edgeDots.Count > 0) { ImageShow.edgeDots.RemoveAt(ImageShow.edgeDots.Count - 1); } for (int i = 0; i < edgeNum; i++) { ImageShow.addDot(new Point(edgeX[i], edgeY[i])); } ImageShow.source.UnlockBits(bmpData); } return((t2 - t1).TotalMilliseconds); }
public static void callTemplateFinetune() { if (ImageShow.nowFile != null) { ImageShow.source = new Bitmap(ImageShow.nowFile); Rectangle rect = new Rectangle(0, 0, ImageShow.source.Width, ImageShow.source.Height); System.Drawing.Imaging.BitmapData bmpData = ImageShow.source.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, ImageShow.source.PixelFormat); IntPtr ptr = bmpData.Scan0; int bytes = Math.Abs(bmpData.Stride) * ImageShow.source.Height; byte[] rgbValues = new byte[bytes]; System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes); byte[] data = new byte[templateROI.Width * (bmpData.Stride / bmpData.Width) * templateROI.Height]; for (int i = 0; i < templateROI.Height; i++) { for (int j = 0; j < templateROI.Width * (bmpData.Stride / bmpData.Width); j++) { data[i * templateROI.Width * (bmpData.Stride / bmpData.Width) + j] = rgbValues[(i + templateROI.Y) * bmpData.Stride + j + templateROI.X * (bmpData.Stride / bmpData.Width)]; } } int edgeNum = templateROI.Width * templateROI.Height; int[] edgeX = new int[edgeNum]; int[] edgeY = new int[edgeNum]; templateFinetune(templateROI.Width, templateROI.Height, templateROI.Height * templateROI.Width * (bmpData.Stride / bmpData.Width), data, thr, ref edgeNum, edgeX, edgeY); ImageShow.edgeDots.Clear(); for (int i = 0; i < edgeNum; i++) { ImageShow.addDot(new Point(edgeX[i] + templateROI.X, edgeY[i] + templateROI.Y)); } ImageShow.source.UnlockBits(bmpData); } }
public static double newEdgeDetectFun() { DateTime t1 = DateTime.Now, t2 = t1; int imgSize = ImageShow.source.Width * ImageShow.source.Height; byte[] data = new byte[imgSize]; t1 = DateTime.Now; newEdgeDetect(ImageShow.nowFile, edgeDetectStep, edgeDetectThr, imgSize, data); t2 = DateTime.Now; for (int i = 0; i < imgSize; i++) { if (data[i] == 254) { ImageShow.addDot(new Point(i % ImageShow.source.Width, i / ImageShow.source.Width)); } } return((t2 - t1).TotalMilliseconds); }