- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有两张图片(原始的和嘈杂的)。我正在计算 PSNR。我有点为彩色 RGB 图像做了它,但我不知道如何用灰度来做。正如我所读,MSE 计算是不同的。对于 RGB,我的做法与您在以下代码中看到的一样(我使用的是 Visual C#):
for (int i = 0; i < bmp1.Width; i++)
{
for (int j = 0; j < bmp1.Height; j++)
{
mseR += Math.Pow(bmp1.GetPixel(i, j).R - bmp2.GetPixel(i, j).R, 2);
mseG += Math.Pow(bmp1.GetPixel(i, j).G - bmp2.GetPixel(i, j).G, 2);
mseB += Math.Pow(bmp1.GetPixel(i, j).B - bmp2.GetPixel(i, j).B, 2);
}
}
mse = (mseR + mseG + mseB) / ((bmp1.Width * bmp1.Height) * 3);
在这里,我正在处理 R、G、B 像素。但是我不知道在灰度图像的情况下我应该采取什么措施。我是否也可以使用 RGB,因为它实际上给出了一些结果,或者我应该采用其他方法?
最佳答案
要制作灰度,您可以使用平均值制作图片(无需改变您的实现)。我假设您的图像是 bmp1 = grayImage 和 bmp2 = 噪声图像。
for (int i = 0; i < bmp1.Width; i++)
{
for (int j = 0; j < bmp1.Height; j++)
{
// As a grayscale image has rthe same color on all RGB just pick one
int gray1 = bmp1.GetPixel(i, j).R;
int gray2 = bmp2.GetPixel(i, j).R;
double sum = Math.Pow(gray1 - gray2, 2)
mseGray += sum;
}
}
mse = (mseGray) / ((bmp1.Width * bmp1.Height) * 3);
同时一次获取一个像素是使用索引的缓慢过程,也是循环中的优化。它应该提供大约十倍的性能。
您需要将位图制作成可索引的 img,在本例中我假设它是 BitmapSource。有趣的部分是循环和索引构建而不是预编码,预编码只是为了使图像可索引。
var height = bmp1.Height;
var width = bmp1.Width;
var pixelBytes1 = new byte[height * width * 4];
var pixelBytes2 = new byte[height * width * 4];
bmp1.CopyPixels(pixelBytes1, stride, 0);
bmp2.CopyPixels(pixelBytes2, stride, 0);
for (int x = 0; x < width; x++)
{
int woff = x * height;
for (int y = 0; y < height; y++)
{(R*0.3 + G*0.59+ B*0.11)
int index = woff + y;
int gray1 = bmp1[index];
int gray2 = bmp2[index];
double sum = Math.Pow(gray1 - gray2, 2)
mseGray += sum;
}
}
mse = (mseGray) / ((bmp1.Width * bmp1.Height) * 3);
编辑:
我对你的 PSNR 实现有疑问,但我认为它不符合定义这是来自 java 的示例(与 C# 非常相似) http://www.cyut.edu.tw/~yltang/program/Psnr.java
关于c# - 灰度图像的 MSE 计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28925208/
有谁知道是否有办法在悬停时使图像灰度 - 除了创建 2 个单独的图像并更改 src 之外。 谢谢 编辑 - 半工作代码...: $(document).ready(function() {
我正在使用 flexbox 构建一个网站,其中包含 16x9 视频缩略图的 3 乘任意网格。我想在彩色缩略图变成单调(灰度 + x% 透明颜色层)的地方创建翻转,上面有一个白色 Logo 。 尽管我尽
现在泰国很多网站都是灰度的,大多使用-webkit-filter: grayscale(100%), filter: grayscale(100%)等。 我知道我们可以像往常一样“手动”(在 Chro
给定一张灰度的图像,我如何获得该位置的灰度像素值? 这始终将 temp 输出为 -16777216(黑色)。 public void testMethod() { int width = im
灰度化一个可绘制对象: ColorMatrix matrix = new ColorMatrix(); matrix.setSaturation(200); ColorMatrixColorFilte
我正在尝试创建一种悬停效果,其中图像以全彩色开始,当我将鼠标悬停在图像上时,我希望它有一个蓝色覆盖层。 事实是,只有一个简单的蓝色叠加层,它只是在彩色图像之上放置一个半透明的蓝色 block ……这意
将颜色 Drawable 转换为灰度的正确方法是什么(表示禁用状态)? 编辑: 黑白 => 灰度 最佳答案 我知道这个问题是不久前提出的,但我遇到了一个更简单的解决方案,如果你有一个 Drawable
我需要将 CMYK 图像转换为灰度 CMYK 图像。起初我以为我可以使用与 RGB -> 灰度转换相同的方法,比如 (R + G + B)/3 或 max(r, g, b)/2 + min(r, g,
我遇到了一些将 UIImage 更改为灰度的代码的问题。它可以在 iPhone/iPod 上正常工作,但在 iPad 上,任何已经绘制的内容都会在此过程中被拉伸(stretch)和扭曲。 它有时也只在
假设我有: int x = 140; 我想得到的结果: int y = new Color(x, x, x).getRGB() 来自 Java API 文档: getRGB() Gets the RG
我在我的论文中使用 opencv 用 c++ 编写了一个 block 匹配算法。它正在处理灰度图片并通过其绝对像素地址寻址 IPLImage。 我必须将 IPLImage 分成相同大小的 block
我有一个带有背景图像的 div,我正在使用过滤器以黑白方式显示它 (filter: grayscale(100%);)。我现在正试图在该 div 中放置一个颜色图标。尝试将图标设置为 grayscal
我会避免使用 cvtColor(frame, image, CV_RGB2GRAY); 转换摄像机拍摄的每一帧无论如何设置 VideoCapture 直接进入灰度? 例子: VideoCapture
我有一些 CSS 可以将我的图像变成灰度(带有一些用于 Firefox 的 svg) img.grayscale{ filter: grayscale(100%);
有没有什么方法可以在不丢失任何其他功能的情况下以灰度显示 Google map (通过 Javascript API 嵌入)? 最佳答案 是的,他们在 API 的 V3 中引入了 StyledMaps
我正在使用 Java Swing 制作桌面应用程序。 在我的应用程序中,我对 16 位灰度和 tiff 图像进行了一些图像处理。 在我的应用程序中,用户可以通过将图像拖放到 JDesktopPane
我正在为学校的一个项目执行此操作,稍后将添加更多功能,但我在完成基本设置时遇到了困难。 我最初尝试在 C++ 中执行此操作,但在阅读了有关 BufferedImage 的一些文档后决定切换到 Java
我使用 Canvas 更改网页上图像的颜色(本例为灰度)。但是,通过使用以下代码,仅更改了最后一张图像。 但我想更改网页上所有图像的颜色 $(function(){ var theI
首先我要警告你,我只是一个试图让事情发挥作用的物理学家,我对 C++ 的知识基本上是不存在的。 我目前正在使用 GATE 模拟 CT 扫描仪,我需要将输出转换为 bmp 文件。 Gate 制作了一系列
link 在 chrome 中,它运行完美。但是,在 Firefox 中,图像不会出现。 我已经设置了 SVG 的 mime 类型,并且 mime 类型检查器显示 mime 类型是正确的。 有人能帮帮
我是一名优秀的程序员,十分优秀!