void GetImageData() { BitmapData SrcBmpData = SrcBmp.LockBits(new Rectangle(0, 0, SrcBmp.Width, SrcBmp.Height), ImageLockMode.ReadWrite, SrcBmp.PixelFormat); BitmapData DstBmpData = DstBmp.LockBits(new Rectangle(0, 0, DstBmp.Width, DstBmp.Height), ImageLockMode.ReadWrite, DstBmp.PixelFormat); int ImgWidth = SrcBmp.Width; int ImgHeight = SrcBmp.Height; int ImgStride = SrcBmpData.Stride; byte *Src = (byte *)SrcBmpData.Scan0; byte *Dest = (byte *)DstBmpData.Scan0; if (SrcBmpData.PixelFormat == PixelFormat.Format8bppIndexed) { SrcImg = new TMatrix(ImgWidth, ImgHeight, ImgStride, (int)IP_DEPTH.IP_DEPTH_8U, 1, Src); DestImg = new TMatrix(ImgWidth, ImgHeight, ImgStride, (int)IP_DEPTH.IP_DEPTH_8U, 1, Dest); } else if (SrcBmpData.PixelFormat == PixelFormat.Format24bppRgb) { SrcImg = new TMatrix(ImgWidth, ImgHeight, ImgStride, (int)IP_DEPTH.IP_DEPTH_8U, 3, Src); DestImg = new TMatrix(ImgWidth, ImgHeight, ImgStride, (int)IP_DEPTH.IP_DEPTH_8U, 3, Dest); } else if (SrcBmpData.PixelFormat == PixelFormat.Format32bppArgb && DstBmpData.PixelFormat == PixelFormat.Format32bppArgb) { SrcImg = new TMatrix(ImgWidth, ImgHeight, ImgStride, (int)IP_DEPTH.IP_DEPTH_8U, 4, Src); DestImg = new TMatrix(ImgWidth, ImgHeight, ImgStride, (int)IP_DEPTH.IP_DEPTH_8U, 4, Dest); } SrcBmp.UnlockBits(SrcBmpData); DstBmp.UnlockBits(DstBmpData); }
private void CmdProcess_Click(object sender, EventArgs e) { int Min_PosX = 0, Min_PosY = 0, Max_PosX = 0, Max_PosY = 0; BitmapData SrcBmpData = SrcBmp.LockBits(new Rectangle(0, 0, SrcBmp.Width, SrcBmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); BitmapData DstBmpData = DstBmp.LockBits(new Rectangle(0, 0, DstBmp.Width, DstBmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); Stopwatch Sw = new Stopwatch(); Sw.Start(); SrcImg = new TMatrix(SrcBmp.Width, SrcBmp.Height, SrcBmpData.Stride, (int)IP_DEPTH.IP_DEPTH_8U, 3, (byte *)SrcBmpData.Scan0); DestImg = new TMatrix(DstBmp.Width, DstBmp.Height, DstBmpData.Stride, (int)IP_DEPTH.IP_DEPTH_8U, 3, (byte *)DstBmpData.Scan0); TMatrix *Dest = null; MatchTemplate(ref DestImg, ref SrcImg, ref Dest); MinMaxLoc(ref *Dest, ref Min_PosX, ref Min_PosY, ref Max_PosX, ref Max_PosY); IP_FreeMatrix(&Dest); SrcBmp.UnlockBits(SrcBmpData); DstBmp.UnlockBits(DstBmpData); Pen P = new Pen(Color.Red); Graphics G = Graphics.FromImage(DstBmp); G.DrawRectangle(P, new Rectangle(Min_PosX, Min_PosY, SrcImg.Width, SrcImg.Height)); P.Dispose(); G.Dispose(); LblInfo.Text = "Image size: " + PicSrc.Image.Width.ToString() + " X " + PicSrc.Image.Height.ToString() + "\nAlgorithm processing time " + Sw.ElapsedMilliseconds.ToString() + " ms"; PicDest.Refresh(); }
void ShowResult() { BitmapData SrcBmpData = SrcBmp.LockBits(new Rectangle(0, 0, SrcBmp.Width, SrcBmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); BitmapData DstBmpData = DstBmp.LockBits(new Rectangle(0, 0, DstBmp.Width, DstBmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); SrcImg = new TMatrix(SrcBmp.Width, SrcBmp.Height, SrcBmpData.Stride, (int)IP_DEPTH.IP_DEPTH_8U, 3, (byte *)SrcBmpData.Scan0); DestImg = new TMatrix(SrcBmp.Width, SrcBmp.Height, SrcBmpData.Stride, (int)IP_DEPTH.IP_DEPTH_8U, 3, (byte *)DstBmpData.Scan0); Stopwatch Sw = new Stopwatch(); Sw.Start(); SelectiveBlur(ref SrcImg, ref DestImg, Radius.Value, Threshold.Value, EdgeMode.Tile); LblInfo.Text = "Image size: " + PicSrc.Image.Width.ToString() + " X " + PicSrc.Image.Height.ToString() + "\nAlgorithm processing time " + Sw.ElapsedMilliseconds.ToString() + " ms"; SrcBmp.UnlockBits(SrcBmpData); DstBmp.UnlockBits(DstBmpData); PicDest.Refresh(); }
private void CmdDeal_Click(object sender, EventArgs e) { BitmapData SrcBmpData = SrcBmp.LockBits(new Rectangle(0, 0, SrcBmp.Width, SrcBmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); BitmapData DstBmpData = DstBmp.LockBits(new Rectangle(0, 0, DstBmp.Width, DstBmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); Stopwatch Sw = new Stopwatch(); Sw.Start(); SrcImg = new TMatrix(SrcBmp.Width, SrcBmp.Height, SrcBmpData.Stride, (int)IP_DEPTH.IP_DEPTH_8U, 3, (byte *)SrcBmpData.Scan0); DestImg = new TMatrix(DstBmp.Width, DstBmp.Height, DstBmpData.Stride, (int)IP_DEPTH.IP_DEPTH_8U, 3, (byte *)DstBmpData.Scan0); ImageQuilting(ref SrcImg, ref DestImg, TileSize.Value, TileSize.Value, Overlap.Value, Overlap.Value); SrcBmp.UnlockBits(SrcBmpData); DstBmp.UnlockBits(DstBmpData); LblInfo.Text = "Image size: " + PicSrc.Image.Width.ToString() + " X " + PicSrc.Image.Height.ToString() + "\nAlgorithm processing time " + Sw.ElapsedMilliseconds.ToString() + " ms"; PicDest.Refresh(); }
private void CmdSave_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Bitmap files (*.Bitmap)|*.Bmp|Jpeg files (*.jpg)|*.jpg|Png files (*.png)|*.png"; saveFileDialog.FilterIndex = 3; saveFileDialog.RestoreDirectory = true; if (saveFileDialog.ShowDialog() == DialogResult.OK) { if (saveFileDialog.FilterIndex == 1) { DstBmp.Save(saveFileDialog.FileName, ImageFormat.Bmp); } else if (saveFileDialog.FilterIndex == 2) { DstBmp.Save(saveFileDialog.FileName, ImageFormat.Jpeg); } else if (saveFileDialog.FilterIndex == 3) { DstBmp.Save(saveFileDialog.FileName, ImageFormat.Png); } } }