2012-04-16 80 views
5

我正在使用SimpleCV来拼接图像。我在SimpleCV的GitHub代码中做了一些改变,并最终正确地转换了图像。但问题是,变换后图像的颜色会发生变化。图像拼接SimpleCV:变形后的颜色空间变化

我已经使用了这些图像http://imgur.com/a/lrGw4。我的代码的输出是:http://i.imgur.com/2J722h.jpg

这是我的代码:

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") 

回答

3

看来你使用SimpleCV的旧版本。在最新的版本,以获得单应矩阵的方式是[1]:

ofimg[0].getHomography() 

编辑:

好像你提的色差问题是由于颜色空间的变化。所以,请改变你的扭曲图像到行:

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

我怀疑发生的事情是,翘曲后返回的图像是在BGR颜色空间,同时SimpleCV默认使用RGB色彩空间。请让我知道它是怎么回事。

+0

我正在使用github的SimpleCV的最新版本。我这样做是因为我在SimpleCV的代码中做了一些改变。在此之前,单应性矩阵本身是错误的。但是现在图像完全变形了,但变换图像的颜色会发生变化。在findkeypointMatch函数中,我更改了一些代码。这是我执行的变更https://github.com/ingenuitas/SimpleCV/pull/63/files。但颜色问题也在之前。 – Rishi 2012-04-16 17:06:43

+0

我编辑了答案。我不能完全运行你的代码,但写了一个类似的脚本,发现问题是倒置的颜色空间。 – fireant 2012-04-18 05:54:15

+0

真棒.. :)。你的逻辑完美无缺。 :)。谢谢。 – Rishi 2012-04-18 13:43:16