diff --git a/tools/qupath_roi_splitter/qupath_roi_splitter.py b/tools/qupath_roi_splitter/qupath_roi_splitter.py index 1091d5af1..3a410dcc6 100644 --- a/tools/qupath_roi_splitter/qupath_roi_splitter.py +++ b/tools/qupath_roi_splitter/qupath_roi_splitter.py @@ -22,15 +22,20 @@ def collect_roi_coords(input_roi, feature_index): else: coord_index = 0 for sub_roi in input_roi["geometry"]["coordinates"]: - # Polygon with holes or MultiPolygon - if not isinstance(sub_roi[0][0], list): - all_coords.extend(collect_coords(sub_roi, feature_index, coord_index)) - coord_index += len(sub_roi) + if len(sub_roi) == 2: + # Special case: LMD data + all_coords.extend(collect_coords([sub_roi], feature_index, coord_index)) + coord_index += 1 else: - # MultiPolygon with holes - for sub_coord in sub_roi: - all_coords.extend(collect_coords(sub_coord, feature_index, coord_index)) - coord_index += len(sub_coord) + # Polygon with holes or MultiPolygon + if not isinstance(sub_roi[0][0], list): + all_coords.extend(collect_coords(sub_roi, feature_index, coord_index)) + coord_index += len(sub_roi) + else: + # MultiPolygon with holes + for sub_coord in sub_roi: + all_coords.extend(collect_coords(sub_coord, feature_index, coord_index)) + coord_index += len(sub_coord) return all_coords @@ -103,7 +108,7 @@ def split_qupath_roi(in_roi): parser = argparse.ArgumentParser(description="Split ROI coordinates of QuPath TMA annotation by cell type (classification)") parser.add_argument("--qupath_roi", default=False, help="Input QuPath annotation (GeoJSON file)") parser.add_argument("--fill", action="store_true", required=False, help="Fill pixels in ROIs (order of coordinates will be lost)") - parser.add_argument('--version', action='version', version='%(prog)s 0.3.0') + parser.add_argument('--version', action='version', version='%(prog)s 0.3.1') parser.add_argument("--all", action="store_true", required=False, help="Extracts all ROIs") parser.add_argument("--img", action="store_true", required=False, help="Generates image of ROIs") args = parser.parse_args() diff --git a/tools/qupath_roi_splitter/qupath_roi_splitter.xml b/tools/qupath_roi_splitter/qupath_roi_splitter.xml index 6cd8b0169..963b23cbc 100644 --- a/tools/qupath_roi_splitter/qupath_roi_splitter.xml +++ b/tools/qupath_roi_splitter/qupath_roi_splitter.xml @@ -1,7 +1,7 @@ Split ROI coordinates of QuPath TMA annotation by cell type (classification) - 0.3.0 + 0.3.1 0 @@ -21,7 +21,9 @@ #end for mkdir out && mv *.txt out/ + #if $optional.img && mv *.png out/ + #end if ]]> @@ -33,14 +35,15 @@ - + + optional['img'] - +