梯度方向计算 [英] Gradient direction computation

查看:266
本文介绍了梯度方向计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在计算机视觉课程中完成我的任务。子任务之一是基于图像亮度的梯度方向计算。我做了一个矩阵明亮[宽度] [高度]包含图像的每个像素的亮度值。我有两个这样的函数:

I'm working on my task in computer vision course. One of sub-tasks is gradient direction computation based on image brightness. I've made a matrix bright[width][height] containing brightness values for every pixel of the image. And i have two such functions:

double Image::grad_x(int x,int y){
    if(x==width-1 || x==0) return bright[x][y];
    return bright[x+1][y]-bright[x-1][y];
}
double Image::grad_y(int x,int y){
    if(y==height-1 || y==0) return bright[x][y];
    return bright[x][y+1]-bright[x][y-1];
}

EDIT:边界检查固定

border check fixed

我使用简单的导数,不使用Sobel运算符,因为简单的导数足以满足我的需要。

I'm working with simple derivative, without using Sobel operator 'cause simple derivative is sufficient for my needs.

问题是,我正在做这个渐变计算权限,我究竟要做什么边框像素(现在函数返回像素本身的值,确定它的准确)?顺便说一句,有没有任何实用程序的图像的梯度的计算?

The question is, am i doing this gradient computation right and what exactly do i have to do with border pixels(right now function returns value of the pixel itself, im not sure it's accurate)? And, by the way, is there any utility for computation of gradients of the image? I want to be sure my program is performing well.

推荐答案

您的计算是正确的。这是一个简单的渐变方法,你使用,但如果这是罚款,你的使用没有什么错误。

Your computation is correct. It is a simple gradient method you're using, but if that's fine for your use there is nothing wrong with that.

这些角落是一个问题, t具有足够的数据来以与其他像素相同的方式计算梯度。处理它们的一种方法是简单地不计算边角情况,并以稍小的图像生活。

The corner cases are a problem because you don't have enough data to calculate a gradient in the same way as the other pixels. One way to deal with them is to simply not calculate the corner cases and live with a slightly smaller image.

如果这不是一个选项,你也可以外推丢失的数据。如果你假设梯度平滑地变化,它的工作原理是这样的:

If this is not an option you can also extrapolate the missing data. If you assume that the gradient changes smoothly it works like this:

在你的x梯度计算中,你可能已经计算了像素1的衍生物A和像素2的B.如果你想推断像素0的一个值(角的情况),可以使用值a-(ba)。

In your x-gradient calculations you may have calculated the derivate A for pixel 1 and B for pixel 2. If you want to extrapolate a value for pixel 0 (the corner case) the value a-(b-a) could be used.

一个数字示例:

  pixel1: gradient = 100
  pixel2: gradient = 80

  extrapolate using a-(b-a): 

  pixel0: gradient = 100 - (80-100)) = 120

这篇关于梯度方向计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