1

特徴検出によって、ある画像から別の画像にピクセルを変換する必要があります。射影変換行列を計算しました。1 つのイメージはベース イメージで、もう 1 つのイメージは直線的に変換されたイメージです。

ここで、より大きなグリッドを定義し、ベース イメージのピクセルをそれに割り当てる必要があります。たとえば、ベース イメージが 20 の場合(1,1)、より大きなグリッドでは 20 になり(1,1)ます。グリッドのすべての未入力の値にゼロを割り当てます。次に、線形に変換された画像をベース画像にマッピングし、「ドローネ三角形分割」に基づいて独自のアルゴリズムを記述して、画像間を補間する必要があります。

私の質問は、翻訳された画像をベース画像にマッピングするときに、コンセプトを使用することです

(w,z)=inv(T).*(x,y)  
A=inv(T).*B  

ここで(w,z)、 はベース イメージの(x,y)座標、 は変換されたイメージの座標、は座標Aを含む行列、 は座標を含む行列です。(w z 1)B(x y 1)

次のコードを使用すると、新しい座標を取得できますが、これらを画像に関連付けるにはどうすればよいでしょうか? 2 番目の画像のピクセルも最初の画像に変換されますか? そうでない場合、どうすればこれを行うことができますか?

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

0

あなたはここであまりにも多くの作業を行っています. Delaunay Triangulation はまったく必要ないと思います. Image Processing Toolboxの関数を使用してimwarp、イメージを変換します。元の画像とtformによって返されたオブジェクトを取得しestimateGeometricTransformます。

于 2013-12-03T15:28:19.767 に答える