Пример #1
0
        public void ProcessFilter(TifFileInfo fi, int channel, float tolerance, int thresholdValue, DistanceTransformMethod distance)
        {
            //Apply in the history
            if (fi.newFilterHistory == null || fi.newFilterHistory.Length != fi.sizeC)
            {
                fi.isBinary         = new bool[fi.sizeC];
                fi.newFilterHistory = new List <string> [fi.sizeC];
                for (int i = 0; i < fi.sizeC; i++)
                {
                    fi.newFilterHistory[i] = new List <string>();
                    fi.isBinary[i]         = false;
                }
            }
            fi.isBinary[fi.cValue] = true;
            Filters.MyConvolution.CheckIsImagePrepared(fi);

            int[] indexes = new int[fi.imageCount / fi.sizeC];

            for (int i = channel, position = 0; i < fi.imageCount; i += fi.sizeC, position++)
            {
                indexes[position] = i;
            }

            foreach (int frame in indexes)
            {
                UnmanagedImage input = CreateImage(frame, fi, thresholdValue);

                BinaryWatershed bw = new BinaryWatershed(tolerance, distance);
                input = bw.Apply(input);

                ReturnCTImage(frame, fi, input);
            }
        }
Пример #2
0
 public override Task extractContourns()
 {
     return(Task.Run(delegate(){
         this.rgb = this.rgb.Resize(this.preferredSize.Width, this.preferredSize.Height, Emgu.CV.CvEnum.Inter.Linear, true);
         this.mask = this.mask.Resize(this.preferredSize.Width, this.preferredSize.Height, Emgu.CV.CvEnum.Inter.Linear, true);
         Bitmap maskAsBitmap = mask.ToBitmap();
         Bitmap rgbAsBitmap = new Bitmap(this.rgb.ToBitmap());
         var dt = new BinaryWatershed(0.5f, DistanceTransformMethod.Euclidean);
         Bitmap output = dt.Apply(maskAsBitmap);
         BlobCounter bc = new BlobCounter();
         bc.ObjectsOrder = ObjectsOrder.Area;
         bc.ProcessImage(output);
         Blob[] blobs = bc.GetObjectsInformation();
         foreach (Blob blob in blobs)
         {
             if (blob.Area > 100)
             {
                 List <Accord.IntPoint> border = bc.GetBlobsEdgePoints(blob);
                 Point[] borderPoints = border.Select(pt => new Point(pt.X, pt.Y)).ToArray();
                 bc.ExtractBlobsImage(rgbAsBitmap, blob, false);
                 //this.rgb.Draw(new Cross2DF(new PointF(blob.CenterOfGravity.X, blob.CenterOfGravity.Y), 15, 15), new Bgr(0, 255, 0), 3);
                 this.pollenGrains.Add(new PollenGrain(blob));
             }
         }
     }));
 }
Пример #3
0
        public void ApplyTest1()
        {
            string basePath = Path.Combine(NUnit.Framework.TestContext.CurrentContext.TestDirectory, "watershed");

            Directory.CreateDirectory(basePath);

            Bitmap shapes = Accord.Imaging.Image.Clone(Resources.water);

            shapes.Save(Path.Combine(basePath, "shapes.jpg"));

            var    bw     = new BinaryWatershed();
            Bitmap result = bw.Apply(shapes);

            Assert.AreEqual(746, result.Width);
            Assert.AreEqual(643, result.Height);
            Assert.AreEqual(PixelFormat.Format8bppIndexed, result.PixelFormat);

            Assert.AreEqual(9, bw.MaxPoints.Count);

            string strX = bw.MaxPoints.Select(i => i.X).ToArray().ToCSharp();
            string strY = bw.MaxPoints.Select(i => i.Y).ToArray().ToCSharp();

            double[] x = new double[] { 310, 546, 136, 254, 429, 612, 398, 345, 498 };
            double[] y = new double[] { 436, 153, 392, 201, 336, 339, 242, 183, 319 };

            Assert.AreEqual(x, bw.MaxPoints.Select(i => i.X).ToArray());
            Assert.AreEqual(y, bw.MaxPoints.Select(i => i.Y).ToArray());

            result.Save(Path.Combine(basePath, "watershed.jpg"));

            GrayscaleToRGB toRGB = new GrayscaleToRGB();

            result = toRGB.Apply(result);

            PointsMarker marker = new PointsMarker(Color.Red, 5);

            marker.Points = bw.MaxPoints;
            Bitmap marked = marker.Apply(result);

            marked.Save(Path.Combine(basePath, "watershed-marks.jpg"));

            Assert.IsNotNull(result);
            Assert.IsNotNull(marked);
        }
Пример #4
0
        private void watershedToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BinaryWatershed filter = new BinaryWatershed();

            Image = filter.Apply(Image);
        }