将一幅图像取平均值缩小N倍实现方法
2024-09-25 02:15:32
/// <summary>
/// 将图像缩小N倍
/// </summary>
/// <param name="source">原图数据</param>
/// <param name="height">原图高度</param>
/// <param name="width">原图宽度</param>
/// <param name="scale">缩小倍数</param>
/// <returns></returns>
public static ushort[] ImgNarrow(ushort[] source, int height, int width,int scale)
{
if (Convert.ToBoolean(height % scale) || Convert.ToBoolean(width % scale))
{
throw new Exception("高宽必须为" + scale + "的倍数");
}
ushort[] dest = new ushort[height * width / (scale * scale)];
int n = ;
for (int y = ; y < height; y = y + scale)
{
for (int x = ; x < width; x = x + scale)
{
int index = y * width + x;
int sum = ;
for (int i = ; i < scale; i++)
{
for (int j = ; j < scale; j++)
{
sum += source[index + i * width + j];
}
}
dest[n] = Convert.ToUInt16(sum / (scale * scale));
n++;
}
}
return dest;
}
原图是灰度数据,最终的目的是将图像缩小了N倍,然后取周围N*N个点的灰度平均值作为新图像的值,目前这个实现复杂度有点高,有更优解请评论回复
最新文章
- deepsooncms在Ubuntu 14.04上部署教程
- C语言 独木舟问题
- tp5 model 的数据自动完成
- AdminLTE 2 开源模版
- bootstrap-datetimepicker.js 设置开始时间的Bug。
- [Java面试八]Hibernate总结以及在面试中的一些问题.
- Windows配置mycat
- iOS - Mac OS X 终端设置
- openstackM版本常见问题汇总
- Socket.IO 1.0 正式发布,快速可靠的实时引擎
- Windows下使用命令行设置ip地址的DNS服务器
- linux 安装apahce的configure: error: APR not found. Please read the documentation解决办法
- Android百度地图开发03之地图控制 + 定位
- Spring事务传播特性的浅析——事务方法嵌套调用的迷茫
- Ubuntu 源
- 查找附近网点geohash算法及实现 (Java版本号)
- spring jdbc 源码
- oracle 数据库中的序列
- 【洛谷P1090 合并果子】
- 论文笔记【三】A Deep Dive into Word Sense Disambiguation with LSTM
热门文章
- postman抓包工具与kap项目部署(新猿旺学习总结)
- 1.4:SubShader
- APScheduler
- MySQL 增删改查
- Spring Boot 数据库连接池 HikariCP
- Maven解决包冲突
- Eclipse使用Maven,创建项目出现:Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resour
- matlab 入门
- 树莓派3代刷ubuntu mate在命令行下配置wifi不能连接的一个诡异的bug的解决
- webgl学习