Once we have images uploaded to Bisque, we might want to be able to overlay annotations on top of them so that users can interact with them. This post quickly goes through the conversation of a binary mask, in matlab, into an XML which can later be imported into Bisque.
This post is rather short because it is very similar to the process of exporting binary masks to ventana/image viewer.
In this case, we’ve done some tubule segmentation using deep learning. The output filenames all contain “class” which is a binary mask such as this one:
Next we iterate through the files, and create the original file name by replacing the latter part of the filename with the correct extension:
- for fi=1:length(files)
By design, the binary mask is half the size of the original image, so we upscale it as both the binary mask and the original file need to be of the same size for the annotation coordinate systems to overlay correctly.
We initialize the xml which needs to be sent. The root tag is a <gobject> and inside we can fill it with many polygons, each of which contain an ordered list of verticies.
We want to do each object of the binary individually, so we label it and iterate through all of the object numbers
- for zz=1:num
We’re only interested in the points on the perimeter, so we use bwperim to create a binary perimeter image
Afterwards, we want to trace a path, in order, around the perimeter and get those x,y coordinates. Matlab also has inbuilt functions for this:
- C=bwtraceboundary(p,[r(1) c(1)],'N');
Now that we have the path, we create the polygon itself by starting the polygon tag, then iterating through each vertex adding the appropriate xml:
- for yy=1:length(C)
- xml_to_send=strcat(xml_to_send,sprintf('<vertex index="%d" t="0.0" x="%0.2f" y="%0.2f" z="0.0"/>\n',yy-1,C(yy,2),C(yy,1)));
Once all of our objects are done, we close the gobject and write the xml to file
Finally, we add the original filename to the list of files which are needed on the server: