15

I will use sift in identifying a certain type of object what if that object change in color can it recognize it? i will use opencv library for sift cv2.xfeatures2d.SIFT_create()

Noah Christopher
  • 166
  • 1
  • 13
jude
  • 360
  • 3
  • 12

2 Answers2

20

SIFT operates on grayscale images only. In the conclusion of Lowe's paper, he notes:

The features described in this paper use only a monochrome intensity image, so further distinctiveness could be derived from including illumination-invariant color descriptors (Funt and Finlayson, 1995; Brown and Lowe, 2002).

The OpenCV implementation converts color images to grayscale images before extracting features.

static Mat createInitialImage( const Mat& img, bool doubleImageSize, float sigma )
{
    /* ... */
    Mat gray, gray_fpt;
    if( img.channels() == 3 || img.channels() == 4 )
    {
        cvtColor(img, gray, COLOR_BGR2GRAY);
        gray.convertTo(gray_fpt, DataType<sift_wt>::type, SIFT_FIXPT_SCALE, 0);
    }
    else
        img.convertTo(gray_fpt, DataType<sift_wt>::type, SIFT_FIXPT_SCALE, 0);
    /* ... */
}
cyang
  • 5,574
  • 2
  • 25
  • 34
9

What have you tried so far? You could verify this with an experiment such as..

import cv2
img = cv2.imread('0.jpg',1) # 1 = read image as color
sift = cv2.xfeatures2d.SIFT_create()
kp = sift.detect(img,None)
img2 = cv2.drawKeypoints(img,kp,None)
cv2.imwrite('siftkpcolor.jpg',img2)

Then you can run the code again with the same image and do

import cv2
img = cv2.imread('0.jpg',0) # 0 = read image as gray
sift= cv2.xfeatures2d.SIFT_create()
kp = sift.detect(img,None)
img2 = cv2.drawKeypoints(img,kp,None)
cv2.imwrite("siftkpgray.jpg",img2)

Now you will have two images saved, one in color with keypoints drawn and another in gray with keypoints drawn. What do you see? I tried the above code with

>>>cv2.__version__
3.1.0-dev

Check my images below. This may not be as fined-grained as you want but it's a start. Most image processing applications tend to use grayscale because it is much less data to crunch than a full color image.

For a reference check these tutorials:

  1. why we should use gray scale for image processing
  2. http://docs.opencv.org/3.1.0/da/df5/tutorial_py_sift_intro.html
  3. http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_gui/py_image_display/py_image_display.html

Color KP

Gray KP

Community
  • 1
  • 1
Noah Christopher
  • 166
  • 1
  • 13
  • I guess just by inspection it is now enough I tried comparing the descriptors if des == des2: des for color and des2 for grayscale descriptors. it says it is not the same. although i dont know if the result is valid since i compare a multi dimensional array to another multidimenional array what do you think? – jude Nov 20 '16 at 01:49
  • I also used opencv 3.1.0 in python – jude Nov 20 '16 at 01:51
  • I'm not sure if the descriptors are deterministic each time the algorithm executes. What you could do is take a smaller/cropped image that has only a few features and manually inspect the results of des (color) and des ( gray) to see what you end up with. – Noah Christopher Nov 20 '16 at 03:28
  • is the color of the circles from the keypoints in your picture have any meaning or is it just to give distinction one from the other. it seems like it has the same keypoints but different color – jude Nov 20 '16 at 05:02
  • As far as I'm aware the color doesn't matter. You could also try `img=cv2.drawKeypoints(gray,kp,None,flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)` and I _believe_ the size of the circles will vary depending the key point orientation and magnitude using this flag. – Noah Christopher Nov 20 '16 at 11:49