Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image stitching SimpleCV: colorspace changes after warping

I am using SimpleCV to stitch images. I have made some changes in SimpleCV's GitHub code and eventually got the image transformed correctly. But the problem is, the color of the image after getting transformed is changed.

I have used these images http://imgur.com/a/lrGw4. The output of my code is: http://i.imgur.com/2J722h.jpg

This is my code:

from SimpleCV import *
import cv2
import cv

img1 = Image("s.jpg")
img2 = Image("t.jpg")

dst = Image((2000, 1600))

# Find the keypoints.
ofimg = img1.findKeypointMatch(img2)

# The homography matrix.
homo = ofimg[1]
eh = dst.getMatrix()

# transform the image.
x = Image(cv2.warpPerspective(np.array((img2.getMatrix())), homo,
  (eh.rows, eh.cols+300), np.array(eh), cv.INTER_CUBIC))

# blit the img1 now on coordinate (0, 0).
x = x.blit(img1, alpha=0.4)
x.save("rishi1.jpg")
like image 873
Rishi Avatar asked Oct 23 '22 02:10

Rishi


1 Answers

It seems you're using an old revision of SimpleCV. In the latest version the way to get the homography matrix is [1]:

ofimg[0].getHomography()

Edit:

It seems the color problem you're mentioning is due to the change of color space. So please change the line you warp the image to:

x = Image(cv2.warpPerspective(np.array((img2.getMatrix())), homo,
  (eh.rows, eh.cols+300), np.array(eh), cv.INTER_CUBIC), colorSpace=ColorSpace.RGB).toBGR()

I suspect what's happening is that the returned image after warping is in the BGR color space while SimpleCV by default uses the RGB color space. Please let me know how it goes.

like image 71
fireant Avatar answered Oct 27 '22 09:10

fireant