4

我想平均一些被零均值高斯加性噪声破坏的 .jpg 图像。在四处搜索之后,我想出了添加图像矩阵并将总和除以矩阵的数量。但是,生成的图像是全黑的。通常,当图像数量增加时,生成的图像会变得更好。但是当我使用更多图像时,它会变暗。

我正在使用 800x600 黑白 .jpg 图像。这是我使用的脚本:

image1 = imread ('PIC1.jpg');
image2 = imread ('PIC2.jpg');
image3 = imread ('PIC3.jpg');
image4 = imread ('PIC4.jpg');

sum = image1 + image2 + image3 + image4; 
av = sum / 4; 
imshow(av);
4

3 回答 3

10

问题可能是图像数据都是 type uint8,因此将它们全部加起来会导致像素值的饱和度为 255,从而为您提供一个大部分为白色的图像,然后当您除以图像数量。您应该将图像转换为另一种数据类型,例如double,然后执行平均,然后转换回uint8

% Load your images:
image1 = imread('PIC1.jpg');
image2 = imread('PIC2.jpg');
image3 = imread('PIC3.jpg');
image4 = imread('PIC4.jpg');

% Convert the images to type double and sum them:
imageSum = double(image1) + double(image2) + double(image3) + double(image4);

% Divide by the number of images and convert back to type uint8:
averageImage = uint8(imageSum./4);

% Display the averaged image:
imshow(averageImage);

旁注:您应该避免为变量提供与任何现有函数相同的名称,因为这可能会导致问题/混乱。这就是为什么我将变量更改sumimageSum(有一个内置函数sum)。

于 2010-03-15T19:21:32.803 回答
7

使用图像处理工具箱中的IMLINCOMB的替代解决方案:

I = imlincomb(0.25,I1, 0.25,I2, 0.25,I3, 0.25,I4);
于 2010-03-15T23:52:49.023 回答
2

你也可以使用 imagesc(averageImage); 此功能具有自动缩放图像并且不会显示为黑色

于 2012-11-18T04:48:50.917 回答