Export formats for markups

Could someone please explain the difference between the export options for fixed landmarks (fiducials) and semiLM patches in 3D Slicer? I’m not familiar with the .mrk.json, .json, .fcsv, and *.fcsv formats or the advantage of using one over the other. I’m planning to import these files into R for GM analysis using the geomorph package for analysis.

Additionally, I’m currently exporting these as .fcsv files, but I’m not able to make excel recognize and separate the file contents correctly. I’ve tried opening the app and using the open option and selecting the file, but it just opens without separating the contents into cells by commas. Any advice on this topic would be appreciated as well.

First off, if you want to read markups into R, we have a few simple convenience functions that you might find useful. GitHub - muratmaga/SlicerMorph_Rexamples: Some functions to import SlicerMorph data into R (look at read.markups.fcsv.R and read.markups.json.R).

Another option is to use the log_parser.R script. Recent versions of GPA module in SlicerMorph writes a simple log file that contains important information such as the number of landmark, input file locations etc (see the readme.MD in the link above for details).

Finally, geomorph_regression.R provides an example of how to use procrustes aligned coordinates from SlicerMorph in R. It also shows an example of directly reading the original coordinates into R (to show that results are identical either way).

You might find it easier to process them in R with the scripts I provided above. But if you want to see the contents in Excel, just use the Text to Columns option under Data (and choose comma as separator).

If you are only doing landmarks (whether semi or anatomical LMs) and your goal is shape analysis in R, then the difference between fcsv and json is not much. However, if you are using other Markup types such as lines, closed curves, planes, etc., and particularly if you are making measurements from them, fcsv cannot store these measurements, while JSON can. For example, if you create a line with two Fiducal markups that is 10 mm long, if you save this file as fcsv and load it back into Slicer, all you will get will be the coordinates of the two control points that used in making the line. There won’t be a length measurement, there won’t be a visualization of that line segment. If you save it as json, they will be restored next time you load that into Slicer.

2 Likes

Great, thank you! This is exactly what I needed to know.

1 Like

I’m so grateful for your infinite patience.

New problem: I accidentally saved the file after I applied the text to columns function, and now when I try and reload the file into 3D Slicer it won’t read the fiducial coordinates. I tried using the TEXTJOIN function to rejoin the text into a single column with the comma delimiter in Excel, but that isn’t making any difference. I realize this is more of an Excel help kind of question, but I’m hoping you might have some ideas for how I can make the file readable for 3D Slicer again.

Well as you discovered, that’s one reason not to use excel.

  1. In excel save your original fcsv in csv format using save as.
  2. Open the csv file in notepad (or a simple text editor) and paste these on top of the file (including the # sign)
  3. save and try opening in Slicer now.
# Markups fiducial file version = 4.13
# CoordinateSystem = LPS
# columns = id,x,y,z,ow,ox,oy,oz,vis,sel,lock,label,desc,associatedNodeID

I certainly have discovered a lot in the last 12 hours, including the sheer panic. I will not be saving those edited files again. Thank you, thank you, thank you! Maybe it’s time to lose the incessant need to meticulously check my data at every step.

You should do that, particularly when you are learning the software and creating a workflow.

The thing is you really shouldn’t be editing those fcsv, but just looking at the contents to make yourself familiar with the format, and what you are exporting. For that a notepad editor would suffice. Better use something like R where you can programmatically read them and don’t worry about overwriting the files…

If you are editing them to make some changes, that’s pretty much something you shouldn’t do.

Got it. Wasn’t doing any editing, just wanting to see what was in them in a way that didn’t make my eyes cross. But it’s easy enough to import them and do that in R, I suppose. Thanks again!

1 Like

It takes just 2-3 commands to read or write control points from/to csv file - see examples here.

While this is really easy to do, maybe we should expose csv (not fcsv) import/export of markups control point coordinates somewhere on the GUI.

I would discourage this, because there is already enough confusion about LPS/RAS and how the format is changed thru times and how control points displayed in Markups module versus saved in file. Without those headers saved in the file, it would be a big headache.

I don’t mean it as a save format, strictly as an import/export format. But I fully agree that if we can educate people to move away from csv and use json instead then that’s much better.

By the way, Excel can import json files very nicely as a data source, the same way as it can generate live table views from various other databases (see step-by-step instructions below). So, Excel’s limitation is not that it cannot load JSON files, but in what analysis it can do on them and that you need to use the GUI or VBA (or maybe C#), which are not that well suited for data analysis.


Step-by-step instructions for importing a markups json file (*.mrk.json) into Excel as a live data source:

  • In the ribbon, choose Data / Get data / From file / From JSON, and select the *.mrk.json file

image

= Table.SplitColumn(#"Extracted Values1", "Column1.position", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"Column1.position.1", "Column1.position.2", "Column1.position.3"})

  • Click on “List” in “Markups” row
  • Click on “Record”
  • Click on “List” in “controlPoints” row
  • Click “To Table”, click OK
  • Click on the field selector and choose the fields you want in the table, for example “label”, “position” and “positionStatus”

image

  • Split position column by clicking on the field selector and then choosing “Extract values…”

image

  • Choose semicolon as delimiter and click OK
  • Click “Split column” / “By delimiter”, make sure semicolon is used as delimiter and then click OK
  • Click Close&Load

image

You only need to do this once, from this point the markups json file acts as a database (you can update table content from the json file with a single click or enable auto-refresh, etc.), you can change the input json file, etc.

2 Likes

I don’t get an “Export as” option in the menu, just export to DICOM. Am I missing a module or something? I’m new to Slicer FYI (sorry!).

In the latest Slicer preview version there should be “Export to file…”

Hm, well I just downloaded Slicer today, so should be the latest (4.11.20210226)

@rsookias See the following post below.

Great! That solved it. And is there any way to bulk export fiducials? E.g. I have 20 landmarks…

You mean you’ve 20 fiducial objects you would like to convert to a format (e.g., from fcsv to json or vice versa). Load all of them into SLicer, and use the Save (Ctrl + S) command.

Ah, yes, good idea. Thanks!

Also if you put them under one folder in the Slicer data browser then you can export that folder using “Export to file…”