Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 需要一个算法来映射不同维度图像中点的坐标吗_Java_Image Processing - Fatal编程技术网

Java 需要一个算法来映射不同维度图像中点的坐标吗

Java 需要一个算法来映射不同维度图像中点的坐标吗,java,image-processing,Java,Image Processing,我在当前项目中遇到了一个问题。我有两份相同图像的副本,比如image1.tiff和image2.tiff,但尺寸不同(像素和DPI不同)。假设image1.tiff中的一个点位于坐标(x,y)处,我需要在image2.tiff中找到同一点的坐标。我已经试了很多次想一个算法。请求您的帮助。我建议以下方法: double image1_to_image2 = image2.width()/image1.width(); double image2_to_image1 = image1.width()

我在当前项目中遇到了一个问题。我有两份相同图像的副本,比如image1.tiff和image2.tiff,但尺寸不同(像素和DPI不同)。假设image1.tiff中的一个点位于坐标(x,y)处,我需要在image2.tiff中找到同一点的坐标。我已经试了很多次想一个算法。请求您的帮助。

我建议以下方法:

double image1_to_image2 = image2.width()/image1.width();
double image2_to_image1 = image1.width()/image2.width();
如果将
x1
y1
作为第一个图像的坐标,则可以按如下方式计算第二个图像的相应位置:

int x2 = x1 * image1_to_image2;
int y2 = y1 * image1_to_image2;
如果图像的纵横比不同,则需要分别计算高度的比例因子


该方法背后的基本思想是,通过除以宽度(假设宽度是较大的尺寸,但它是否小于高度并不重要),将图像的坐标映射到间隔
i_1=[0;1]
。通过将缩放后的坐标与第二幅图像的宽度相乘,可以将坐标映射回间隔
i_2=[0;x_1*width_2]
,该间隔最多为第二幅图像的宽度。

可以使用
仿射变换器进行此操作

例如:

BufferedImage img1 = new BufferedImage(200, 100, BufferedImage.TYPE_INT_ARGB);
BufferedImage img2 = new BufferedImage(400, 200, BufferedImage.TYPE_INT_ARGB);

double sx = img2.getWidth() / (double) img1.getWidth();
double sy = img2.getHeight() / (double) img1.getHeight();

AffineTransformOp xform = 
        new AffineTransformOp(AffineTransform.getScaleInstance(sx, sy), null);
Point srcPt = new Point(7, 49);
Point dstPoint = (Point) xform.getPoint2D(srcPt, new Point());

System.err.println("srcPt: " + srcPt);
System.err.println("dstPoint: " + dstPoint);
将打印:

srcPt: java.awt.Point[x=7,y=49]
dstPoint: java.awt.Point[x=14,y=98]

理论上,您应该只需要缩放x/y坐标。因此,如果图像A比图像B大50%,那么A中的任何点在B上都比B小50%(或者在这里是一半)…nb-我的数学是垃圾,所以如果实现错误,我道歉,但理论应该是正确的。。。