简体   繁体   English

遍历EmguCV中Mat的每个像素

[英]Iterate over each pixel of Mat in EmguCV

I want to assign the value to each pixel of Mat in EmguCV using C#. 我想使用C#将值分配给EmguCV中Mat的每个像素。 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 . 我能够使用Image做到这一点,但我想通过Mat做到这一点。 So, can anyone please tell me how to do this. 所以,任何人都可以告诉我该怎么做。

In EmguCV you can use Data method to get the value of each pixel but as per written in Documentation you cannot reallocate it. 在EmguCV中,您可以使用Data方法来获取每个像素的值,但是根据文档中的描述,您无法重新分配它。 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. 我从您的问题中了解到的是,您想将每个像素的颜色值放入Mat类的变量中。 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 . 我创建了一个3维数组,并使用Mat类的SetTo方法将数组分配给Mat Hopefully that helps. 希望有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM