Вопрос

I am taking three images and saving them as Tiff images in order to preserve the data of the image for analysis. In my program I load these three images as 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. 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.

For color images EmguCV stores Red, Green and Blue Data in layer 0,1,2 of the image respectively

 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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top