2024年图像的腐蚀与膨胀之c++实现(qt + 不调包)_qimage膨胀腐蚀,2024年最新2024年春招C C++面试题

img
img

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

			for (int i = -sizeKernel / 2; i <= sizeKernel / 2; i++)
			{
				color = QColor(image->pixel(x + i, y + j));
				while (color.red() < k && kernel[sizeKernel / 2 + i][sizeKernel / 2 + j] && hr == 1)
				{
					hr = 0;
				}
				while (color.green() < k && kernel[sizeKernel / 2 + i][sizeKernel / 2 + j] && hg == 1)
				{
					hg = 0;
				}
				while (color.blue() < k && kernel[sizeKernel / 2 + i][sizeKernel / 2 + j] && hb == 1)
				{
					hb = 0;
				}
			}
		}
		if (hr == 0)
		{
			r = 0;
		}
		else
		{
			r = color.red();
		}
		if (hg == 0)
		{
			g = 0;
		}
		else
		{
			g = color.green();
		}
		if (hb == 0)
		{
			b = 0;
		}
		else
		{
			b = color.blue();
		}

		newImage->setPixel(x, y, qRgb(r, g, b));
	}
}
return newImage;

}

/采用最小描述算法,腐蚀处理/

QImage* MainWindow::Erosiontionrgb(QImage* image)
{
QImage* newImage = new QImage(image->width(), image->height(), QImage::Format_ARGB32);
int kernel[7][7] = {
{ 0,0,0,1,0,0,0 },
{ 0,1,1,1,1,1,0 },
{ 0,1,1,1,1,1,0 },
{ 1,1,1,1,1,1,1 },
{ 0,1,1,1,1,1,0 },
{ 0,1,1,1,1,1,0 },
{ 0,0,0,1,0,0,0 } };
int sizeKernel = 7;
QColor color;
QColor Rcolor;

for (int y = sizeKernel / 2; y < image->height() - sizeKernel / 2; y++)
{
	for (int x = sizeKernel / 2; x < image->width() - sizeKernel / 2; x++)
	{
		int kr = 255;
		int kg = 255;
		int kb = 255;
		Rcolor = QColor(image->pixel(x, y));
		for (int j = -sizeKernel / 2; j <= sizeKernel / 2; j++)
		{
			for (int i = -sizeKernel / 2; i <= sizeKernel / 2; i++)
			{
				color = QColor(image->pixel(x + i, y + j));
				while (color.red() < kr && kernel[sizeKernel / 2 + i][sizeKernel / 2 + j])
				{
					kr = color.red();
				}
				while (color.green() < kg && kernel[sizeKernel / 2 + i][sizeKernel / 2 + j])
				{
					kg = color.green();
				}
				while (color.blue() < kb && kernel[sizeKernel / 2 + i][sizeKernel / 2 + j])
				{
					kb = color.blue();
				}
			}
		}
		newImage->setPixel(x, y, qRgb(kr, kg, kb));
	}
}
return newImage;

}


#### **2.膨胀原理**


    图像的膨胀过程一般也是通过结构元素模板操作,有点类似于卷积运算,其具体过程:将结构模板在图像上滑动,如果结构模板任意有一个对应为1的点遇到图像上为1的点(此时图像已经被二值化了,如果是彩色图像,可以通过和阈值比大小),那么该点的像素值可以被设置为1;还有一种腐蚀方法:依次对结构元素模板中所有为1的位置对应的像素进行检测,取出其中的最大值max,将当前结构元素所在位置的像素值置为max。腐蚀的作用是扩展物体的边界点和连接临近区域。



/采用二值图算法,定义阈值K,对于灰度大于k的像素认为存在&#x

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值