private void openImageToolStripMenuItem_Click(object sender, EventArgs e) { if (openFileDialogImage.ShowDialog() == DialogResult.OK) { string nameOfFile = openFileDialogImage.FileName; try { bitmap = new Bitmap(nameOfFile); imProcessing = new Processing(new Bitmap(nameOfFile)); initialisePlan(bitmap.Width, bitmap.Height); pictureBoxMainImage.Image = bitmap; contourFlag = false; movingEditFlag = false; buttonRectangularSelection.Enabled = true; buttonDrawContour.Enabled = false; buttonColoring.Enabled = false; buttonSelectBrightness.Enabled = false; buttonZoomOutImage.Enabled = false; buttonZoomInImage.Enabled = false; listBoxPercentage.Items.Clear(); labelHistogramOfCurrentImage.Visible = true; panelHistogrammOfCurrentImage.Visible = true; labelHistogramOfSelectedFragment.Visible = false; panelHistogramOfSelectedFragment.Visible = false; labelPercentage.Visible = false; listBoxPercentage.Visible = false; paintHistogram(Coloring.calculateHistogram(bitmap), Coloring.calculateMaxHistogramValue(Coloring.calculateHistogram(bitmap)), pictureBoxCurrentImageHistogram, histMainBitmap); pictureBoxCurrentImageHistogram.Invalidate(); } catch (Exception exc) { imName = ""; } imName = openFileDialogImage.FileName; } }
private void pictureBoxMainImage_MouseUp(object sender, MouseEventArgs e) { if (extractionFlag) { if ((e.X < bitmap.Width) && (e.X > 0) && (e.Y > 0) && (e.Y < bitmap.Height)) { Graphics gr = pictureBoxMainImage.CreateGraphics(); if ((previousPoint.X < e.X) && (e.Y > previousPoint.Y)) { gr.DrawRectangle(penRect, previousPoint.X, previousPoint.Y, e.X - previousPoint.X, e.Y - previousPoint.Y); subImageRectSelection = Coloring.RectangleCut(previousPoint.X, previousPoint.Y, e.X - previousPoint.X, e.Y - previousPoint.Y, bitmap); paintHistogram(Coloring.calculateHistogram(subImageRectSelection), Coloring.calculateMaxHistogramValue(Coloring.calculateHistogram(subImageRectSelection)), pictureBoxRectangularFragmentHistogram, histMainBitmapRectSelection); } else if ((previousPoint.X < e.X) && (e.Y < previousPoint.Y)) { gr.DrawRectangle(penRect, previousPoint.X, e.Y, e.X - previousPoint.X, previousPoint.Y - e.Y); subImageRectSelection = Coloring.RectangleCut(previousPoint.X, e.Y, e.X - previousPoint.X, previousPoint.Y - e.Y, bitmap); paintHistogram(Coloring.calculateHistogram(subImageRectSelection), Coloring.calculateMaxHistogramValue(Coloring.calculateHistogram(subImageRectSelection)), pictureBoxRectangularFragmentHistogram, histMainBitmapRectSelection); } else if ((previousPoint.X > e.X) && (e.Y < previousPoint.Y)) { gr.DrawRectangle(penRect, e.X, e.Y, previousPoint.X - e.X, previousPoint.Y - e.Y); subImageRectSelection = Coloring.RectangleCut(e.X, e.Y, previousPoint.X - e.X, previousPoint.Y - e.Y, bitmap); paintHistogram(Coloring.calculateHistogram(subImageRectSelection), Coloring.calculateMaxHistogramValue(Coloring.calculateHistogram(subImageRectSelection)), pictureBoxRectangularFragmentHistogram, histMainBitmapRectSelection); } else { gr.DrawRectangle(penRect, e.X, previousPoint.Y, previousPoint.X - e.X, e.Y - previousPoint.Y); subImageRectSelection = Coloring.RectangleCut(e.X, previousPoint.Y, previousPoint.X - e.X, e.Y - previousPoint.Y, bitmap); paintHistogram(Coloring.calculateHistogram(subImageRectSelection), Coloring.calculateMaxHistogramValue(Coloring.calculateHistogram(subImageRectSelection)), pictureBoxRectangularFragmentHistogram, histMainBitmapRectSelection); } gr.Dispose(); endPoint = e.Location; contourEnteredFlag = true; extractionPaintFlag = false; buttonRectangularSelection.Focus(); count = 1; } else { Graphics gr = pictureBoxMainImage.CreateGraphics(); if ((previousPoint.X < endPoint.X) && (endPoint.Y > previousPoint.Y)) { gr.DrawRectangle(penRect, previousPoint.X, previousPoint.Y, endPoint.X - previousPoint.X, endPoint.Y - previousPoint.Y); subImageRectSelection = Coloring.RectangleCut(previousPoint.X, previousPoint.Y, endPoint.X - previousPoint.X, endPoint.Y - previousPoint.Y, bitmap); paintHistogram(Coloring.calculateHistogram(subImageRectSelection), Coloring.calculateMaxHistogramValue(Coloring.calculateHistogram(subImageRectSelection)), pictureBoxRectangularFragmentHistogram, histMainBitmapRectSelection); } else if ((previousPoint.X < endPoint.X) && (endPoint.Y < previousPoint.Y)) { gr.DrawRectangle(penRect, previousPoint.X, endPoint.Y, endPoint.X - previousPoint.X, previousPoint.Y - endPoint.Y); subImageRectSelection = Coloring.RectangleCut(previousPoint.X, endPoint.Y, endPoint.X - previousPoint.X, previousPoint.Y - endPoint.Y, bitmap); paintHistogram(Coloring.calculateHistogram(subImageRectSelection), Coloring.calculateMaxHistogramValue(Coloring.calculateHistogram(subImageRectSelection)), pictureBoxRectangularFragmentHistogram, histMainBitmapRectSelection); } else if ((previousPoint.X > endPoint.X) && (endPoint.Y < previousPoint.Y)) { gr.DrawRectangle(penRect, endPoint.X, endPoint.Y, previousPoint.X - endPoint.X, previousPoint.Y - endPoint.Y); subImageRectSelection = Coloring.RectangleCut(endPoint.X, endPoint.Y, previousPoint.X - endPoint.X, previousPoint.Y - endPoint.Y, bitmap); paintHistogram(Coloring.calculateHistogram(subImageRectSelection), Coloring.calculateMaxHistogramValue(Coloring.calculateHistogram(subImageRectSelection)), pictureBoxRectangularFragmentHistogram, histMainBitmapRectSelection); } else { gr.DrawRectangle(penRect, endPoint.X, previousPoint.Y, previousPoint.X - endPoint.X, endPoint.Y - previousPoint.Y); subImageRectSelection = Coloring.RectangleCut(endPoint.X, previousPoint.Y, previousPoint.X - endPoint.X, endPoint.Y - previousPoint.Y, bitmap); paintHistogram(Coloring.calculateHistogram(subImageRectSelection), Coloring.calculateMaxHistogramValue(Coloring.calculateHistogram(subImageRectSelection)), pictureBoxRectangularFragmentHistogram, histMainBitmapRectSelection); } gr.Dispose(); contourEnteredFlag = true; extractionPaintFlag = false; count = 1; buttonRectangularSelection.Focus(); } } if (movingEditFlag) { if (updatePlan(plContour.GetPointByIndex(movIndex), edPoint)) { plContour.ChangePointByIndex(movIndex, edPoint); } else { updateConourEdit(); } contourFlag = true; movingEditFlag = false; } }