在Halcon中有这样一个函数:
estimate_noise estimate_noise — Estimate the image noise from a single image.
Signature
estimate_noise(Image : : Method, Percent : Sigma)
Description
The operator estimate_noise estimates the standard deviation of additive noise within the domain of the image that is passed in Image. The standard deviation is returned in Sigma.
The operator is useful in the following use cases:
determination of MinContrast for matching,
determination of the amplitude for edge filters,
camera evaluation,
monitoring errors in camera operation (e.g., user overdrives camera gain).
即从单幅图像中评估图像噪音的均方差,这个算子可以用于计算匹配时的最小对比度(发现新大陆了,原路模板匹配还可以用这个做自动化)、边缘检测滤波器的幅度、摄像机评估、控相机操作中的错误(例如用户过度调节相机增益)。
我觉得还可以把他作为自动去噪的一个参考指标。
Halcon里提供了四个评估噪音的方法:: 'foerstner', 'immerkaer', 'least_squares', 'mean',其本身最推荐的方法是immerkaer,如其帮助文档里所说:
Use the method 'immerkaer', instead of the methods 'foerstner', 'least_squares', or 'mean'. The method 'immerkaer' does not rely on the existence of homogeneous image regions, and hence is almost always applicable.
关于immerkaer方法,开放的Halcon基本上提供了完整的算法思路:
'immerkaer': If Method is set to 'immerkaer', first the following filter mask is applied to the input image:

The advantage of this method is that M is almost insensitive to image structure but only depends on the noise in the image. Assuming a Gaussian distributed noise, its standard deviation is finally obtained as

