479 {
480 Plugins.MouseUp(ImageView.SelectedImage, e, buts);
481 PointD p = new PointD((float)e.X, (float)e.Y);
482 PointD mouseU = ImageView.SelectedImage.ToImageSpace(p);
483 if (App.viewer ==
null ||
currentTool ==
null || ImageView.SelectedImage ==
null)
484 return;
485 Scripting.UpdateState(Scripting.State.GetUp(e, buts.Event.Button));
489 {
490 ROI an = new ROI();
491 an.AddPoint(new PointD(e.X, e.Y));
492 an.type = ROI.Type.Point;
493 an.coord = App.viewer.GetCoordinate();
494 an.Selected = true;
496
497 AddROI(an);
498 }
499 else
501 {
503 {
506 }
507 }
508 else
510 {
512 {
514 }
515 }
516 else
518 {
520 {
522 }
523 }
524 else
526 {
528 }
529 else
530 if (
Tools.currentTool.type ==
Tools.Tool.Type.magic && buts.Event.Button == 1)
531 {
532 PointD pf = new PointD(ImageView.mouseUp.X - ImageView.mouseDown.X, ImageView.mouseUp.Y - ImageView.mouseDown.Y);
533 ZCT coord = App.viewer.GetCoordinate();
534
535 Rectangle r =
new Rectangle((
int)ImageView.mouseDown.X, (
int)ImageView.mouseDown.Y, (
int)(ImageView.mouseUp.X - ImageView.mouseDown.X), (
int)(ImageView.mouseUp.Y - ImageView.mouseDown.Y));
536 if (r.Width <= 2 || r.Height <= 2)
537 return;
538 AForge.Bitmap bf = ImageView.SelectedImage.Buffers[ImageView.SelectedImage.Coords[coord.Z, coord.C, coord.T]].GetCropBuffer(r);
539 Statistics[] sts = Statistics.FromBytes(bf);
540 Statistics st = sts[0];
541 AForge.Bitmap crop = bf;
542 Threshold th;
544 {
545 th =
new Threshold((
int)magicSel.
Threshold);
546 }
547 else
548 if (magicSel.
Index == 2)
549 th = new Threshold((int)(st.Min + st.Mean));
550 else
551 if (magicSel.
Index == 1)
552 th = new Threshold((int)st.Median);
553 else
554 th = new Threshold(st.Min);
555 th.ApplyInPlace(crop);
556 Invert inv = new Invert();
557 AForge.Bitmap det;
558 if (bf.BitsPerPixel > 8)
559 det = AForge.Imaging.Image.Convert16bppTo8bpp((crop));
560 else
561 det = crop;
562 BlobCounter blobCounter = new BlobCounter();
563 blobCounter.ProcessImage(det);
564 Blob[] blobs = blobCounter.GetObjectsInformation();
565
566 GrahamConvexHull hullFinder = new GrahamConvexHull();
567
568
569 foreach (Blob blob in blobs)
570 {
571 if (blob.Rectangle.Width < magicSel.
Max && blob.Rectangle.Height < magicSel.
Max)
572 continue;
573 List<IntPoint> leftPoints = new List<IntPoint>();
574 List<IntPoint> rightPoints = new List<IntPoint>();
575 List<IntPoint> edgePoints = new List<IntPoint>();
576 List<IntPoint> hull = new List<IntPoint>();
577
578 blobCounter.GetBlobsLeftAndRightEdges(blob,
579 out leftPoints, out rightPoints);
580 edgePoints.AddRange(leftPoints);
581 edgePoints.AddRange(rightPoints);
582
583 hull = hullFinder.FindHull(edgePoints);
584 PointD[] pfs = new PointD[hull.Count];
585 for (int i = 0; i < hull.Count; i++)
586 {
587 pfs[i] = new PointD(r.X + hull[i].X, r.Y + hull[i].Y);
588 }
589 ROI an = ROI.CreateFreeform(coord, pfs);
590 ImageView.SelectedImage.Annotations.Add(an);
591 }
592 }
593 else
594 if (
Tools.currentTool.type ==
Tools.Tool.Type.bucket && buts.Event.Button == 1)
595 {
596 if (mouseU.X >= ImageView.SelectedImage.SizeX && mouseU.Y >= ImageView.SelectedImage.SizeY)
597 return;
599 floodFiller.Tolerance = new ColorS(0, 0, 0);
600 floodFiller.Bitmap = ImageView.SelectedBuffer;
601 floodFiller.FloodFill(new AForge.Point((int)mouseU.X, (int)mouseU.Y));
602 App.viewer.UpdateImages();
603 }
604 else
605 if (
Tools.currentTool.type ==
Tools.Tool.Type.dropper && buts.Event.Button == 1)
606 {
607 if (mouseU.X < ImageView.SelectedImage.SizeX && mouseU.Y < ImageView.SelectedImage.SizeY)
608 {
609 DrawColor = ImageView.SelectedBuffer.GetPixel((
int)mouseU.X, (
int)mouseU.Y);
610 }
611 }
613 }
AForge.Rectangle Rectangle
Definition ImageView.cs:14
int Threshold
Definition MagicSelect.cs:82
bool Numeric
Definition MagicSelect.cs:74
int Index
Definition MagicSelect.cs:98
int Max
Definition MagicSelect.cs:94