Simulink-Coder image data representation in C

1 回表示 (過去 30 日間)
FJS
FJS 2017 年 5 月 9 日
コメント済み: FJS 2017 年 5 月 13 日
Hello, I have a question related to an image representation out of Matlab Simulink Coder. If I have a Simulink block with an RGB image output size for instance 320x240x3, I get in my generated code an array with the size "img[230400]". My question is now, if I want to write this array to an .ppm-file-format, how do I have to iterate over this array to get a row based rgb order and see the image.
Thanks in advanced.

採用された回答

Alain Kuchta
Alain Kuchta 2017 年 5 月 12 日
編集済み: Alain Kuchta 2017 年 5 月 12 日
Assuming img is an I x J x K array, the array element given in MATLAB by:
img(i,j,k)
can accessed in the generated C code at:
img[(k-1)*(J*I) + (j-1)*I + (i-1)];
For a more detailed explanation of how matrices and arrays are stored in generated code, refer to the following documentation:
  1 件のコメント
FJS
FJS 2017 年 5 月 13 日
Thank's, that helped. Column based thinking was the tricky part. Here is my solution:
for(int i = 1; i <= dimy; i++)
for(int j = 1; j <= dimx; j++)
for(int k = 1; k <= channel; k++)
fprintf(fp,"%d ",img[(k-1)*(dimx*dimy)+(j-1)*dimy+(i-1)]);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeComputer Vision with Simulink についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by