Games202作业5(完结)

单帧降噪

也就是针对图像空间进行降噪

也就是我们需要在像素(i,j)的四周进行采样,然后将采样的权重加到一起,然后所有的权重和像素的乘积也加到一起,然后相除,得到最终滤波后的(i,j)像素期望的结果。

Buffer2D<Float3> Denoiser::Filter(const FrameInfo &frameInfo) {int height = frameInfo.m_beauty.m_height;int width = frameInfo.m_beauty.m_width;Buffer2D<Float3> filteredImage = CreateBuffer2D<Float3>(width, height);int kernelRadius = 16;#pragma omp parallel forfor (int y = 0; y < height; y++) {for (int x = 0; x < width; x++) {float sum_of_weight = 0.0;Float3 sum_of_weight_values(0.0);Float3 position_i = frameInfo.m_position(x, y);Float3 color_i = frameInfo.m_beauty(x, y);Float3 normal_i = frameInfo.m_normal(x, y);int boundary_x_max = std::min(kernelRadius + x, width);int boundary_x_min = std::max(0, x - kernelRadius);int boundary_y_max = std::min(kernelRadius + y, height);int boundary_y_min = std::max(y - kernelRadius, 0);for(int j_y = boundary_y_min; j_y < boundary_y_max; j_y++){for(int j_x = boundary_x_min; j_x < boundary_x_max; j_x++){Float3 position_j = frameInfo.m_position(j_x, j_y);Float3 color_j = frameInfo.m_beauty(j_x, j_y);Float3 normal_j = frameInfo.m_normal(j_x, j_y);//positionfloat p_w = - Dot(position_i - position_j, position_i - position_j) / (2.0 * m_sigmaCoord * m_sigmaCoord);//colorfloat c_w = - Dot(color_i - color_j, color_i - color_j) / (2.0 * m_sigmaColor * m_sigmaColor);//normalfloat n_w = - SafeAcos(Dot(normal_i, normal_j)) * SafeAcos(Dot(normal_i, normal_j)) / (2.0 * m_sigmaNormal * m_sigmaNormal);//planefloat pl_w = - (Dot(normal_i,(position_j - position_i) / std::max(SafeSqrt(Dot(position_j - position_i, position_j - position_i)), 0.0001f)) * Dot(normal_i,(position_j - position_i) / std::max(SafeSqrt(Dot(position_j - position_i, position_j - position_i)), 0.0001f))) / (2.0 * m_sigmaPlane * m_sigmaPlane);float weight = std::exp(p_w + c_w + n_w + pl_w);sum_of_weight += weight;sum_of_weight_values += (frameInfo.m_beauty(j_x, j_y) * weight);}}// TODO: Joint bilateral filterfilteredImage(x, y) = sum_of_weight_values / std::max(0.0001f,sum_of_weight);}}return filteredImage;
}

结果

滤波前:

非常大的噪声

滤波后:

非常的夸张了

投影到上一帧

首先我们需要求出motion vector来判断上一帧的像素位置来补充当前帧的对应像素的信息

  • 根据当前帧的当前像素的物体的编号求当前帧的像素对应物体的model矩阵
  • 求该物体上一帧的model矩阵
  • 求上一帧的screen坐标
  • 判断上一帧的screen坐标最终渲染出来的物体是不是该物体,不是就continue
  • 将上一帧的结果保存在m_accColor中
void Denoiser::Reprojection(const FrameInfo &frameInfo) {int height = m_accColor.m_height;int width = m_accColor.m_width;Matrix4x4 preWorldToScreen =m_preFrameInfo.m_matrix[m_preFrameInfo.m_matrix.size() - 1];//P矩阵Matrix4x4 preWorldToCamera =m_preFrameInfo.m_matrix[m_preFrameInfo.m_matrix.size() - 2];//V矩阵#pragma omp parallel forfor (int y = 0; y < height; y++) {for (int x = 0; x < width; x++) {m_valid(x, y) = false;m_misc(x, y) = Float3(0.f);auto current_position = frameInfo.m_position(x, y);int current_id = frameInfo.m_id(x, y);if(current_id == -1){continue;}Matrix4x4 currentModel = frameInfo.m_matrix[current_id];Matrix4x4 lastModel = m_preFrameInfo.m_matrix[current_id];Matrix4x4 currentModelInv = Inverse(currentModel);Float3 lastScreen = preWorldToScreen(preWorldToCamera(currentModelInv(current_position, Float3::Point), Float3::Point), Float3::Point);if(lastScreen.x <0 || lastScreen.x >= width || lastScreen.y < 0 || lastScreen.y >= height){continue;}int actualId = m_preFrameInfo.m_id(lastScreen.x, lastScreen.y);if(actualId == current_id){m_valid(x, y) = true;m_misc(x, y) = m_accColor(lastScreen.x, lastScreen.y);}// TODO: Reproject}}std::swap(m_misc, m_accColor);
}

