Iterate over each pixel of Mat in EmguCV

蓝咒 提交于 2021-01-29 10:45:37

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/50363945/iterate-over-each-pixel-of-mat-in-emgucv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!