网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事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