累积多帧

首先我们需要计算均值和方差

Float3 mean(0.0);
for(int i = x_min; i < x_max; i++){for(int j = y_min; j < y_max; j++){mean += curFilteredColor(i, j);}
}
mean /= std::max(static_cast<float>((x_max - x_min) * (y_max - y_min)), 0.0001f);
Float3 variance(0.0);
for(int i = x_min; i < x_max; i++){for(int j = y_min; j < y_max; j++){variance += ((curFilteredColor(i, j) - mean) * (curFilteredColor(i, j) - mean));}
}
variance /= std::max(static_cast<float>((x_max - x_min) * (y_max - y_min)), 0.0001f);
Float3 sigma = SafeSqrt(variance);

然后混合计算:

void Denoiser::TemporalAccumulation(const Buffer2D<Float3> &curFilteredColor) {int height = m_accColor.m_height;int width = m_accColor.m_width;int kernelRadius = 3;
#pragma omp parallel forfor (int y = 0; y < height; y++) {for (int x = 0; x < width; x++) {// TODO: Temporal clampint x_min = std::max(0, x - kernelRadius);int x_max = std::min(width, x + kernelRadius);int y_min = std::max(0, y - kernelRadius);int y_max = std::min(height, y + kernelRadius);Float3 mean(0.0);for(int i = x_min; i < x_max; i++){for(int j = y_min; j < y_max; j++){mean += curFilteredColor(i, j);}}mean /= std::max(static_cast<float>((x_max - x_min) * (y_max - y_min)), 0.0001f);Float3 variance(0.0);for(int i = x_min; i < x_max; i++){for(int j = y_min; j < y_max; j++){variance += ((curFilteredColor(i, j) - mean) * (curFilteredColor(i, j) - mean));}}variance /= std::max(static_cast<float>((x_max - x_min) * (y_max - y_min)), 0.0001f);Float3 sigma = SafeSqrt(variance);Float3 color = m_accColor(x, y);Float3 color_last = Clamp(color, mean - sigma * m_colorBoxK, mean + sigma * m_colorBoxK);float alpha = 1.0f;if(m_valid(x, y)){alpha = m_alpha;}// TODO: Exponential moving averagem_misc(x, y) = Lerp(color_last, curFilteredColor(x, y), alpha);}}std::swap(m_misc, m_accColor);
}

用A-Trous Wavelet加速单帧降噪

其实就是膨胀卷积原理,间隔采样

Buffer2D<Float3> Denoiser::Valelt_Filter(const FrameInfo &frameInfo) {int height = frameInfo.m_beauty.m_height;int width = frameInfo.m_beauty.m_width;Buffer2D<Float3> filteredImage = CreateBuffer2D<Float3>(width, height);int kernelRadius = 16;
#pragma omp parallel forfor (int y = 0; y < height; y++) {for (int x = 0; x < width; x++) {float sum_of_weight = 0.0;Float3 sum_of_weight_values(0.0);Float3 position_i = frameInfo.m_position(x, y);Float3 color_i = frameInfo.m_beauty(x, y);Float3 normal_i = frameInfo.m_normal(x, y);int boundary_x_max = std::min(kernelRadius + x, width);int boundary_x_min = std::max(0, x - kernelRadius);int boundary_y_max = std::min(kernelRadius + y, height);int boundary_y_min = std::max(y - kernelRadius, 0);for(int pass = 0; pass < 5; pass++){for(int i_left = -2; i_left <=2 ;i_left++){for(int j_left = -2; j_left <= 2; j_left ++){int j_x = x + i_left * std::pow(pass,2);int j_y = y + j_left * std::pow(pass,2);Float3 position_j = frameInfo.m_position(j_x, j_y);Float3 color_j = frameInfo.m_beauty(j_x, j_y);Float3 normal_j = frameInfo.m_normal(j_x, j_y);//positionfloat p_w = - Dot(position_i - position_j, position_i - position_j) / (2.0 * m_sigmaCoord * m_sigmaCoord);//colorfloat c_w = - Dot(color_i - color_j, color_i - color_j) / (2.0 * m_sigmaColor * m_sigmaColor);//normalfloat n_w = - SafeAcos(Dot(normal_i, normal_j)) * SafeAcos(Dot(normal_i, normal_j)) / (2.0 * m_sigmaNormal * m_sigmaNormal);//planefloat pl_w = - (Dot(normal_i,(position_j - position_i) / std::max(SafeSqrt(Dot(position_j - position_i, position_j - position_i)), 0.0001f)) * Dot(normal_i,(position_j - position_i) / std::max(SafeSqrt(Dot(position_j - position_i, position_j - position_i)), 0.0001f))) / (2.0 * m_sigmaPlane * m_sigmaPlane);float weight = std::exp(p_w + c_w + n_w + pl_w);sum_of_weight += weight;sum_of_weight_values += (frameInfo.m_beauty(j_x, j_y) * weight);}}}// TODO: Joint bilateral filterfilteredImage(x, y) = sum_of_weight_values / std::max(sum_of_weight, 0.0001f);}}return filteredImage;
}

