user9733371
user9733371

Reputation:

Iterate over each pixel of Mat in EmguCV

I want to assign the value to each pixel of Mat in EmguCV using C#. I have read the documentation but doesn't find any way to do this. I have able to do this with Image but I want to do this with Mat. So, can anyone please tell me how to do this.

Upvotes: 1

Views: 2244

Answers (1)

Lakshraj
Lakshraj

Reputation: 291

In EmguCV you can use Data method to get the value of each pixel but as per written in Documentation you cannot reallocate it. What I get to know from your question is that you want to put the color value of each pixel to variable of Mat class. If this is the problem you can see the below code that works perfect for me.

        Byte[,,] color = new Byte[256, 1, 3];
        int i = 0;
        for (double x = 0; x < palette.Rows;)
        {
            color[i, 0, 0] = palette.Data[(int)x, palette.Width / 2, 0];
            color[i, 0, 1] = palette.Data[(int)x, palette.Width / 2, 1];
            color[i, 0, 2] = palette.Data[(int)x, palette.Width / 2, 2];
            i++;
            x = x + 3.109;
        }
        Mat lut = new Mat(256, 1, DepthType.Cv8U, 3);
        lut.SetTo(color);

I have used this approach during pseudo coloring of the image by any color palette. I have created a 3 Dimensional array and using SetTo method of Mat class I have just assign that array to Mat. Hopefully that helps.

Upvotes: 2

Related Questions