Mihai Alexandru-Ionut
Mihai Alexandru-Ionut

Reputation: 48327

How to detect number of objects from image?

I have a windows forms application and i want to count number of objects from a medical images. For instance

enter image description here

I used an algorithm which can take the contours of every object from the image.

private void findContoursToolStripMenuItem_Click(object sender, EventArgs e)
    {
        Image<Gray, byte> imgOutput = imgInput.Convert<Gray, byte>().ThresholdBinary(new Gray(100), new Gray(255));
        Emgu.CV.Util.VectorOfVectorOfPoint contours = new Emgu.CV.Util.VectorOfVectorOfPoint();
        Mat hier = new Mat();

        Image<Gray, byte> imgout = new Image<Gray, byte>(imgInput.Width, imgInput.Height, new Gray(100));

        CvInvoke.FindContours(imgOutput, contours, hier, Emgu.CV.CvEnum.RetrType.External, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple);
        CvInvoke.DrawContours(imgout, contours, -1, new MCvScalar(123, 0, 0));

        pictureBox2.Image = imgout.Bitmap;

    } 

But I can't find out the number of cells from the image. Any advice or algorithm I have to use ?

I search within EMGU documentation but I don't find any function which does somethink like I want.

Any advice or answer will be rewarded.

If you consider that is too broad, I don't want the implemented algorithm. I just need some ideas or a suggestion of algorithm i have to use.

Upvotes: 0

Views: 1361

Answers (1)

Neil
Neil

Reputation: 11891

It probably a bit basic and brute force, but how about selecting a random point on the image that is close to the green colour, then effectively search for 'matching' colours (with a tolerance for the same colour. As you visit each pixel, colour it black so you don't look at it again and count how many pixels you have coloured in. Each time you select a pixel, make sure it's not black. Once you can't find any more points, if the number of black pixels is greater than a tolerance (so you only find 'big' polygons), then count it in the number of cells.

Upvotes: 1

Related Questions