使用A-Trous Wavelet之后:

使用A-Trous Wavelet之前:

没加temporal和filter:

但是速度从10秒提升到了1秒一帧

所有作业代码(作业2被我弄不见了....)

lhjackgod/games202

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/56907.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

P4可编程技术详解:从理论到硬件实现

P4的诞生 为打破传统的固定封装模式&#xff0c;充分解放数据平面的编程能力&#xff0c;Nick McKeown领导的斯坦福大学研究团队于2014年提出可编程处理语言P4。借助P4的数据平面编程能力&#xff0c;用户可在网卡、交换机、路由器等网络设备上实现包括VXLAN、MPLS等在内的各种…

电影评论网站开发:Spring Boot技术指南

3系统分析 3.1可行性分析 通过对本电影评论网站实行的目的初步调查和分析&#xff0c;提出可行性方案并对其一一进行论证。我们在这里主要从技术可行性、经济可行性、操作可行性等方面进行分析。 3.1.1技术可行性 本电影评论网站采用SSM框架&#xff0c;JAVA作为开发语言&#…

Linux文件的查找和打包以及压缩

文件的查找 文件查找的用处&#xff0c;在我们需要文件但却又不知道文件在哪里的时候 文件查找存在着三种类型的查找 1、which或whereis&#xff1a;查找命令的程序文件位置 2、locate&#xff1a;也是一种文件查找&#xff0c;但是基于数据库的查找 3、find&#xff1a;针…

基于SpringBoot+Vue+uniapp微信小程序的社区门诊管理系统的详细设计和实现(源码+lw+部署文档+讲解等)

项目运行截图 技术框架 后端采用SpringBoot框架 Spring Boot 是一个用于快速开发基于 Spring 框架的应用程序的开源框架。它采用约定大于配置的理念&#xff0c;提供了一套默认的配置&#xff0c;让开发者可以更专注于业务逻辑而不是配置文件。Spring Boot 通过自动化配置和约…

01 设计模式-创造型模式-工厂模式

工厂模式&#xff08;Factory Pattern&#xff09;是 Java 中最常用的设计模式之一&#xff0c;它提供了一种创建对象的方式&#xff0c;使得创建对象的过程与使用对象的过程分离。 工厂模式提供了一种创建对象的方式&#xff0c;而无需指定要创建的具体类。 通过使用工厂模式…

1.2.3 TCP IP模型

TCP/IP模型&#xff08;接网叔用&#xff09; 网络接口层 网络层 传输层 应用层 理念&#xff1a;如果某些应用需要“数据格式转换”“会话管理功能”&#xff0c;就交给应用层的特定协议去实现 tip&#xff1a;数据 局部正确不等于全局正确 但是&#xff0c;数据的 全局正…

数码准备记录

1.数据结构 常见的数据结构包括数组、链表、栈、队列、树&#xff08;如二叉树、B树、B树&#xff09;、图等 2.队列和栈的区别 队列是一种先入先出的数据结构&#xff0c;即最先加入的元素被最先移除&#xff1b; 栈是一种后进后出的数据结构&#xff0c;即最后加入的元素…

RTMP协议分析

理论 总体介绍 RTMP协议是应⽤层协议&#xff0c;是要靠底层可靠的传输层协议&#xff08;通常是TCP&#xff09;来保证信息传输的可靠性的。在基于传输层协议的链接建⽴完成后&#xff0c;RTMP协议也要客户端和服务器通过“握⼿”来建⽴基于传输层链接之上的RTMP Connection链…

Collection 单列集合 List Set

