c++ - 加载图像集 - Matlab-->C++ 翻译

标签 c++ matlab fits

我有一个 Matlab 脚本,我正试图将其转换为 C++(见下文),因为它非常慢。我是 C++ 新手,一开始我尝试使用 codegen 但它不起作用(我收到消息 ??? This text contains non-empty top-level expressions. 它出现成为脚本。)

您对如何开始转换代码有什么建议吗?另外,完成 fitsread 工作的最佳 C++ 函数是什么?

这是我的代码:

clear;

number_projections = 10;
imgs_per_proj = 2000; % Number of images per projection

% Lets load the reference images relative to the various wavelengths

R1 = zeros(imgs_per_proj, 512, 512);
R2 = zeros(imgs_per_proj, 512, 512);

l = 0;
for k = 1:imgs_per_proj
    s = sprintf('Ref/R1_000_%05i.fits',k-1);
    t = sprintf('Ref/R2_000_%05i.fits',k-1);
    l = l + 1;
    R1(l,:,:) = fitsread(s);
    R2(l,:,:) = fitsread(t);
end

最佳答案

codegen 要求您尝试转换的 MATLAB 代码在函数中,看起来您正在尝试转换脚本

但是,即使您这样做,fitsread 似乎也不是 codegen 中受支持的函数。以下是支持的函数列表: http://www.mathworks.com/help/simulink/ug/functions-supported-for-code-generation--alphabetical-list.html

C++ 中没有可替代 fitsread 的“内置”函数 - 为此您需要一个库。您可以在此处找到名为 CCFits 的 C++ FITS 库:http://heasarc.gsfc.nasa.gov/fitsio/CCfits/

他们应该有您可以遵循的教程。

关于c++ - 加载图像集 - Matlab-->C++ 翻译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28977775/

相关文章:

c++ - 'if constexpr branch' 不会在模板函数内的 lambda 内被丢弃

optimization - 什么时候不对 matlab 进行矢量化?

matlab - 在 Matlab 中使用 imfinfo 函数进行图像压缩

python - 使用python修改fits文件时出现错误 "buffer is too small for requested array"

python - 如何将像素坐标与 imshow() 命令一起使用,以便从 python 中适合图像的特定部分生成图像?

c++ - CCfits 库演示代码不起作用

c++ - Qt QSqlQuery 返回 json

c++ - 返回值错误

c++ - 循环内变量的定义

python - 为什么 MATLAB 在使用 "from tensorflow import keras"调用 python 脚本时会产生错误?