Image 坐标映射是否与matlab中用于delaunay三角剖分的像素映射相同

Image 坐标映射是否与matlab中用于delaunay三角剖分的像素映射相同,image,matlab,transform,delaunay,matlab-cvst,Image,Matlab,Transform,Delaunay,Matlab Cvst,我必须通过特征检测将像素从一幅图像转换到另一幅图像。我已经计算了射影变换矩阵。一个图像是基础图像,另一个是线性转换的图像 现在我必须定义一个更大的网格,并将基本图像中的像素分配给它。例如,如果基础图像在(1,1)处为20,则在较大的网格上,我将在(1,1)处为20。并为网格的所有未填充值指定零。然后,我必须将线性转换后的图像映射到基础图像上,并基于“delaunay三角剖分”编写自己的算法在图像之间进行插值 我的问题是,当我将翻译后的图像映射到基础图像时,我使用了这个概念 (w,z)=inv(T

我必须通过特征检测将像素从一幅图像转换到另一幅图像。我已经计算了射影变换矩阵。一个图像是基础图像,另一个是线性转换的图像

现在我必须定义一个更大的网格,并将基本图像中的像素分配给它。例如,如果基础图像在
(1,1)
处为20,则在较大的网格上,我将在
(1,1)
处为20。并为网格的所有未填充值指定零。然后,我必须将线性转换后的图像映射到基础图像上,并基于“delaunay三角剖分”编写自己的算法在图像之间进行插值

我的问题是,当我将翻译后的图像映射到基础图像时,我使用了这个概念

(w,z)=inv(T).*(x,y)  
A=inv(T).*B  
其中
(w,z)
是基本图像的坐标,
(x,y)
是翻译图像的坐标,
A
是包含坐标的矩阵
(w z 1)
B
是包含坐标的矩阵
(x,y 1)

如果我使用下面的代码,我会得到新的坐标,但是我如何将这些东西与图像联系起来呢?第二幅图像中的像素是否也被转换到第一幅图像上?如果没有,我怎么做

close all; clc; clear all;

image1_gray=imread('C:\Users\Javeria Farooq\Desktop\project images\a.pgm');
figure; imshow(image1_gray); axis on; grid on;
title('Base image');
impixelinfo
hold on

image2_gray =imread('C:\Users\Javeria Farooq\Desktop\project images\j.pgm');
figure(2); imshow(image2_gray); axis on; grid on;
title('Unregistered  image1');
impixelinfo

% Detect and extract features from both images
points_image1= detectSURFFeatures(image1_gray, 'NumScaleLevels', 100, 'NumOctaves', 5,  'MetricThreshold', 500 );
points_image2 = detectSURFFeatures(image2_gray, 'NumScaleLevels', 100, 'NumOctaves', 12,  'MetricThreshold', 500 );

[features_image1, validPoints_image1] = extractFeatures(image1_gray, points_image1);
[features_image2, validPoints_image2] = extractFeatures(image2_gray, points_image2);

% Match feature vectors
indexPairs = matchFeatures(features_image1, features_image2, 'Prenormalized', true) ;

% Get matching points
matched_pts1 = validPoints_image1(indexPairs(:, 1));
matched_pts2 = validPoints_image2(indexPairs(:, 2));

figure; showMatchedFeatures(image1_gray,image2_gray,matched_pts1,matched_pts2,'montage');
legend('matched points 1','matched points 2'); 
figure(5); showMatchedFeatures(image1_gray,image3_gray,matched_pts4,matched_pts3,'montage');
legend('matched points 1','matched points 3'); 

% Compute the transformation matrix using RANSAC
[tform, inlierFramePoints, inlierPanoPoints, status] = estimateGeometricTransform(matched_pts1, matched_pts2, 'projective')
figure(6); showMatchedFeatures(image1_gray,image2_gray,inlierPanoPoints,inlierFramePoints,'montage');
[m n] = size(image1_gray);
image1_gray = double(image1_gray);
[x1g,x2g]=meshgrid(m,n) % A MESH GRID OF 2X2
k=imread('C:\Users\Javeria Farooq\Desktop\project images\a.pgm');
ind = sub2ind( size(k),x1g,x2g);

%[tform1, inlierFramepPoints, inlierPanopPoints, status] = estimateGeometricTransform(matched_pts4, matched_pts3, 'projective')
%figure(7); showMatchedFeatures(image1_gray,image3_gray,inlierPanopPoints,inlierFramepPoints,'montage');
%invtform=invert(tform)
%x=invtform
%[xq,yq]=meshgrid(1:0.5:200.5,1:0.5:200.5);

r=[];
A=[];
k=1;

%i didnot know how to refer to variable tform so i wrote the transformation
%matrix from variable structure tform
T=[0.99814272,-0.0024304502,-1.2932052e-05;2.8876773e-05,0.99930143,1.6285858e-06;0.029063907,67.809265,1]

%lets take i=1:400 so my r=2 and resulting grid is 400x400
for i=1:200
    for j=1:200
        A=[A; i j 1];
        z=A*T;
        r=[r;z(k,1)/z(k,3),z(k,2)/z(k,3)];
        k=k+1;
    end
end

%i have transformed the coordinates but how to assign values??
%r(i,j)=c(i,j)
d1=[];
d2=[];
for l=1:40000
    d1=[d1;A(l,1)];
    d2=[d2;r(l,1)];
    X=[d1 d2];
    X=X(:);
end

c1=[];
c2=[];
for l=1:40000
    c1=[c1;A(l,2)];
    c2=[c2;r(l,2)];
    Y=[c1 c2];
    Y=Y(:);
end

%this delaunay triangulation is of vertices as far as i understand it
%doesnot have any pixel value of any image
DT=delaunayTriangulation(X,Y);
triplot(DT,X,Y);

你在这里做的工作太多了,我认为你根本不需要Delaunay三角测量。使用图像处理工具箱中的
imwarp
函数变换图像。它采用原始图像和由
estimateGeometricTransform
返回的
tform
对象,您在这里做的工作太多了,我认为您根本不需要Delaunay三角剖分。使用图像处理工具箱中的
imwarp
函数变换图像。它获取原始图像和由
estimateGeometricTransform
返回的
tform
对象。我使用以下两个步骤解决了此问题:

  • 使用transformPointsForward命令,使用EstimateGeometrTransform返回的tform对象变换图像的坐标

  • 使用Matlab中的scatterdinterpolant类并使用scatterdinterpolant命令 为变换后的坐标指定各自的像素值

  • F=散射极间体(p,z)

    这里p=包含所有变换坐标的nx2矩阵

    z=nx1 matrix containing pixel values of image that is transformed,it is obtained by converting image to column vector using image=image(:)
    

    最后,所有变换后的坐标及其像素值都显示在基础图像上,并且可以进行插值。

    我使用以下两个步骤解决了这个问题:

  • 使用transformPointsForward命令,使用EstimateGeometrTransform返回的tform对象变换图像的坐标

  • 使用Matlab中的scatterdinterpolant类并使用scatterdinterpolant命令 为变换后的坐标指定各自的像素值

  • F=散射极间体(p,z)

    这里p=包含所有变换坐标的nx2矩阵

    z=nx1 matrix containing pixel values of image that is transformed,it is obtained by converting image to column vector using image=image(:)
    

    最后,所有变换后的坐标及其像素值都显示在基础图像上,并且可以进行插值。

    对不起,我忘记添加代码了。您可以通过编辑答案并将每行代码缩进四个空格来添加代码块,我更新了你的问题和代码以便于阅读,因为越容易理解,你越有可能得到回答。请检查我的编辑,以确保它们仍然准确地传达您的问题。@nispio谢谢您,先生,它传达了我的问题,我现在正在寻找答案对不起,我忘了添加代码。您可以通过编辑您的答案并将每行代码缩进四个空格来添加代码块,我更新了你的问题和代码以便于阅读,因为越容易理解,你越有可能得到回答。请检查我的编辑,以确保它们仍然准确地表达您的问题。@nispio谢谢,先生。它表达了我的问题,我正在寻找答案。现在无法使用imwarp函数,因为它将线性插值网格上变换的像素值,然而,我想使用delaunay三角剖分并通过曲面近似进行插值出于好奇,您试图解决的问题是什么?我真的想不出射影变换的情况,在这种情况下,双线性或双三次插值是不够的。这是一个立体校正的例子,其中,
    imwarp
    做得很好:实际上,在投影变换后,我必须对图像进行超分辨率处理。我不必只进行插值,所以我不需要插值的类型imwarp,否则你说的是对的。imwarp函数不能使用,因为它将对变换后的图像进行线性插值网格上的像素值,但是我想使用delaunay三角剖分并通过曲面近似进行插值出于好奇,您试图解决的问题是什么?我真的想不出射影变换的情况,在这种情况下,双线性或双三次插值是不够的。这里有一个立体校正的例子,其中,
    imwarp
    做得很好:实际上,我必须在投影变换后对图像进行超分辨率处理。我不必只进行插值,所以我不需要插值的类型imwarp,否则你说的是对的。