集合概念 集合是一种特殊类 ,这些类可以存储任意类对象,并且长度可变, 这些集合类都位于java.util中,使用的话必须导包 按照存储结构可以分为两大类 单列集合 Collection 双列集合 Map 两种 区别如下 Collection 单列集合类的根接口,用于存储一系列符合某种规则的元素,它有两…

Electron-(二)桌面应用的启动动画创建

一、概述 在很多桌面应用中都会有启动画面的显示。启动画面可以解决在启动时耗时较长&#xff0c;将每一步反馈给用户。另外一方面解决启动过程中的环境检查及检查结果的反馈。 在当今的桌面应用领域&#xff0c;启动动画已成为提升用户体验的重要组成部分。它不仅仅是一个简单…

【Linux】main函数的参数列表从何而来?

Linux系统进程通过exec系列函数启动新程序时&#xff0c;argc整型 、 argv数组 和 环境变量表 environ 会作为 exec 系列函数的参数&#xff0c;显式传递给新程序的 main 函数。 main函数的参数列表 在C语言中&#xff0c;main函数的标准参数列表通常如下所示&#xff1a; in…

极客wordpress模板

这是一个展示WordPress主题的网页设计。页面顶部有一个导航栏&#xff0c;包含多个选项&#xff0c;如“关于我们”、“产品中心”、“案例展示”、“新闻动态”、“联系我们”和“技术支持”。页面中间部分展示了多个产品&#xff0c;每个产品都有一个图片和简短的描述。页面下…

MySQL【知识改变命运】06

前言&#xff1a;在05这节数据结构里面&#xff0c;我们知道select * from 这个操作很危险&#xff0c;如果数据库很大&#xff0c;会把服务器资源耗尽&#xff0c;接下来提到的查询可以有效的限制返回记录 1&#xff1a;分页查询 分页查询可以有效控制一次查询出来的结果集的…

【CTF刷题9】2024.10.19

[MoeCTF 2021]babyRCE 考点&#xff1a;关键词过滤&#xff08;绕过方法参考往期博客&#xff09; 来源&#xff1a;nssctf <?php$rce $_GET[rce]; if (isset($rce)) {if (!preg_match("/cat|more|less|head|tac|tail|nl|od|vi|vim|sort|flag| |\;|[0-9]|\*|\|\%|\&g…

图像中的数值计算

目录 图像读取与形状图像数据展示图像数据操作超出范围的像素值处理 图像读取与形状 使用cv2.imread函数读取图像文件。图像的形状通过shape属性获取&#xff0c;格式为(高度, 宽度, 颜色通道数)。 import cv2img1 cv2.imread(bg.jpg) img2 cv2.imread(fish.jpg)print(img1…

Linux服务器安装SRAToolkit教程

SRAToolkit是由NCBI&#xff08;美国国家生物技术信息中心&#xff09;提供的一个工具集&#xff0c;用于下载、读取和转换SRA&#xff08;Sequence Read Archive&#xff09;格式的数据文件。这些数据文件包含了大规模的核酸序列数据&#xff0c;对于基因组学研究至关重要。本…

pytorch激活函数介绍

在 PyTorch 中,激活函数(Activation Functions)是神经网络中重要的非线性组件,用于引入非线性,使网络能够学习复杂的函数关系。以下是 PyTorch 中常见的激活函数及其特点: 1. ReLU (Rectified Linear Unit) 函数: torch.nn.ReLU()公式: ReLU(x)=max⁡(0,x)特点: 常用于隐…

python-代码技巧

python-代码技巧 简单tips1、多个列表循环遍历2、使用map对列表中多个文件进行批量操作 仅个人笔记使用&#xff0c;感谢点赞关注 简单tips 1、多个列表循环遍历 dataTypes ["train","test"] dataStations ["1","2","3"…

【C语言】自定义类型:结构体--结构体内存对齐(用于计算结构体的大小)

结构体内存对齐 结构体内存对齐用于计算结构体的大小。 &#xff08;1&#xff09;对齐规则 1&#xff09;&#xff09;结构体的第一个成员对齐到和结构体变量起始位置偏移量为0的地址处。 2&#xff09;&#xff09;其他成员变量要对齐到某个数字&#xff08;对齐数&#…

FFmpeg 4.3 音视频-多路H265监控录放C++开发四 :RGB颜色

一 RGB 的意义&#xff1f; 为什么要从RGB 开始讲起呢&#xff1f; 因为最终传输到显卡显示器的颜色都是RGB 即使能处理YUV的API&#xff0c;本质上也是帮你做了从 YUV 到 RGB的转换。 RGB888 表示 R 占8bit&#xff0c;G 占8bit&#xff0c;B 占8bit&#xff0c;也就是每一…