How to convert from structure to table?

Hi!
Hope everyone is doing well! I am following YOLO example for inferences with my own dataset. I noticed the example had annotations in the format like below in a table format (imagefilename cloumn, and vehicle column).
While the annotations file that I have has a different format and I am struggling to convert to the similar format as above. When I import the json file, it converts the data into stuct, which I am not very familiar with other than looking up Youtube videos, and MATLAB docs.
This is the data from imported json file.
This has multiple categories and each bounding box is split into individual rows. It seems I will have to convert that into a table format for corresponding image. I can have multiple columns for different categories. Any suggestions?
Thanks!

Answers (1)

You can use struct2table(): https://www.mathworks.com/help/releases/R2020b/matlab/ref/struct2table.html to convert structs to table. This shows how to access data in MATLAB's table: https://www.mathworks.com/help/matlab/matlab_prog/access-data-in-a-table.html

5 Comments

Here's my crude attempt at conversion:
I am thinking in terms of python syntax by wanting to iterate though column, but I feel like for MATLAB, it would be indicies?
vd2 = table();
for i = 1:3 % vd.image_id(end) %200
if vd.image_id(i) == i && vd.category_id(i) == 3 %vd is coverted to table from struct
vd2 = vd.bbox(i);
end
i = i+1;
end
the code doesn't work btw. I was trying to interate though image id 1 to 3 for example and make sure category id =3, if so, store the value in a new table. Eventually, I will have to make sure the new table for bbox column looks like this:
[202,190,132,122 ; 405, 193, 88, 77 ; 80, 220,48,28 ; 129, 219, 28, 34] - which corresponds to 1st image.
So, I have tried a lot of different ways to approach this problem. I was able to extract image id, category id, and bbox in a table format, but I wasn't getting the loop to work.
Another approach is that once I converted original struc2table, I used to following line to extract info from table itself:
rows = (vd.image_id == 0 & vd.category_id ==3);
vd(rows,:) and then I can extract bbox column which is 4x1 cell array
Now, after some conversion, I can get it to be 4x4 cell array, but I am not able to store it in a new table, like how the original dataset from the example is set up.
imagefile1 vehicle
1.jpg m by n matrix.
Any help is appreciated!
Kev
Kev on 27 Oct 2020
Edited: Kev on 27 Oct 2020
After spending nearly 20 hours on this, I figured it out. :|
Sorry! I wasn't able to respond to this. Glad that you figured it out. You may consider sharing the solution so that it will be helpful for anyone else coming to this page.
sure, I will post the solution once I get the detector working so I know the code can be used in the future.

Sign in to comment.

Categories

Asked:

Kev
on 26 Oct 2020

Commented:

Kev
on 29 Oct 2020

Community Treasure Hunt

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

Start Hunting!