My brain is hardwired with C++ mindset. Need help vectorizing the following loop.
This code is trying to generate a C++ header that contains an array that maps every pixel location of an distorted image to the undistorted coordinates.
FYI cameraParams
and imgIntrinsics
are already previously generated by the estimateFisheyeParameters
function and undistortFisheyeImage
image previously.
fileID = fopen('undistorted.h', 'w');
fprintf(fileID, '#ifndef UNDISTORTED_H\n#define UNDISTORTED_H\n\n');
fprintf(fileID, 'const float distortionFix[%d][%d][2] = {', mrows, ncols);
for y = 1:mrows
fprintf(fileID, '{');
for x = 1:ncols
undistortedPoint = undistortFisheyePoints([x y], cameraParams.Intrinsics);
undistortedPoint = undistortedPoint - imgIntrinsics.PrincipalPoint;
fprintf(fileID, '{%f, %f}', undistortedPoint);
if x < ncols
fprintf(fileID, ', ');
end
end
if (y < mrows)
fprintf(fileID, '},\n');
end
end
fprintf(fileID, '}};\n\n#endif');