1

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

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

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

(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);
4

2 回答 2

1

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

  1. 使用transformPointsForward命令变换图像坐标,使用estimateGeometrcTransform返回的tform对象

  2. 使用 Matlab 中的scatterInterpolant 类并使用命令scatteredInterpolant 将变换后的坐标分配给它们各自的像素值。

F=scatteredInterpolant(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(:)

最后,所有变换后的坐标与它们的像素值一起出现在基础图像上,并且可以进行插值。

于 2013-12-07T04:20:12.880 回答
0

你在这里做了太多的工作,我认为你根本不需要德劳内三角测量。使用imwarp图像处理工具箱中的函数来转换图像。它采用原始图像和tform返回的对象estimateGeometricTransform

于 2013-12-03T15:28:19.767 回答