gpt4 book ai didi

c# - (高斯)滤波后归一化图像

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:56:02 36 4
gpt4 key购买 nike

我已经按照 Nixon Aguado 的算法实现了一个高斯滤波器。算法(找到此处描述的模板后 gaussian template )如下。

我相信伪代码是 MATLAB 风格的。

function convolved=convolve(image,template)
%New image point brightness convolution of template with image
%Usage:[new image]=convolve(image,template of point values)
%Parameters:image-array of points
% template-array of weighting coefficients
%Author: Mark S. Nixon
%get image dimensions
[irows,icols]=size(image);
%get template dimensions
[trows,tcols]=size(template);
%set a temporary image to black
temp(1:irows,1:icols)=0;

%half of template rows is
trhalf=floor(trows/2);
%half of template cols is
tchalf=floor(tcols/2);
%then convolve the template
for x=trhalf+1:icols-trhalf %address all columns except border
for y=tchalf+1:irows-tchalf %address all rows except border
sum=0;
for iwin=1:trows %address template columns
for jwin=1:tcols %address template rows
sum=sum+image(y+jwin-tchalf-1,x+iwin-trhalf-1)* template(jwin,iwin);
end
end
temp(y,x)=sum;
end
end

%finally, normalise the image
convolved=normalise(temp);

无论如何,让我担心的是最后一部分“正常化”。我尝试了我的算法(用 C# 编写),一些像素的值为 255.00000003(明显大于 255)。我应该“规范化”结果以将其扩大到 0-255 范围吗?那不是在修改图像吗(高斯除外)我只是希望此操作只涉及高斯滤波器。


编辑:我已经消除了“规范化”,它似乎运作良好,所以我不知道为什么这本书的作者推荐它。尽管如此,如果由于某种原因某些值 > 255 出现并且无法绘制,我的程序会崩溃,这仍然让我担心。

最佳答案

正如其他人在评论中指出的那样,规范化图像以确保每个 channel 的范围为 0 到 255 是不好的。

归一化在每个值都被限制在 0 到 255 之间的意义上的图像对于适当的过滤器内核来说不是必需的。然而在实践中,由于 way floating point numbers work,它可能是必要的或有用的。 . float 不能表示所有可能的实数,而且每次计算都会带来一些误差。这可能是 255.00000003 作为值之一的原因。

与许多信号处理算法一样,该算法假设时间/空间离散,但值连续。推理这些算法并用数学方法描述它们要容易得多。

在计算机上,您没有连续的值。图像使用离散值,每个 channel 通常是 0 到 255 之间的整数(每个 channel 8 位)。声音通常以每声道 16 位编码。

在绝大多数情况下,这是完全可以接受的,但它实际上是高斯滤波器输出之后的另一个滤波器(尽管是非线性滤波器)。所以是的,从严格意义上讲,您确实修改了高斯滤波器的输出,无论是在保存图像时还是在屏幕上显示图像时。

关于c# - (高斯)滤波后归一化图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45793261/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com