Read run-length encoding data from a table

1 回表示 (過去 30 日間)
Jacopo Biasetti
Jacopo Biasetti 2022 年 7 月 9 日
編集済み: Jan 2022 年 7 月 10 日
Hi,
I have the attached table where the second column (EncodedPixels) contains the run-length encoding of bounding box masks.
I wonder how to transform each row in the column EncodedPixels into double for subsequent manipulation.
Thanks,
Jacopo

回答 (2 件)

dpb
dpb 2022 年 7 月 9 日
Not sure what the next step(s) are, but to convert each row use something like
data=reshape(str2double(split(tT.EncodedPixels(i)).'),2,[]).';
where i=1:height(test_table)
You can probably avoid the above step by reading the data in in proper format as numeric from the beginning, though; I presume these came from some other input file? Show us the format for it and we can probably read directly into numeric array.
  1 件のコメント
Jacopo Biasetti
Jacopo Biasetti 2022 年 7 月 10 日
Thanks for your reply.
Here is the original file, it comes in csv format.

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


Jan
Jan 2022 年 7 月 10 日
編集済み: Jan 2022 年 7 月 10 日
This is one of the files I would not import with readtable, but manually:
[fid, msg] = fopen(FileName, 'r');
assert(fid > 0, 'Cannot read file: %s', msg);
k = 0;
Header = fgetl(fid);
while ~feof(fid)
S = fgetl(fid);
if ~isempty(S)
k = k + 1;
[File, Value] = strtok(S, ',')
Data(k).File = File;
Num = sscanf(Value(2:end), '%g');
% Decode run-length encoded values:
Data(k).Value = repelem(Num(1:2:end), Num(2:2:end));
% Or maybe:
% ??? Data(k).Value = repelem(Num(2:2:end), Num(1:2:end));
end
end
fclose(fid);

カテゴリ

Help Center および File ExchangeData Import and Export についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by