- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我在使用 Sobel 算子进行边缘检测时遇到问题:它会产生太多假边缘,效果如下图所示。我正在使用 3x3 sobel 运算符 - 首先提取垂直然后水平,最终输出是每个滤波器输出的幅度。合成图像的边缘被正确提取,但自然图像产生的错误边缘或“噪声”太多,即使图像已通过应用模糊或中值滤波器进行预处理。这可能是什么原因造成的?是实现问题(然后:为什么合成图像很好?)还是我需要做更多的预处理?
原文:
输出:
代码:
void imageOp::filter(image8* image, int maskSize, int16_t *mask)
{
if((image == NULL) || (maskSize/2 == 0) || maskSize < 1)
{
if(image == NULL)
{
printf("filter: image pointer == NULL \n");
}
else if(maskSize < 1)
{
printf("filter: maskSize must be greater than 1\n");
}
else
{
printf("filter: maskSize must be odd number\n");
}
return;
}
image8* fImage = new image8(image->getHeight(), image->getWidth());
uint16_t sum = 0;
int d = maskSize/2;
int ty, tx;
for(int x = 0; x < image->getHeight(); x++) //
{ // loop over image
for(int y = 0; y < image->getWidth(); y++) //
{
for(int xm = -d; xm <= d; xm++)
{
for(int ym = -d; ym <= d; ym++)
{
ty = y + ym;
if(ty < 0) // edge conditions
{
ty = (-1)*ym - 1;
}
else if(ty >= image->getWidth())
{
ty = image->getWidth() - ym;
}
tx = x + xm;
if(tx < 0) // edge conditions
{
tx = (-1)*xm - 1;
}
else if(tx >= image->getHeight())
{
tx = image->getHeight() - xm;
}
sum += image->img[tx][ty] * mask[((xm+d)*maskSize) + ym + d];
}
}
if(sum > 255)
{
fImage->img[x][y] = 255;
}
else if(sum < 0)
{
fImage->img[x][y] = 0;
}
else
{
fImage->img[x][y] = (uint8_t)sum;
}
sum = 0;
}
}
for(int x = 0; x < image->getHeight(); x++)
{
for(int y = 0; y < image->getWidth(); y++)
{
image->img[x][y] = fImage->img[x][y];
}
}
delete fImage;
}
最佳答案
这似乎是由于您的代码中某处存在数学错误。按照我的评论,这是我在此处通过 Sobel 运算符运行您的图像时得到的结果(边缘强度由输出图像的亮度表示):
我使用了 GLSL 片段着色器来生成这个:
precision mediump float;
varying vec2 textureCoordinate;
varying vec2 leftTextureCoordinate;
varying vec2 rightTextureCoordinate;
varying vec2 topTextureCoordinate;
varying vec2 topLeftTextureCoordinate;
varying vec2 topRightTextureCoordinate;
varying vec2 bottomTextureCoordinate;
varying vec2 bottomLeftTextureCoordinate;
varying vec2 bottomRightTextureCoordinate;
uniform sampler2D inputImageTexture;
void main()
{
float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r;
float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r;
float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r;
float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r;
float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r;
float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r;
float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r;
float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r;
float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity;
float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity;
float mag = length(vec2(h, v));
gl_FragColor = vec4(vec3(mag), 1.0);
你没有显示你的掩码值,我假设它包含 Sobel 内核。在上面的代码中,我硬编码了针对 3x3 Sobel 内核中每个像素的红色 channel 执行的计算。这纯粹是为了在我的平台上表现。
我在您的代码中没有注意到的一件事(同样,我可能会遗漏它,就像我将总和设置回 0 一样)是确定 Sobel 运算符的两个部分的 vector 大小。如果存在的话,我希望能在某处看到平方根运算。
关于c++ - sobel 算子 - 假边自然图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13363918/
我尝试用java实现Sobel边缘检测。它有点有效,但我收到了很多看似随机的噪音...... 我将图像加载为 BufferedImages 并首先将其转换为灰度图像(通过我在网上找到的算法)。之后我计
我尝试在 Java 中实现 Sobel 运算符,但结果只是一些像素的混合。 int i, j; FileInputStream inFile = new FileInputStream
我有每个像素的 Sobel 算子的梯度。在我的例子中是 320x480。但是我怎样才能将它们与方向联系起来呢?例如,我打算绘制指纹方向图。那么,我该如何开始呢? 是将梯度分成 block (例如 16
我为 Sobel 运算符编写了一个用于边缘检测的类,但是当我使用示例图像时,我的边缘消失了。如果有人可以帮助我,我将不胜感激。 import java.awt.image.BufferedImage;
x-导数 Sobel 看起来是这样的: -1 0 +1 -2 0 +2 -1 0 +1 假设我的图像有两个样本看起来像这样(0=黑色,1=白色): 0 0 1 1 0 0 0 0
我正在使用图像上的索贝尔边缘检测进行作业。我目前正在努力进行渐变操作。编译时收到“二元运算符 '*' 的操作数类型错误”错误。我认为这可能是因为我将所有像素定义为字母,并且我不确定下一步应该是什么。任
我的 Sobel 边缘检测算子的输出很奇怪。这是我的代码: BufferedImage temp = img; float kernelx[][] = {{-1, 0, 1},{-2,
我想在我的 android 应用程序中使用 Sobel 运算符。但是我不明白如何使用一个像素。 int sobel_x[][] = {{-1, 0, 1}, {-2, 0, 2},
我想在图像上使用高斯模糊作为使用 sobel 边缘检测过滤器的预处理步骤。 我以前在灰度图像上有效地实现了 sobel 和高斯模糊运算符,但是,我从未尝试过在彩色图像上使用它们。 之前,我一直采用像素
对于嵌入式设计,我试图在不使用缓冲器的情况下在板上实现索贝尔边缘检测。即我直接从屏幕上阅读和写作。但是,我可以存储大约一两个图像宽度的数据以供以后引用。这是由于董事会规定的限制。但是我陷入了一些问题。
这个问题不太可能帮助任何 future 的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况有关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visit
我试图理解 cv2.Sobel 中的 scale 参数.将 scale 设置为 1/8,我沿 x 轴得到如下输出: 但是对于 scale = 10 或 scale = 100,输出非常相似。 上面两幅
我正在使用 sobel 运算符通过 EmguCV 3.0(OpenCV 的 .NET 包装器)检测灰度图像中的边缘。 我使用的代码是 Image gray = new Image(@"C:\gray.
我正在使用 skimage 创建一个与此类似的 sobel 过滤器图像... 我想知道有没有办法锐化这个 sobel 滤镜图像?比如说,把那些比较淡的白线去掉,比如气球后面的淡淡的线条? 我用 Ski
OpenCV 文档说,(order == 0) 表示不会在这个方向上应用导数,即不会执行此内核的计算。 (Order == 1) 意味着这个方向的图像和内核只是一个简单的卷积。 但是 (order =
我想在文本中找到笔划的方向。 Sobel 算子如何用于此目的? 这张图显示的是dp,也就是梯度方向。我想知道如何应用 Sobel 运算符找到要选择的像素,从 p 到 q,沿着路径 sp,到找到边缘上的
我正在尝试对墙壁图像使用 sobel 过滤器,但它不起作用。 我的代码是: im=scipy.misc.imread('IMG_1479bis.JPG') im = im.astype('int32'
阅读一篇论文,我很难理解所描述的算法: 给定手写样本的黑白数字图像,裁剪出单个字符进行分析。由于这可以是任意大小,因此算法需要考虑到这一点(如果更简单,我们可以假设大小为 2^n x 2^m)。 现在
我正在尝试在水平和垂直方向上实现 sobel 运算符。但不知何故我得到了反向输出。我在下面附上的代码。对于水平蒙版 char mask [3][3]= {{-1,-2,-1},{0,0,0},{1,
我在使用 Sobel 算子进行边缘检测时遇到问题:它会产生太多假边缘,效果如下图所示。我正在使用 3x3 sobel 运算符 - 首先提取垂直然后水平,最终输出是每个滤波器输出的幅度。合成图像的边
我是一名优秀的程序员,十分优秀!