我目前正在尝试使用java和OpenCV包装融合放射性灰度图像。我编写了一些代码,以便在数据库中找到相似的图像并将它们融合。融合部分是我所在的地方,struggling.This是我正在努力解决的方法:
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()的结果。这种方法有替代办法吗?
发布于 2018-03-28 05:14:31
我会使用drawMatches()来验证goodMatches中没有异常值。离群点会完全破坏计算机的同调。如果得到异常值,则需要使用findHomography()的健壮变体。
https://stackoverflow.com/questions/49509502
复制相似问题