Identify x,y-coordinates of white pixel in binary image in c# [closed]

asked 2020-04-28 02:07:38 -0600

Hello, everyone,

I would have to determine the x,y coordinates of individual white pixels within a single-line image for an image processing task. For this purpose I have thought of two approaches, for which I have not found a solution yet.

1st solution: For a fast identification of the pixels I perform a binarization via a threshold function and try to find the white pixels in it.

Problem: I need to use OpenCV version 3.0.0 for certain reasons, which I unfortunately cannot change. The only function that works and can be used with a non-zero value is CV.CountNonZero(). However, this function only returns the number of pixels and not the position. The function CV.FindNonZero() is unfortunately not available to me.

Second solution: Iterate and adjust the color value of each pixel within the single-line image. The following code was written for this:

        //Find all pixel > 0 (just for control how many I have to find)
        var count = CV.CountNonZero(threshold_zeile);
        Console.WriteLine(count);

        //Iterate through the rows and cols to read out the color value 
        for (int i = 0; i < threshold_zeile.Rows; i++)
        {// image : the binary image
            var row = threshold_zeile.GetRow(i);
            for (int j = 0; j < threshold_zeile.Cols; j++)
            {
                var dings = threshold_zeile.Data;
                int b = dings[i,j,0];
                int b = *threshold_zeile.Data[i,j,0];

                var col = row.GetCol(j);
                int b = (int) col.Data; //int value = (int)returned[0];
                if (b == 255)
                {
                    Console.WriteLine("x: " + i + "\ty: " + j);// returned the (x,y) //co ordinates of all white pixels.
                }
            }

        }

Unfortunately the command .Date[i, j, 0] does not work. The error message System.OverflowException: The arithmetic operation caused an overflow is always issued. I have already researched many forums and unfortunately I can neither find a way to solve the error message, nor an alternative to read the color value of the pixel.

Can anyone help me with this? I'm running out of ideas. Many thanks in advance.

edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant by berak
close date 2020-04-28 02:08:59.547418