hadim / read-roi

Read ROI files .zip or .roi generated with ImageJ.
BSD 3-Clause "New" or "Revised" License
51 stars 22 forks source link

Cannot read in composite ROIs #9

Closed OSchoppe closed 4 years ago

OSchoppe commented 5 years ago

In ImageJ, there can be ROIs of the type "composite". This will, for instance, be the case if several regions are marked in a single z-slice of a volume.

It looks like the current implementation of this package cannot read in those composites correctly. For me, it only returns a rectangle comprising the bounding box of the individual regions. I have not found a way to solve this issue.

However, a colleague wrote a small code snippet for Fiji as a workaround. This code snippet takes all composite ROIs and splits them up. Then, they can be processed with this package. If useful for you, please find the code below. Credits go to Mihail Todorov (LMU Munich):

// convert composite type ROIs for Python input
setBatchMode(true);
for (i=0; i<roiManager("count"); i++) { 
    roiManager("select", i);
    roiType=Roi.getType;
    if (roiType == "composite") {
        //print("type: "+roiType);
        roiManager("Split");
    }
  }
setBatchMode(false);
showMessage("Macro finished");

Small side note: Fiji/ImageJ for some reason requires to read in the data for which the ROI was defined in order to open/process the ROIs. Depending on the size of your data, this can be slow. We found that this works substantially faster if you just define a blank stack of 8 bit images of the same size.

hadim commented 4 years ago

Another person got the same issue:

I have just found your program and it is just what I need, but I am having problems with a particular imageJ ROI type called "composite". I can see from the ROI manager description: 1 Roi_name Composite 124 98 35 44 none none 0 17 0 17 0

when I read it using your program:

{'Roi_name': {'type': 'rectangle', 'left': 124, 'top': 98, 'width': 35, 'height': 44, 'arc_size': 0, 'name': '

Roi_name', 'position': 17}}

I imagine that the "composite" type is not in the ROI_TYPE posibilities and the rectangle is selected when an unknown is found. I would assume that the properties of the composite should be the same as the freehand. I have attached an example in order to help you.

If anyone wants to submit a PR about it, I would be happy to review and merge it.

hadim commented 4 years ago

Should be fixed.

scottclowe commented 4 years ago

Thanks for reporting this, @OSchoppe. Full support for composite ROIs was added in v1.6.0.

Composite ROIs have a 'paths' dictionary key, which contains a list of all the paths in the composite ROI. Each path is a list of co-ordinates for the nodes along the path. As per the .roi file contents, the paths are not closed, so you will have to repeat the starting co-ordinate at the end of each path if you wish to close the path. Each path begins at its top-most point, and I believe the paths are listed in order of their top-most point but I am not sure on this. The nesting of the paths is left for the user to determine. Each outermost path describes a region of pixels which are included in the ROI, whereas a path immediately inside this describes pixels which are excluded (and a path inside that describes pixels to be included again).