where N is the number of image pixels to which M is applied. Note that the result obtained by this method is independent of the value passed in Percent.
这个M算子明显就是类似一个边缘检测的算子,然后把所有这个算子的结果相加,再求某个意义下的平均值,Halcon说这个方法的好处是对图像的结构不敏感,而只完全依赖于图像的噪音本身。
我想有了这个提示,要实现这个功能应该就是很简单的过程了。
我的一个实现如下所示:
// 模拟实现halcon的estimate_noise函数
int IM_EstimateNoise(unsigned char *Src, int Width, int Height, int Stride, float &Sigma)
{
int Channel = Stride / Width;
if (Src == NULL) return IM_STATUS_NULLREFRENCE;
if ((Width <= 0) || (Height <= 0)) return IM_STATUS_INVALIDPARAMETER;
if (Channel != 1) return IM_STATUS_NOTSUPPORTED;
unsigned int Sum = 0;
for (int Y = 1; Y < Height - 1; Y++)
{
unsigned char *LinePL = Src + (Y - 1) * Stride;
unsigned char *LinePC = Src + (Y - 0) * Stride;
unsigned char *LinePN = Src + (Y + 1) * Stride;
for (int X = 1; X < Width - 1; X++)
{
int L = LinePL[X - 1] - 2 * LinePL[X] + LinePL[X + 1];
int C = -2 * LinePC[X - 1] + 4 * LinePC[X] - 2 * LinePC[X + 1];
int N = LinePN[X - 1] - 2 * LinePN[X] + LinePN[X + 1];
Sum += IM_Abs(L + C + N);
}
}
Sigma = sqrtf(IM_PI / 2) / (6 * Width * Height) * Sum;
return IM_STATUS_OK;
}
为了简化代码,没有考虑图像周边单位像素的信息了,如果要严格意义的实现,也应该不是很难吧。
我们比较下halcon的结果和上面这段代码的结果,使用Halcon自带的测试代码和图片:
dev_update_off ()
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
TestImages := ['for6','pumpe','die/die_02','clip','ic0','horses','board/board-01','combine']
NumImages := |TestImages|
for I := 0 to NumImages - 1 by 1
read_image (Image, TestImages[I])
dev_resize_window_fit_image (Image, 0, 0, -1, -1)
dev_display (Image)
for AddedNoise := 0 to 15 by 5
gauss_distribution (AddedNoise + 1e-2, Distribution)
add_noise_distribution (Image, ImageNoise, Distribution)
write_image (ImageNoise, 'bmp', 0, 'C:/Users/Administrator/Desktop/1.bmp')
estimate_noise (ImageNoise, 'foerstner', 20, SigmaFoerstner)
estimate_noise (ImageNoise, 'immerkaer', 20, SigmaImmerkaer)
estimate_noise (ImageNoise, 'least_squares', 20, SigmaLeastSquares)
estimate_noise (ImageNoise, 'mean', 20, SigmaMean)
dev_display (ImageNoise)
disp_message (WindowHandle, 'Added Gaussian noise: Sigma = ' + AddedNoise, 'window', 12, 12, 'black', 'true')
Message := 'Estimated image noise (Sigma):'
Message[1] := 'Method \'foerstner\': ' + SigmaFoerstner$'5.2f'
Message[2] := 'Method \'immerkaer\': ' + SigmaImmerkaer$'5.2f'
Message[3] := 'Method \'least_squares\': ' + SigmaLeastSquares$'5.2f'
Message[4] := 'Method \'mean\': ' + SigmaMean$'5.2f'
disp_message (WindowHandle, Message, 'windowe', 40, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
endfor
endfor
噪音图像 Halcon的结果
使用上述C的代码获取的结果为: 5.240565,和Halcon的结果基本一致。
我们再找一些正常的图片看看这个噪音值是否合理:

噪音值 0.7763 噪音值 2.6604
基本啥都比较小。

噪音值 7.2155 噪音值 20.04
对于高斯噪音,如上所示,还是能明显的区别出来的。
不过测试也表面,有些图的噪音虽然视觉看起来比较明显,但是用这参数去衡量时,确是很小,这个可能是因为他针对的是加性噪音做的评估吧。
参考资料:
W. Förstner: “Image Preprocessing for Feature Extraction in Digital Intensity, Color and Range Images“, Springer Lecture Notes on Earth Sciences, Summer School on Data Analysis and the Statistical Foundations of Geomatics, 1999
J. Immerkaer: “Fast Noise Variance Estimation“, Computer Vision and Image Understanding, Vol. 64, No. 2, pp. 300-302, 1996
Sinatra新手;我正在运行一些rspec测试,但在日志中收到了一堆不需要的噪音。如何消除日志中过多的噪音?我仔细检查了环境是否设置为:test,这意味着记录器级别应设置为WARN而不是DEBUG。spec_helper:require"./app"require"sinatra"require"rspec"require"rack/test"require"database_cleaner"require"factory_girl"set:environment,:testFactoryGirl.definition_file_paths=%w{./factories./test/
我有带有Logo图像的公司模型has_attached_file:logo我用他们的Logo创建了许多公司。现在,我需要添加新样式has_attached_file:logo,:styles=>{:small=>"30x15>",:medium=>"155x85>"}我是否应该重新上传所有旧数据以重新生成新样式?我不这么认为……或者有什么rake任务可以重新生成样式吗? 最佳答案 参见Thumbnail-Generation.如果rake任务不适合你,你应该能够在控制台中使用一个片段来调用重新处理!关于相关公司
我正在尝试使用Ruby2.0.0和Rails4.0.0提供的API从imgur中提取图像。我已尝试按照Ruby2.0.0文档中列出的各种方式构建http请求,但均无济于事。代码如下:require'net/http'require'net/https'defimgurheaders={"Authorization"=>"Client-ID"+my_client_id}path="/3/gallery/image/#{img_id}.json"uri=URI("https://api.imgur.com"+path)request,data=Net::HTTP::Get.new(path
2022/8/4更新支持加入水印水印必须包含透明图像,并且水印图像大小要等于原图像的大小pythonconvert_image_to_video.py-f30-mwatermark.pngim_dirout.mkv2022/6/21更新让命令行参数更加易用新的命令行使用方法pythonconvert_image_to_video.py-f30im_dirout.mkvFFMPEG命令行转换一组JPG图像到视频时,是将这组图像视为MJPG流。我需要转换一组PNG图像到视频,FFMPEG就不认了。pyav内置了ffmpeg库,不需要系统带有ffmpeg工具因此我使用ffmpeg的python包装p
有这样的事吗?我想在Ruby程序中使用它。 最佳答案 试试这个http://csl.sublevel3.org/jp2a/此外,Imagemagick可能还有一些东西 关于ruby-是否有将图像文件转换为ASCII艺术的命令行程序或库?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/6510445/
我正在使用Dragonfly在Rails3.1应用程序上处理图像。我正在努力通过url将图像分配给模型。我有一个很好的表格:{:multipart=>true}do|f|%>RemovePicture?Dragonfly的文档指出:Dragonfly提供了一个直接从url分配的访问器:@album.cover_image_url='http://some.url/file.jpg'但是当我在控制台中尝试时:=>#ruby-1.9.2-p290>picture.image_url="http://i.imgur.com/QQiMz.jpg"=>"http://i.imgur.com/QQ
我对图像处理完全陌生。我对JPEG内部是什么以及它是如何工作一无所知。我想知道,是否可以在某处找到执行以下简单操作的ruby代码:打开jpeg文件。遍历每个像素并将其颜色设置为fx绿色。将结果写入另一个文件。我对如何使用ruby-vips库实现这一点特别感兴趣https://github.com/ender672/ruby-vips我的目标-学习如何使用ruby-vips执行基本的图像处理操作(Gamma校正、亮度、色调……)任何指向比“helloworld”更复杂的工作示例的链接——比如ruby-vips的github页面上的链接,我们将不胜感激!如果有ruby-
Organization和Image具有一对一的关系。Image有一个名为filename的列,它存储文件的路径。我在Assets管道中包含这样一个文件:app/assets/other/image.jpg。播种时如何包含此文件的路径?我已经在我的种子文件中尝试过:@organization=...@organization.image.create!(filename:File.open('app/assets/other/image.jpg'))#Ialsotried:#@organization.image.create!(filename:'app/assets/other/i
默认情况下:回形针gem将所有附件存储在公共(public)目录中。出于安全原因,我不想将附件存储在公共(public)目录中,所以我将它们保存在应用程序根目录的uploads目录中:classPost我没有指定url选项,因为我不希望每个图像附件都有一个url。如果指定了url:那么拥有该url的任何人都可以访问该图像。这是不安全的。在user#show页面中:我想实际显示图像。如果我使用所有回形针默认设置,那么我可以这样做,因为图像将在公共(public)目录中并且图像将具有一个url:Someimage:看来,如果我将图像附件保存在公共(public)目录之外并且不指定url(同
使用Paperclip,我想从这样的URL抓取图像:require'open-uri'user.photo=open(url)问题是我最后得到一个像“open-uri20110915-4852-1o7k5uw”这样的文件名。有什么方法可以更改user.photo上的文件名?作为一个额外的变化,Paperclip将我的文件存储在S3上,所以如果我可以在初始分配中设置我想要的文件名就更好了,这样图像就会上传到正确的S3key。像这样:user.photo=open(url),:filename=>URI.parse(url).path 最佳答案