简体   繁体   English

使用Emgu.CV添加和平均Tiff图像以创建平均Tiff图像

[英]Adding and averaging Tiff images using Emgu.CV to create an averaged Tiff image

I am taking three images and saving them as Tiff images in order to preserve the data of the image for analysis. 我正在拍摄三张图像,并将它们另存为Tiff图像,以便保留图像数据以供分析。 In my program I load these three images as Emgu.CV.Image<Rgb,ushort> . 在我的程序中,我将这三个图像加载为Emgu.CV.Image<Rgb,ushort> I need to add these three images together and return a final tiff image that is the average of the three seperate images. 我需要将这三个图像加在一起,并返回最终的tiff图像,该图像是三个单独图像的平均值。 What would be the best way to go about doing this? 这样做的最佳方法是什么?

Using the underlying method you can access the individual pixel values of images in emgucv and then find the average. 使用基础方法,您可以访问emgucv中图像的单个像素值,然后找到平均值。

For color images EmguCV stores Red, Green and Blue Data in layer 0,1,2 of the image respectively 对于彩色图像,EmguCV分别在图像的第0,1,2层中存储红色,绿色和蓝色数据

 for (int i = 0; i < img1.Width; i++)
    {
        for (int j = 0; j < img1.Height; j++)
        {
            img4.Data[i,j,0] = (img1.Data[i,j,0] + img2.Data[i,j,0] +img3.Data[i,j,0])/3;
            img4.Data[i,j,1] = (img1.Data[i,j,1] + img2.Data[i,j,1]+ img3.Data[i,j,1])/3;
            img4.Data[i,j,2] = (img1.Data[i,j,2] + img2.Data[i,j,2]+ img3.Data[i,j,2])/3;
        }
    }

Note: The above code assumes that all the images are of equal size(height and width),if its not the case you should iterate for the image with the biggest size, and set the unavailable images's(or smaller image's) corresponding pixels to zero before adding . 注意:以上代码假定所有图像的大小(高度和宽度)相等,如果不是这种情况,则应迭代最大尺寸的图像,并将不可用图像(或较小图像)的对应像素设置为零在添加之前。

You should also use some thing as Math.Floor or similar to normalize each pixel values as pixel values can't be in decimals. 您还应该使用Math.Floor类的东西或类似的东西来标准化每个像素值,因为像素值不能为小数。

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

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