Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
高级会员
注册日期: 2019-11-21
帖子: 3,006
声望力: 66 ![]() |
![]()
我想对零均值高斯加性噪声破坏的.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); 回答: 问题可能是图像数据全部为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); 旁注:您应该避免为变量指定与任何现有函数相同的名称,因为这可能导致问题/混乱。这就是为什么我将变量sum更改为imageSum (有内置函数sum )。 更多&回答... |
![]() |
![]() |