如何使用SIFT算法与彩色反转的图像 [英] How to use SIFT algorithm with a color inverted image

查看:506
本文介绍了如何使用SIFT算法与彩色反转的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如我有两个图像,其中第一个是定期,第二个用彩色反转(我的意思是255 - 像素的颜色值)。

For example I have two images, where first one is a regular and second one with a color inversion (I mean 255 - pixel color value).

我已经应用OpenCV的使用和洛文SIFT算法,他们两人,所以现在我有每个图像的关键点和描述符。

I've applied SIFT algorithm to both of them using OpenCV and Lowe paper, so now I have key points and descriptors of each image.

关键点位置做匹配,但关键点的方向和描述符值,这样做,因为颜色反转的不是。

KeyPoints positions do match, but KeyPoints orientations and Descriptors values do not, because of color inversion.

我很好奇,也有人试图解决这样的问题?

I'm curious do anybody try to solve such a problem?

除了 这里有梯度的例子:

In addition here are the gradients example:

我用OpenCV的C ++实现使用的教程和模块/非自由/ src目录/ sift.cpp文件。另外我做了下面的方法来看待梯度:

I'm using OpenCV C++ implementation using this tutorial and modules/nonfree/src/sift.cpp file. In addition I've made the following method to look at gradients:

void MINE::showKeypoints(cv::Mat image, std::vector<cv::KeyPoint> keypoints, string number)
{
    cv::Mat img;
    image.copyTo(img);

    for(int i=0;i<(int)keypoints.size();i++)
    {
        cv::KeyPoint kp = keypoints[i];

        cv::line(img, cv::Point2f(kp.pt.x ,kp.pt.y), cv::Point2f(kp.pt.x ,kp.pt.y), CV_RGB(255,0,0), 4);
        cv::line(img, cv::Point2f(kp.pt.x ,kp.pt.y), cv::Point2f(kp.pt.x+kp.size*cos(kp.angle),kp.pt.y+kp.size*sin(kp.angle)), CV_RGB(255,255,0), 1);
    }
    cv::imshow (str, img);
}

梯度的示例

Example of the gradients.

正如你所看到的倒置和原始图像渐变不是相反

As you can see gradients of inverted and original images are not opposite

推荐答案

如果您否定输入图像,然后梯度将有相反的方向 G&LT; - -G )。

If you negate the input image then the gradients will have opposite directions (G <- -G).

您需要提醒的是SIFT描述基本上是梯度方向的直方图:

You need to remind that SIFT descriptors are basically histogram of gradient orientations:

由于坡度是否定的倒影上,我们得到:

Since the gradient is negated on the inverted image we obtain:

  • 0号箭头=&GT; 4箭头
  • 第一个箭头=&GT; 5箭头
  • 第二个箭头=&GT; 6箭头
  • 3TH箭头=&GT; 7箭头
  • 0th arrow => 4th arrow
  • 1st arrow => 5th arrow
  • 2nd arrow => 6th arrow
  • 3th arrow => 7th arrow

在换句话说,如果你考虑的第一个8-箱直方图(还有4×4这样的直方图计),如果你表示 A b 等相关SIFT描述符组成部分,我们有:

In other words if you consider the first 8-bins histogram (there are 4x4 such histograms in total), and if you denote a, b, etc the related SIFT descriptors components, we have:

  • 在原始图像: [A,B,C,D,E,F,G,H]
  • 倒象: [E,F,G,H,A,B,C,D]
  • original image: [a, b, c, d, e, f, g, h]
  • inverted image: [e, f, g, h, a, b, c, d]

所以,你可以通过4大小的包交换的组件转换倒影SIFT描述符。

So you can convert the inverted image SIFT descriptor by swapping the components by 4-sized packs.

伪算法:

# `sift` is the 128-sized array that represents the descriptor
NCELLS = 16
NORI   = 8

0.upto(NCELLS - 1) do |cell|
  offset = cell * NORI
  offset.upto(offset + NORI/2 - 1) do |i|
    sift.swap!(i, i + NORI/2)
  end
end


下面是如何对此进行验证 vlfeat

  1. 否定默认图像:转换-negate default.pgm negate.pgm
  2. 在默认的图像
  3. 提取关键点: ./筛--frames default.pgm
  4. 选择的第一个关键点:尾-n 1 default.frame&GT; kpt.frame
  5. 的默认图像描述它: ./筛--descriptors --read帧kpt.frame default.pgm
  6. 与否定形象描述它: ./筛--descriptors --read帧kpt.frame negate.pgm
  7. 格式可以描述符,每行4组件(见下文)
  1. Negate the default image: convert -negate default.pgm negate.pgm
  2. Extract keypoints on default image: ./sift --frames default.pgm
  3. Select the first keypoint: tail -n 1 default.frame > kpt.frame
  4. Describe it with the default image: ./sift --descriptors --read-frames kpt.frame default.pgm
  5. Describe it with the negated image: ./sift --descriptors --read-frames kpt.frame negate.pgm
  6. Format both descriptors with 4 components per line (see below)

然后用形象化例如输出差异-u 了opendiff :该行换2×2的预期

Then visualize the output with e.g. diff -u or opendiff: the lines are swapped 2-by-2 as expected.

cat default.descr | ruby -e\
'STDIN.read.split(" ").each_slice(4) {|s| p s}'\
> default.out

cat negate.descr | ruby -e\
'STDIN.read.split(" ").each_slice(4) {|s| p s}'\
> negate.out

这篇关于如何使用SIFT算法与彩色反转的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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