- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
基本上,我有这样一张图片
或在同一图像中具有多个矩形的图像。矩形完全是黑色和白色,有“脏”的边缘和凹痕,但很容易看出它们是矩形。更准确地说,它们是图像蒙版。白色区域是要“单独保留”的图像部分,但黑色部分要变成双色调。
我的问题是,如何从这个退化的矩形中制作出漂亮而清晰的矩形?我是 Python 专家,但我必须使用 Qt 和 C++ 来完成这项任务。如果不使用其他库会更可取。
谢谢!
最佳答案
如果包含所有非黑色像素的边界框可以执行您想要的操作,那么这应该可以解决问题:
int boundLeft = INT_MAX;
int boundRight = -1;
int boundTop = INT_MAX;
int boundBottom = -1;
for(int y=0;y<imageHeight;++y) {
bool hasNonMask = false;
for(int x=0;x<imageWidth;++x) {
if(isNotMask(x, y)) {
hasNonMask = true;
if(x < boundLeft) boundLeft = x;
if(x > boundRight) boundRight = x;
}
}
if(hasNonMask) {
if(y < boundTop) boundTop = y;
if(y > boundBottom) boundBottom = y
}
}
如果结果的大小为负数,则图像中没有非 mask 像素。代码可以更优化,但我还没有喝够咖啡。 :)
关于c++ - 如何修复腐 eclipse 的矩形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4841086/
在浏览 OpenCV 源代码时,我注意到对于不止一次的迭代,它只会创建一个更大尺寸的内核并进行一次迭代。 所以我的问题是,如果我们采用 3x3 大小的 SQUARE 结构元素并在三个迭代中对其进行扩张
我无法理解 scipy 的 binary_erosion 函数。 from scipy.ndimage import binary_erosion a = np.zeros([12,12]) a[1:
我有这个代码。 #include "opencv2/objdetect/objdetect.hpp" #include "opencv2/highgui/highgui.hpp" #include "
我正在对 Mat 应用腐 eclipse 操作,但速度非常慢。 因为在 OpenCV 中,您可以通过两种不同的方式应用它(使用 morphologyEx 和使用 erode)。 我正在测量(大约)它的
二值图像上的腐 eclipse 会减少白色区域,而膨胀会增加它。我使用 OpenCV 在彩色图像上进行了相同的尝试,并得到了类似的结果。我尝试对二进制 jpeg 图像进行侵 eclipse /膨胀。由
我在安卓设备上同时使用 OpenCV 和 FastCV 来执行一些图像处理操作。对帧进行阈值处理后,我得到了一张二值图像,在感兴趣区域附近存在适量的黑白噪声。 对图像进行腐 eclipse ,然后进行
如果用 zeros(3,3) 结构元素腐 eclipse 图像,它应该全为 1,但在 OpenCV 的情况下,它返回图像。类似地,用 zeros(3,3) 结构元素对图像进行膨胀会返回图像本身,而不是
我是图像处理新手,正在尝试编写一种用于腐 eclipse 和膨胀的自定义方法。然后我尝试将我的结果与 OpenCV 腐 eclipse 和膨胀函数结果进行比较。我对输入图像进行一处零填充,然后将内核与
我已经尝试过并且有效。如果迭代次数足够大,就会出现显着的变化。 我不明白的是它是如何完成的。 是否有默认的内核形状和大小?可能是 MORPH_RECT 和 (2,2)? 最佳答案 从这里开始Link
我有一个很长的项目:一个在浏览器中运行并使用 SVG 和 Javascript 的基本矢量图形工具(也许你已经在其他地方看到过这些)。该工具只有非常有限的一组功能,因为受众受到限制并且目的非常具体,实
我正在为 OpenGL 编写一个简单的位图字体渲染器,我也想渲染一些 Unicode。然而,在许多字体中,一些字符丢失并呈现为正方形。这些因此浪费了我纹理中的空间,我想摆脱它们。有没有WinAPI函数
我是一名优秀的程序员,十分优秀!