使用java和opencv进行灰度图像的图像融合给出了奇怪的结果

问题描述 投票:1回答:1

我目前正在尝试使用java和OpenCV包装器融合放射灰度图像。我写了一些代码来在数据库中找到相似的图像并融合它们。融合部分是我在努力的地方。这是我正在努力的方法:

public BufferedImage registerImages(BufferedImage source, BufferedImage target) 
throws RegistrationException{

    LinkedList<DMatch> goodMatches = getGoodMatches(source, target);
    if(goodMatches.size() >= 7){
         List<KeyPoint> sourceKeypoints = sourceKeyPointsMat.toList();
        List<KeyPoint> targetKeypoints = targetKeyPointsMat.toList();

        LinkedList<Point> sourcePoints = new LinkedList<>();
        LinkedList<Point> targetPoints = new LinkedList<>();

        for(int i = 0; i < goodMatches.size(); i++) {
            sourcePoints.addLast(sourceKeypoints.get(goodMatches.get(i).queryIdx).pt);
            targetPoints.addLast(targetKeypoints.get(goodMatches.get(i).trainIdx).pt);
        }

        MatOfPoint2f sourceMatOfPoint2f = new MatOfPoint2f();
        sourceMatOfPoint2f.fromList(sourcePoints);
        MatOfPoint2f targetMatOfPoint2f = new MatOfPoint2f();
        targetMatOfPoint2f.fromList(targetPoints);

        Mat homography = Calib3d.findHomography(sourceMatOfPoint2f, targetMatOfPoint2f);            
        Mat transformationResult = new Mat(sourceImageMat.rows(), sourceImageMat.cols(), sourceImageMat.type());                
        Imgproc.warpPerspective(sourceImageMat, transformationResult, homography, transformationResult.size());

        Mat resultImage = new Mat();
        Core.add(transformationResult, targetImageMat, resultImage);

        return mat2BufferedImage(resultImage);
    }
    else{
        throw new RegistrationException();
    }
}

mat2BufferedImage()getGoodMatches()都经过测试,似乎是有效的。 findHomography()warpPerspective()似乎有问题,因为这是我查看转换后的(未融合)图像的结果:https://i.imgur.com/8JRQwtG.png

有人知道出了什么问题吗?先感谢您!

编辑:因此,经过进一步调查,结果表明转换矩阵具有极强的透视变换(值从400-700)。由于图像非常相同/只有很小的差异,我不明白为什么这是findHomography()的结果。这种方法有替代方案吗?

java opencv image-processing
1个回答
0
投票

我会用drawMatches()来验证goodMatches中没有异常值。异常值可以完全搞乱计算单应性。如果你得到异常值,那么你需要使用强大的findHomography()变体。

© www.soinside.com 2019 - 2024. All rights reserved.