1

I've been working on an EMGU based project where i need to create a skeleton image with the ZhangSuen thinning algorithm, which works perfectly fine. For further analysis I want to obtain all pixel locations of the skeleton and store them in a List<Point>

I've researched a lot about performance issues when using Bitmap.GetPixel() and Bitmap.SetPixel() methods. Thats why i followed the approach of using a byte[,,] array to get the pixel locations. My approach so far looks like this:

    public static List<Point> GetSkeletonPoints(Image<Gray, Byte> src, Byte color = 255)
    {
        var SkeletonPoints = new List<Point>();
        int rows = src.Width;
        int cols = src.Height;
        byte[,,] data = src.Data;

        for(int y = rows - 1; y >= 0; y--)
        {
            for(int x = cols - 1; x >= 0; x--)
            {
              if(data[x, y, 0] != 0)
                {
                    SkeletonPoints.Add(new Point(x, y));
                }
            }
        }
        return SkeletonPoints;
    }

The skeletonpixels have the value of 255, while the background is black (0). Now the weird thing is if i try to modify the input image like this:

src.Data[0,0,0] = 255;

absolutely nothing changes when I look at the image by using CvInvoke.Imshow("test", src);

Running the presented method results in no Point being added to the list, which means the condition in the if-statement is never fulfilled. Running the if-statement like this if(data[x, y, 0] == 0) results in a condition that is always fulfilled and i get every single point location in the image, despite being actually black (0) or white (255).

I thought that i by mistake used a completely black image.. But then i applied the CvInvoke.FindNonZero() method to the input image and found 500 NonZero-pixels, which makes absolutely no sense to me.

I'm kinda desperate by now, maybe i'm missing something? Any help or hint is much appreciated!! (even if it's something that doesn't solve my problem but enhances the performance of looping over images in general)

Kajij
  • 11
  • 1
  • 2
  • Okay i found what the problem might be... somehow it is indeed the input image that causes the problem. For some reason the Emgu.CV.XImgproc.XImgprocInvoke.Thinning() method produced an output Image which appears to be completely black, but actually isn't. I have no idea what's happening, but turning the output into a Bitmap by calling the ToBitmap() method and turning it back to an Image seemed to work... maybe someone knows the cause of that? – Kajij Jan 13 '18 at 21:16

0 Answers0