嗨我试图导出使用MATLAB Coder
工具从MATLAB中的注册估算器应用程序自动生成的“默认代码”为C++。使用MATLAB编码器将代码从注册估算器应用程序导出到C++
这是我今天所产生的示例代码:
function [MOVINGREG] = registerImages(MOVING,FIXED)
%registerImages Register grayscale images using auto-generated code from Registration Estimator app.
% [MOVINGREG] = registerImages(MOVING,FIXED) Register grayscale images
% MOVING and FIXED using auto-generated code from the Registration
% Estimator App. The values for all registration parameters were set
% interactively in the App and result in the registered image stored in the
% structure array MOVINGREG.
% Auto-generated by registrationEstimator app on 21-Jun-2017
%-----------------------------------------------------------
% Convert RGB images to grayscale
FIXED = rgb2gray(FIXED);
MOVING = rgb2gray(MOVING);
% Default spatial referencing objects
fixedRefObj = imref2d(size(FIXED));
movingRefObj = imref2d(size(MOVING));
% Intensity-based registration
[optimizer, metric] = imregconfig('monomodal');
optimizer.GradientMagnitudeTolerance = 1.00000e-04;
optimizer.MinimumStepLength = 1.00000e-05;
optimizer.MaximumStepLength = 6.25000e-02;
optimizer.MaximumIterations = 100;
optimizer.RelaxationFactor = 0.500000;
% Align centers
fixedCenterXWorld = mean(fixedRefObj.XWorldLimits);
fixedCenterYWorld = mean(fixedRefObj.YWorldLimits);
movingCenterXWorld = mean(movingRefObj.XWorldLimits);
movingCenterYWorld = mean(movingRefObj.YWorldLimits);
translationX = fixedCenterXWorld - movingCenterXWorld;
translationY = fixedCenterYWorld - movingCenterYWorld;
% Coarse alignment
initTform = affine2d();
initTform.T(3,1:2) = [translationX, translationY];
% Apply transformation
tform = imregtform(MOVING,movingRefObj,FIXED,fixedRefObj,'similarity',optimizer,metric,'PyramidLevels',3,'InitialTransformation',initTform);
MOVINGREG.Transformation = tform;
MOVINGREG.RegisteredImage = imwarp(MOVING, movingRefObj, tform, 'OutputView', fixedRefObj, 'SmoothEdges', true);
% Store spatial referencing object
MOVINGREG.SpatialRefObj = fixedRefObj;
end
在部分Run-Time Issues
在编码器工具,我收到了几个问题,例如该编码器需要declare the extrinsic。到现在为止还挺好。我加了例如:coder.extrinsic('imregconfig');
和coder.extrinsic('optimizer');
。但我仍然收到如下错误:
尝试从'mxArray'中提取字段'GradientMagnitudeTolerance'。
尝试从'mxArray'中提取字段'MinimumStepLength'。
尝试从'mxArray'中提取字段'MaximumStepLength'。
...
指着符合optimizer.GradientMagnitudeTolerance = 1.00000e-04;
(和下文)。
我发现通常变量的初始化是缺失的。但我不知道如何在高级中初始化属性optimizer.GradientMagnitudeTolerance
。谁能帮我这个?
PS:我使用MATLAB R2017a
和Microsoft Visual C++ 2017 (C)
编译
嗯这是不好的:/你建议任何其他方式来使用这个代码“outsite”的matlab IDE? – user1234
你可以试试MATLAB编译器来编译这段代码并创建一个独立的可执行文件。那会在MATLAB之外运行。 – Navan