栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

16位数据均值处理c++代码

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

16位数据均值处理c++代码

void MeanFilterSize(unsigned short *input,unsigned short *output,int ksize,int width,int height)
{
	//CV_Assert(ksize % 2 == 1);
	int *kernel = new int[ksize*ksize];

	for (int i = 0; i < ksize*ksize; i++)         // 均值滤波所以都为1
		kernel[i] = 1;

	int len = ksize / 2;

	int ptwidth = width +len*2;
	int ptheight = height +len*2;
	unsigned short* pt = new unsigned short[ptwidth*ptheight];

	memset(pt,0, ptheight*ptwidth*sizeof(unsigned short));
	//memcpy(pd, input, height*width * sizeof(unsigned short));
	

	int channel=1;

	for (int row = 0; row < ptheight; row++)//添加边框的过程
	{
		for (int col = 0; col < ptwidth; col++)
		{
			for (int c = 0; c < channel; c++)
			{
				if (row >= len && row < ptheight - len && col >= len && col < ptwidth - len)
					pt[(ptwidth* row + col)*channel + c] = input[(width * (row - len) + col - len) * channel + c];
				else
					pt[(ptwidth * row + col)*channel + c] =32768;
			}
		}
	}


	//创建结果矩阵
	unsigned short* pd = new unsigned short[width*height];
	memset(pd, 32768, height*width * sizeof(unsigned short));
	//memcpy(pd, input, height*width * sizeof(unsigned short));
	for (int row = len; row < ptheight - len; row++)//卷积的过程
	{
		for (int col = len; col < ptwidth - len; col++)
		{
			for (int c = 0; c < channel; c++)
			{
				float t = 0;
				for (int x = -len; x <= len; x++)
				{
					for (int y = -len; y <= len; y++)
					{
						//cout << "v=" << pt[((row + x) * ptwidth + col + y) * channel + c] << endl;
						t += kernel[(len + x) * ksize + y + len] *(double) pt[((row + x) * ptwidth + col + y) * channel + c];
					}
				}
				//cout << "vbalue- " << unsigned short(t / (ksize*ksize)) << endl;
				pd[(width * (row - len) + col - len) * channel + c] = unsigned short(t / (ksize*ksize*1.0));//防止数据溢出ushort是16为数据
			}
		}
	}

	memcpy(output,pd,width*height*sizeof(unsigned short));


	delete[] pd;
	delete[] pt;
	delete[] kernel;
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1030591.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号