// // this is just too easy... // public bool applySobelEdgeFilter() { if (currentImage != null) { try { // create filter SobelEdgeDetector filter = new SobelEdgeDetector(); // apply the filter filter.ApplyInPlace(currentImage); return true; } catch (Exception e) { Console.WriteLine(e.StackTrace); } } return false; }
public bool applySobelEdgeFilter() { if (currentImage != null) { try { // create filter SobelEdgeDetector filter = new SobelEdgeDetector(); // apply the filter filter.ApplyInPlace(currentImage); return true; } catch (Exception) { } } return false; }
public static IEnumerable<MagicCard> DetectCardArt(Bitmap cameraBitmap) { var ret = new List<MagicCard>(); var filteredBitmap = Grayscale.CommonAlgorithms.BT709.Apply(cameraBitmap); // edge filter var edgeFilter = new SobelEdgeDetector(); edgeFilter.ApplyInPlace(filteredBitmap); // Threshhold filter var threshholdFilter = new Threshold(190); threshholdFilter.ApplyInPlace(filteredBitmap); var bitmapData = filteredBitmap.LockBits( new Rectangle(0, 0, filteredBitmap.Width, filteredBitmap.Height), ImageLockMode.ReadWrite, filteredBitmap.PixelFormat); var blobCounter = new BlobCounter(); blobCounter.FilterBlobs = true; blobCounter.MinHeight = 125; blobCounter.MinWidth = 125; blobCounter.ProcessImage(bitmapData); var blobs = blobCounter.GetObjectsInformation(); filteredBitmap.UnlockBits(bitmapData); var shapeChecker = new SimpleShapeChecker(); var bm = new Bitmap(filteredBitmap.Width, filteredBitmap.Height, PixelFormat.Format24bppRgb); var cardPositions = new List<IntPoint>(); foreach (var blob in blobs) { var edgePoints = blobCounter.GetBlobsEdgePoints(blob); List<IntPoint> corners; // only operate on 4 sided polygons if (shapeChecker.IsConvexPolygon(edgePoints, out corners)) { var subtype = shapeChecker.CheckPolygonSubType(corners); if (corners.Count() != 4) continue; if (subtype != PolygonSubType.Parallelogram && subtype != PolygonSubType.Rectangle) continue; // if the image is sideways, rotate it so it'll match the DB card art corners = Utilities.RotateCorners(corners).ToList(); if (Utilities.GetArea(corners) < 20000) continue; ret.Add( new MagicCard(cameraBitmap, corners)); } } return ret; }
// ========================================================= private void Edge_detectFunc(ref Bitmap frame, int par_int, double par_d, int par_R, int par_G, int par_B) { frame = Grayscale.CommonAlgorithms.RMY.Apply(frame); // Make gray switch (par_int) { case 1: SobelEdgeDetector SobelFilter = new SobelEdgeDetector(); SobelFilter.ApplyInPlace(frame); break; case 2: DifferenceEdgeDetector DifferenceFilter = new DifferenceEdgeDetector(); DifferenceFilter.ApplyInPlace(frame); break; case 3: HomogenityEdgeDetector HomogenityFilter = new HomogenityEdgeDetector(); HomogenityFilter.ApplyInPlace(frame); break; case 4: CannyEdgeDetector Cannyfilter = new CannyEdgeDetector(); // apply the MirrFilter Cannyfilter.ApplyInPlace(frame); break; default: HomogenityEdgeDetector filter = new HomogenityEdgeDetector(); filter.ApplyInPlace(frame); break; } GrayscaleToRGB RGBfilter = new GrayscaleToRGB(); // back to color format frame = RGBfilter.Apply(frame); }
// Process image private void ProcessImage(Bitmap bitmap) { // create filter HistogramEqualization hisFilter = new HistogramEqualization(); // process image //hisFilter.ApplyInPlace(Image); // create filter ContrastCorrection contrastFilter = new ContrastCorrection(4); // apply the filter contrastFilter.ApplyInPlace(bitmap); //QuantizeImage(bitmap); Grayscale grayscaleFilter = new Grayscale(0.33, 0.33, 0.34); // apply the filter Bitmap grayImage = grayscaleFilter.Apply(bitmap); // create filter SobelEdgeDetector sobelFilter = new SobelEdgeDetector(); // apply the filter sobelFilter.ApplyInPlace(grayImage); Threshold filter = new Threshold(110); // apply the filter filter.ApplyInPlace(grayImage); if (GetIntersect(grayImage, bitmap, intersectPoint)) { //MessageBox.Show("draw"); Graphics g = Graphics.FromImage(bitmap); //Sorting for (int i = 0; i < 19; i++) { for (int j = 0; j < 19; j++) { for (int k = 0; k < 19 - 1; k++) { if (Math.Abs(intersectPoint[1, i, k]) > Math.Abs(intersectPoint[1, i, k + 1])) { int tempX = Math.Abs(intersectPoint[0, i, k]); int tempY = Math.Abs(intersectPoint[1, i, k]); intersectPoint[0, i, k] = Math.Abs(intersectPoint[0, i, k + 1]); intersectPoint[1, i, k] = Math.Abs(intersectPoint[1, i, k + 1]); intersectPoint[0, i, k + 1] = tempX; intersectPoint[1, i, k + 1] = tempY; //MessageBox.Show(i + " " + k +" " +tempX + " " + tempY + " " + intersectPoint[0, i, k] + " " + intersectPoint[1, i, k] ,"ok", MessageBoxButtons.OK); } } } } for (int i = 0; i < 19; i++) { for (int j = 0; j < 19; j++) { for (int k = 0; k < 19 - 1; k++) { if (Math.Abs(intersectPoint[0, k, i]) > Math.Abs(intersectPoint[0, k + 1, i])) { int tempX = Math.Abs(intersectPoint[0, k, i]); int tempY = Math.Abs(intersectPoint[1, k, i]); intersectPoint[0, k, i] = intersectPoint[0, k + 1, i]; intersectPoint[1, k, i] = intersectPoint[1, k + 1, i]; intersectPoint[0, k + 1, i] = tempX; intersectPoint[1, k + 1, i] = tempY; } } } } Pen redPen = new Pen(Color.Red, 4); for (int i = 0; i < 19; i++) { for (int j = 0; j < 19; j++) { g.DrawEllipse(redPen, Math.Abs(intersectPoint[0, i, j]) , Math.Abs(intersectPoint[1, i, j]) , (int)5, (int)5); //g.DrawEllipse(redPen, 0, 0, (int)5, (int)5); //Debug.WriteLine((Math.Abs(intersectPoint[0, i, j]) - 2) + " " + (Math.Abs(intersectPoint[1, i, j]) - 2)); } } Pen greenPen = new Pen(Color.Green, 4); greenPen.Dispose(); redPen.Dispose(); g.Dispose(); // Initializes the variables to pass to the MessageBox.Show method. EspacioCamera.Image = bitmap; string message = "Do you accecpt this detection?"; string caption = "The system found totally 38 lines."; MessageBoxButtons buttons = MessageBoxButtons.YesNo; DialogResult result; // Displays the MessageBox. result = MessageBox.Show(message, caption, buttons); if (result == System.Windows.Forms.DialogResult.Yes) { // Closes the parent form. locked = true; } } EspacioCamera.Image = bitmap; }
private void detectQuads(Bitmap bitmap) { // Greyscale filteredBitmap = Grayscale.CommonAlgorithms.BT709.Apply(bitmap); // edge filter SobelEdgeDetector edgeFilter = new SobelEdgeDetector(); edgeFilter.ApplyInPlace(filteredBitmap); // Threshhold filter Threshold threshholdFilter = new Threshold(190); threshholdFilter.ApplyInPlace(filteredBitmap); BitmapData bitmapData = filteredBitmap.LockBits( new Rectangle(0, 0, filteredBitmap.Width, filteredBitmap.Height), ImageLockMode.ReadWrite, filteredBitmap.PixelFormat); BlobCounter blobCounter = new BlobCounter(); blobCounter.FilterBlobs = true; blobCounter.MinHeight = 125; blobCounter.MinWidth = 125; blobCounter.ProcessImage(bitmapData); Blob[] blobs = blobCounter.GetObjectsInformation(); filteredBitmap.UnlockBits(bitmapData); SimpleShapeChecker shapeChecker = new SimpleShapeChecker(); Bitmap bm = new Bitmap(filteredBitmap.Width, filteredBitmap.Height, PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(bm); g.DrawImage(filteredBitmap, 0, 0); Pen pen = new Pen(Color.Red, 5); List<IntPoint> cardPositions = new List<IntPoint>(); // Loop through detected shapes for (int i = 0, n = blobs.Length; i < n; i++) { List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blobs[i]); List<IntPoint> corners; bool sameCard = false; // is triangle or quadrilateral if (shapeChecker.IsConvexPolygon(edgePoints, out corners)) { // get sub-type PolygonSubType subType = shapeChecker.CheckPolygonSubType(corners); // Only return 4 corner rectanges if ((subType == PolygonSubType.Parallelogram || subType == PolygonSubType.Rectangle) && corners.Count == 4) { // Check if its sideways, if so rearrange the corners so it's veritcal rearrangeCorners(corners); // Prevent it from detecting the same card twice foreach (IntPoint point in cardPositions) { if (corners[0].DistanceTo(point) < 40) sameCard = true; } if (sameCard) continue; // Hack to prevent it from detecting smaller sections of the card instead of the whole card if (GetArea(corners) < 20000) continue; cardPositions.Add(corners[0]); g.DrawPolygon(pen, ToPointsArray(corners)); // Extract the card bitmap QuadrilateralTransformation transformFilter = new QuadrilateralTransformation(corners, 211, 298); cardBitmap = transformFilter.Apply(cameraBitmap); List<IntPoint> artCorners = new List<IntPoint>(); artCorners.Add(new IntPoint(14, 35)); artCorners.Add(new IntPoint(193, 35)); artCorners.Add(new IntPoint(193, 168)); artCorners.Add(new IntPoint(14, 168)); // Extract the art bitmap QuadrilateralTransformation cartArtFilter = new QuadrilateralTransformation(artCorners, 183, 133); cardArtBitmap = cartArtFilter.Apply(cardBitmap); MagicCard card = new MagicCard(); card.corners = corners; card.cardBitmap = cardBitmap; card.cardArtBitmap = cardArtBitmap; magicCards.Add(card); } } } pen.Dispose(); g.Dispose(); filteredBitmap = bm; }
public void DetectQuads() { // Greyscale FilteredBitmap = Grayscale.CommonAlgorithms.BT709.Apply(CameraBitmap); // edge filter var edgeFilter = new SobelEdgeDetector(); edgeFilter.ApplyInPlace(FilteredBitmap); // Threshhold filter var threshholdFilter = new Threshold(190); threshholdFilter.ApplyInPlace(FilteredBitmap); var bitmapData = FilteredBitmap.LockBits( new Rectangle(0, 0, FilteredBitmap.Width, FilteredBitmap.Height), ImageLockMode.ReadWrite, FilteredBitmap.PixelFormat); var blobCounter = new BlobCounter { FilterBlobs = true, MinHeight = 125, MinWidth = 125 }; blobCounter.ProcessImage(bitmapData); var blobs = blobCounter.GetObjectsInformation(); FilteredBitmap.UnlockBits(bitmapData); var shapeChecker = new SimpleShapeChecker(); var bm = new Bitmap(FilteredBitmap.Width, FilteredBitmap.Height, PixelFormat.Format24bppRgb); var g = Graphics.FromImage(bm); g.DrawImage(FilteredBitmap, 0, 0); var pen = new Pen((Color)new ColorConverter().ConvertFromString(Application.Current.Resources["AccentColor"].ToString()), 5); var cardPositions = new List<IntPoint>(); // Loop through detected shapes for (int i = 0, n = blobs.Length; i < n; i++) { var edgePoints = blobCounter.GetBlobsEdgePoints(blobs[i]); List<IntPoint> corners; var sameCard = false; // is triangle or quadrilateral if (shapeChecker.IsQuadrilateral(edgePoints, out corners)) { if (!corners.Any()) return; // get sub-type var subType = shapeChecker.CheckPolygonSubType(corners); // Only return 4 corner rectanges if ((subType != PolygonSubType.Parallelogram && subType != PolygonSubType.Rectangle) || corners.Count != 4) continue; // Check if its sideways, if so rearrange the corners so it's veritcal RearrangeCorners(corners); // Prevent it from detecting the same card twice foreach (var point in cardPositions) { var distance = corners[0].DistanceTo(point); if (corners[0].DistanceTo(point) < 40) sameCard = true; } if (sameCard) continue; // Hack to prevent it from detecting smaller sections of the card instead of the whole card var area = GetArea(corners); if (area < 20000)// || area > 35000) continue; cardPositions.Add(corners[0]); g.DrawPolygon(pen, ToPointsArray(corners)); // Extract the card bitmap var transformFilter = new QuadrilateralTransformation(corners, 225, 325); CardBitmap = transformFilter.Apply(CameraBitmap); TmpCard = new MagicCard { Corners = corners, CardBitmap = CardBitmap }; } } pen.Dispose(); g.Dispose(); FilteredBitmap = bm; }
private void TakeSnapshot_funct(Bitmap img) { Bitmap image = Grayscale.CommonAlgorithms.RMY.Apply(img); // find edges SobelEdgeDetector EdgeFilter = new SobelEdgeDetector(); EdgeFilter.ApplyInPlace(image); // back to color format GrayscaleToRGB RGBfilter = new GrayscaleToRGB(); image = RGBfilter.Apply(image); // get rid of grays EuclideanColorFiltering filter = new EuclideanColorFiltering(); filter.CenterColor.Red = 20; filter.CenterColor.Green = 20; filter.CenterColor.Blue = 20; filter.FillOutside = false; filter.Radius = 200; filter.ApplyInPlace(image); Color peek; for (int y = 0; y < image.Height; y++) { for (int x = 0; x < image.Width; x++) { peek = image.GetPixel(x, y); if (peek.R != 0) { image.SetPixel(x, y, Color.Blue); } } } image.MakeTransparent(Color.Black); SnapshotImage = image; SnapshotOriginalImage = image; }
// Process image private void ProcessImage( Bitmap bitmap ) { Grayscale grayscaleFilter = new Grayscale(0.33, 0.33, 0.34); // apply the filter Bitmap grayImage = grayscaleFilter.Apply(bitmap); //Get Histogram /*int[] histogram = new int[256]; for (int i = 0; i < 256; i++) { histogram[i] = 0; } for (int i = 0; i < grayImage.Width; i++ ) { for (int j = 0; j < grayImage.Height; j++) { histogram[(Convert.ToInt32(grayImage.GetPixel(i, j).R.ToString()) + Convert.ToInt32(grayImage.GetPixel(i, j).G.ToString()) + Convert.ToInt32(grayImage.GetPixel(i, j).B.ToString()))/3] +=1; } }*/ //create filter SobelEdgeDetector sobelFilter = new SobelEdgeDetector(); // apply the filter sobelFilter.ApplyInPlace(grayImage); Threshold filter = new Threshold(243); // apply the filter filter.ApplyInPlace(grayImage); HoughLineTransformation lineTransform = new HoughLineTransformation(); lineTransform.ProcessImage(grayImage); Bitmap houghLineImage = lineTransform.ToBitmap(); // get lines using relative intensity HoughLine[] lines = lineTransform.GetLinesByRelativeIntensity(0.5); BitmapData bitmapData = bitmap.LockBits( new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat); BitmapData grayImageData = grayImage.LockBits( new Rectangle(0, 0, grayImage.Width, grayImage.Height), ImageLockMode.ReadWrite, grayImage.PixelFormat); UnmanagedImage unmanagedImage = new UnmanagedImage(bitmapData); int w2 = 0, h2 = 0; int vertical = 0; int horizons = 0; int testColor = 0; Color color = Color.Black; foreach (HoughLine line in lines) { String temp = line.Theta.ToString(); //MessageBox.Show(temp, "ok", MessageBoxButtons.OK); // get line's radius and theta values int r = line.Radius; double t = line.Theta; // check if line is in lower part of the image if (r < 0) { t += 180; r = -r; } // convert degrees to radians t = (t / 180) * Math.PI; // get image centers (all coordinate are measured relative // to center) w2 = grayImage.Width / 2; h2 = grayImage.Height / 2; double x0 = 0, x1 = 0, y0 = 0, y1 = 0; if (line.Theta != 0) { // horizontal // none-vertical line if (line.Theta > 0 && line.Theta < 10 || line.Theta > 170) { x0 = -w2; // most left point x1 = w2; // most right point y0 = (-Math.Cos(t) * x0 + r) / Math.Sin(t); y1 = (-Math.Cos(t) * x1 + r) / Math.Sin(t); color = Color.Red; Drawing.Line(bitmapData, new IntPoint((int)x0 + w2, h2 - (int)y0), new IntPoint((int)x1 + w2, h2 - (int)y1), color); Drawing.Line(grayImageData, new IntPoint((int)x0 + w2, h2 - (int)y0), new IntPoint((int)x1 + w2, h2 - (int)y1), color); } if (line.Theta > 80 && line.Theta < 100) { x0 = -w2; // most left point x1 = w2; // most right point y0 = (-Math.Cos(t) * x0 + r) / Math.Sin(t); y1 = (-Math.Cos(t) * x1 + r) / Math.Sin(t); Drawing.Line(bitmapData, new IntPoint((int)x0 + w2, h2 - (int)y0), new IntPoint((int)x1 + w2, h2 - (int)y1), Color.Blue); Drawing.Line(grayImageData, new IntPoint((int)x0 + w2, h2 - (int)y0), new IntPoint((int)x1 + w2, h2 - (int)y1), Color.Blue); } } else { // vertical line x0 = line.Radius; x1 = line.Radius; y0 = h2; y1 = -h2; color = Color.Red; Drawing.Line(bitmapData, new IntPoint((int)x0 + w2, h2 - (int)y0), new IntPoint((int)x1 + w2, h2 - (int)y1), color); Drawing.Line(grayImageData, new IntPoint((int)x0 + w2, h2 - (int)y0), new IntPoint((int)x1 + w2, h2 - (int)y1), color); } } bitmap.UnlockBits(bitmapData); grayImage.UnlockBits(grayImageData); MessageBox.Show(lines.Length+"", "ok", MessageBoxButtons.OK); // put new image to clipboard Clipboard.SetDataObject(bitmap); // and to picture box pictureBox.Image = bitmap; UpdatePictureBoxPosition(); }
// ========================================================= private void Edge_detectFunc(ref Bitmap frame, int par_int) { frame = Grayscale.CommonAlgorithms.RMY.Apply(frame); // Make gray switch (par_int) { case 1: SobelEdgeDetector SobelFilter = new SobelEdgeDetector(); SobelFilter.ApplyInPlace(frame); break; case 2: DifferenceEdgeDetector DifferenceFilter = new DifferenceEdgeDetector(); DifferenceFilter.ApplyInPlace(frame); break; case 3: HomogenityEdgeDetector HomogenityFilter = new HomogenityEdgeDetector(); HomogenityFilter.ApplyInPlace(frame); break; case 4: // can we not have references to canny in the code. gives me ptsd flashbacks CannyEdgeDetector Nightmare = new CannyEdgeDetector(); // apply the filter Nightmare.ApplyInPlace(frame); break; default: HomogenityEdgeDetector filter = new HomogenityEdgeDetector(); filter.ApplyInPlace(frame); break; } GrayscaleToRGB RGBfilter = new GrayscaleToRGB(); // back to color format frame = RGBfilter.Apply(frame); }
// Process image private void ProcessImage( Bitmap bitmap ) { //QuantizeImage(bitmap); Grayscale grayscaleFilter = new Grayscale(0.33, 0.33, 0.34); // apply the filter Bitmap grayImage = grayscaleFilter.Apply(bitmap); // create filter SobelEdgeDetector sobelFilter = new SobelEdgeDetector(); // apply the filter sobelFilter.ApplyInPlace(grayImage); Threshold filter = new Threshold(243); // apply the filter filter.ApplyInPlace(grayImage); int[,,] intersectPoint = new int[2,19,19]; GetIntersect(grayImage,bitmap,intersectPoint); Graphics g = Graphics.FromImage(bitmap); //Sorting /*int[,] top19 = new int[19, 2]; int[,] left19 = new int[19, 2]; int[,] bot19 = new int[19, 2]; int[,] right19 = new int[19, 2]; int lowest = 9999999; int lowX = 0; int lowY = 0; for (int i = 0; i < 19; i++) { for (int j = 0; j < 19; j++) { if (intersectPoint[0, i, j] + intersectPoint[1, i, j] < lowest) { lowest = intersectPoint[0, i, j] + intersectPoint[1, i, j]; lowX = Math.Abs(intersectPoint[0, i, j]); lowY = Math.Abs(intersectPoint[1, i, j]); } } } */ for (int i = 0; i < 19; i++) { for (int j = 0; j < 19; j++) { for (int k = 0; k < 19 - 1; k++) { if(Math.Abs(intersectPoint[1,i,k]) > Math.Abs(intersectPoint[1,i,k+1])){ int tempX = Math.Abs(intersectPoint[0,i,k]); int tempY = Math.Abs(intersectPoint[1,i,k]); intersectPoint[0,i,k] = Math.Abs(intersectPoint[0,i,k+1]); intersectPoint[1,i,k] = Math.Abs(intersectPoint[1,i,k+1]); intersectPoint[0,i,k+1] = tempX; intersectPoint[1,i,k+1] = tempY; //MessageBox.Show(i + " " + k +" " +tempX + " " + tempY + " " + intersectPoint[0, i, k] + " " + intersectPoint[1, i, k] ,"ok", MessageBoxButtons.OK); } } } } for (int i = 0; i < 19; i++) { for (int j = 0; j < 19; j++) { for (int k = 0; k < 19 - 1; k++) { if(Math.Abs(intersectPoint[0,k,i]) > Math.Abs(intersectPoint[0,k+1,i])){ int tempX = Math.Abs(intersectPoint[0,k,i]); int tempY = Math.Abs(intersectPoint[1,k,i]); intersectPoint[0,k,i] = intersectPoint[0,k+1,i]; intersectPoint[1,k,i] = intersectPoint[1,k+1,i]; intersectPoint[0,k+1,i] = tempX; intersectPoint[1,k+1,i] = tempY; } } } } Pen redPen = new Pen(Color.Red, 4); for (int i = 0; i < 19; i++) { for (int j = 0; j < 5; j++) { g.DrawEllipse(redPen, Math.Abs(intersectPoint[0, i, j]) - 2, Math.Abs(intersectPoint[1, i, j]) - 2, (int)5, (int)5); //g.DrawEllipse(redPen, 0, 0, (int)5, (int)5); } } Pen greenPen = new Pen(Color.Green, 4); greenPen.Dispose(); redPen.Dispose(); g.Dispose(); /*HoughLineTransformation lineTransform = new HoughLineTransformation(); lineTransform.ProcessImage(grayImage); Bitmap houghLineImage = lineTransform.ToBitmap(); // get lines using relative intensity HoughLine[] lines = lineTransform.GetLinesByRelativeIntensity(0.5); BitmapData bitmapData = bitmap.LockBits( new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat); BitmapData grayImageData = grayImage.LockBits( new Rectangle(0, 0, grayImage.Width, grayImage.Height), ImageLockMode.ReadWrite, grayImage.PixelFormat); UnmanagedImage unmanagedImage = new UnmanagedImage(bitmapData); int w2 = 0, h2 = 0; Color color = Color.Black; foreach (HoughLine line in lines) { String temp = line.Theta.ToString(); //MessageBox.Show(temp, "ok", MessageBoxButtons.OK); // get line's radius and theta values int r = line.Radius; double t = line.Theta; // check if line is in lower part of the image if (r < 0) { t += 180; r = -r; } // convert degrees to radians t = (t / 180) * Math.PI; // get image centers (all coordinate are measured relative // to center) w2 = grayImage.Width / 2; h2 = grayImage.Height / 2; double x0 = 0, x1 = 0, y0 = 0, y1 = 0; if (line.Theta != 0) { // horizontal // none-vertical line if (line.Theta > 0 && line.Theta < 10 || line.Theta > 170) { x0 = -w2; // most left point x1 = w2; // most right point y0 = (-Math.Cos(t) * x0 + r) / Math.Sin(t); y1 = (-Math.Cos(t) * x1 + r) / Math.Sin(t); color = Color.Red; Drawing.Line(bitmapData, new IntPoint((int)x0 + w2, h2 - (int)y0), new IntPoint((int)x1 + w2, h2 - (int)y1), color); Drawing.Line(grayImageData, new IntPoint((int)x0 + w2, h2 - (int)y0), new IntPoint((int)x1 + w2, h2 - (int)y1), color); } if (line.Theta > 80 && line.Theta < 100) { x0 = -w2; // most left point x1 = w2; // most right point y0 = (-Math.Cos(t) * x0 + r) / Math.Sin(t); y1 = (-Math.Cos(t) * x1 + r) / Math.Sin(t); Drawing.Line(bitmapData, new IntPoint((int)x0 + w2, h2 - (int)y0), new IntPoint((int)x1 + w2, h2 - (int)y1), Color.Blue); Drawing.Line(grayImageData, new IntPoint((int)x0 + w2, h2 - (int)y0), new IntPoint((int)x1 + w2, h2 - (int)y1), Color.Blue); } } else { // vertical line x0 = line.Radius; x1 = line.Radius; y0 = h2; y1 = -h2; color = Color.Red; Drawing.Line(bitmapData, new IntPoint((int)x0 + w2, h2 - (int)y0), new IntPoint((int)x1 + w2, h2 - (int)y1), color); Drawing.Line(grayImageData, new IntPoint((int)x0 + w2, h2 - (int)y0), new IntPoint((int)x1 + w2, h2 - (int)y1), color); } } bitmap.UnlockBits(bitmapData); grayImage.UnlockBits(grayImageData); MessageBox.Show(lines.Length+"", "ok", MessageBoxButtons.OK); */ Clipboard.SetDataObject(bitmap); // and to picture box pictureBox.Image = bitmap; UpdatePictureBoxPosition(); }