-1

我有两个 3D 图像,我需要使用“lsqcurvefit”注册这两个图像。我知道我可以使用“imregister”,但我想在 Matlab 中使用“lsqcurvefit”使用我自己的注册。我的图像遵循高斯分布。没有很好地记录我应该如何提供它,任何人都可以详细帮助我吗?

图像配准是使用仿射将源图像映射到目标图像的重复过程。我想使用强度基配准,并且我使用图像的所有体素。因此,我需要尽可能地适合这两个图像。

谢谢

4

1 回答 1

1

这是一个如何使用lsqcurvefit. 基本上,您创建了一个函数,该函数采用一组点和一个仿射矩阵(我们将使用平移和旋转部分,但如果需要,您可以使用倾斜和放大)并返回一组新点。可能已经有一个内置函数,但它只有两行,所以很容易编写。该功能是:

function TformPts = TransformPoints(StartCoordinates, TransformMatrix)

TformPts = StartCoordinates*TransformMatrix;

这是一个脚本,它生成一些点,通过随机角度和矢量旋转和平移它们,然后使用该TransformPoints函数作为输入lsqcurvefit来拟合注册所需的变换矩阵。然后它只是一个矩阵乘法来生成注册的点集。如果我们做的很好,当下面的代码运行时,红色圆圈(原始数据)将与黑色星星(移动然后注册的点)很好地对齐。

% 20 random points in x and y between 0 and 100
% row of ones pads out third dimension
pointsList = [100*rand(2, 20); ones(1, 20)];

rotateTheta = pi*rand(1); % add rotation, in radians
translateVector = 10*rand(1,2); % add translation, up to 10 units here

% 2D transformation matrix
% last row pads out third dimension
inputTransMatrix = [cos(rotateTheta), -sin(rotateTheta), translateVector(1);
                    sin(rotateTheta), cos(rotateTheta), translateVector(2);
                    0 0 1];


% Transform starting points by this matrix to make an array of shifted
% points.  
% For point-wise registration, pointsList represents points from one image,
% shiftedPoints points from the other image
shiftedPoints = inputTransMatrix*pointsList;
% Add some random noise
% Remove this line if you want the registration to be exact
shiftedPoints = shiftedPoints + rand(size(shiftedPoints, 1), size(shiftedPoints, 2));

% Plot starting sets of points
figure(1)
plot(pointsList(1,:), pointsList(2,:), 'ro');
hold on
plot(shiftedPoints(1,:), shiftedPoints(2,:), 'bx');
hold off

% Fitting routine
% Make some initial, random guesses
initialFitTheta = pi*rand(1);
initialFitTranslate = [2, 2];

guessTransMatrix = [cos(initialFitTheta), -sin(initialFitTheta), initialFitTranslate(1);
                    sin(initialFitTheta), cos(initialFitTheta), initialFitTranslate(2);
                    0 0 1];

% fit = lsqcurvefit(@fcn, initialGuess, shiftedPoints, referencePoints)             
fitTransMatrix = lsqcurvefit(@TransformPoints, guessTransMatrix, pointsList, shiftedPoints);

% Un-shift second set of points by fit values
fitShiftPoints = fitTransMatrix\shiftedPoints;

% Plot it up
figure(1)
hold on
plot(fitShiftPoints(1,:), fitShiftPoints(2,:), 'k*');
hold off

% Display start transformation and result fit
disp(inputTransMatrix)
disp(fitTransMatrix)
于 2015-02-25T05:05:50.423 回答