如何在两个图像的byte []数组相结合迅速利用C#中的掩码数组 [英] How to combine two image byte[] arrays together quickly utilizing a mask array in C#

查看:352
本文介绍了如何在两个图像的byte []数组相结合迅速利用C#中的掩码数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在概括地说,我有两个图像我想用一个面具覆盖了另一种使第二图像显示了只有部分。这是一个实时图像处理日常工作的一部分,所以我需要尽可能快地执行的操作。

In a nutshell I have two images I want to overlay one over the other using a mask so that only parts of the second image show up. This is part of a real time image processing routine so I need the operation to happen as fast as possible.

具体来说,我有两个32位的图像BGR字节数组。另外,我有一个字节数组,表示图像遮罩。

Specifically, I have two 32 bit image BGR byte arrays. In addition, I have a byte array that represents an image mask.

我要生成一个新的字节数组,其中字节数组是在字节数组b顶部使用掩码数组来决定使用哪个字节重叠。

I want to generate a new byte array where byte array A is overlayed on top of byte array B using the mask array to decide which byte is used.

什么是做到这一点的最快方法是什么?

What is the quickest way to do this?

我是看着约老式精灵屏蔽,但我这个维基百科文章不知道如何最好地转换这C#。 http://en.wikipedia.org/wiki/Mask_(computing

I was looking at this wikipedia article about old fashioned sprite masking but I am not sure how to best translate this to C#. http://en.wikipedia.org/wiki/Mask_(computing)

编辑:我忘了提,我可以restruct任何或所有这使其运行速度更快

I forgot to mention that I can restruct any or all of this to make it run faster.

推荐答案

在原则上,屏蔽像这样很简单 - 假设数组的大小相同,这个代码将做到这一点:

In principle, masking like this is very simple - assuming the arrays are the same size, this code would do it:

static void MaskImage(byte[] background, byte[] foreground, byte[] mask)
{
    for (var i = 0; i < background.Length; ++i)
    {
        background[i] &= mask[i];
        background[i] |= foreground[i];
    }
}

在现实,这将是相当多的复杂的 - 你的背景可能会比任何前景图像放大你屏蔽到它,你就必须做一些算术妥善放置它。虽然繁琐得到的权利,它并不难。

In a reality this will be quite a bit more complicated - your background is likely to be larger than whatever foreground image you're masking onto it, and you'll have to do some arithmetic to place it properly. While tedious to get right, it's not hard.

这篇关于如何在两个图像的byte []数组相结合迅速利用C#中的掩码数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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