遍历EmguCV中Mat的每个像素 [英] Iterate over each pixel of Mat in EmguCV

查看:123
本文介绍了遍历EmguCV中Mat的每个像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用C#将值分配给EmguCV中Mat的每个像素.我已经阅读了文档,但是找不到任何方法.我可以使用 Image 进行此操作,但我想使用 Mat 进行此操作.所以,任何人都可以告诉我该怎么做.

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.

推荐答案

在EmguCV中,您可以使用 Data 方法获取每个像素的值,但是根据文档中的描述,您无法重新分配它.我从您的问题中了解到的是,您想将每个像素的颜色值放入 Mat 类的变量中.如果这是问题所在,那么您可以查看以下对我来说很完美的代码.

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);

在使用任何调色板对图像进行伪着色期间,我都使用了这种方法.我创建了一个3维数组,并使用 Mat 类的 SetTo 方法,将数组分配给 Mat .希望有帮助.

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.

这篇关于遍历EmguCV中Mat的每个像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