diff --git a/read_roi/_read_roi.py b/read_roi/_read_roi.py index 55e7915..31914ee 100644 --- a/read_roi/_read_roi.py +++ b/read_roi/_read_roi.py @@ -81,6 +81,13 @@ class UnrecognizedRoiType(Exception): ELLIPSE=3, IMAGE=4) +# https://docs.oracle.com/javase/6/docs/api/constant-values.html#java.awt.geom.PathIterator +PATHITERATOR_TYPES = dict(SEG_MOVETO=0, + SEG_LINETO=1, + SEG_QUADTO=2, + SEG_CUBICTO=3, + SEG_CLOSE=4) + def get_byte(data, base): if isinstance(base, int): @@ -170,6 +177,84 @@ def get_point_counters(data, hdr2Offset, n_coordinates, size): return counters, positions +def pathiterator2paths(shape_array): + """ + Converts a shape array in PathIterator notation to polygon (or curved) + paths. + + Parameters + ---------- + shape_array : list of floats + paths encoded in `java.awt.geom.PathIterator` format. Each segment + within the path begins with a header value, + + 0 : Move operation + 1 : Line segment + 2 : Quadratic segment + 3 : Cubic segment + 4 : Terminate path + + followed by a number of values describing the path along the segment + to the next node. In the case of a termination operation, the current + path ends, whilst for a move operation a new path begins with a new + node described whose co-ordinate is given by the next two value in + `shape_array`. + + Returns + ------- + paths : list of lists of tuples + The `segements` output contains a list of path paths. Each path + is a list of points along the path. In its simplest form, each tuple + in the list has length two, corresponding to a nodes along a polygon + shape. Tuples of length 4 or 6 correspond to quadratic and cubic paths + (respectively) from the previous node. + ImageJ ROIs are only known to output linear segments (even with + ellipses with subpixel precision enabled), so it is expected that all + segments along the path should be length two tuples containing only the + co-ordinates of the next point on the polygonal path. + + Notes + ----- + Based on the ShapeRoi constructor "from an array of variable length path + segments" and `makeShapeFromArray`, as found in: + https://imagej.nih.gov/ij/developer/source/ij/gui/ShapeRoi.java.html + With further reference to its `PathIterator` dependency, as found in: + https://docs.oracle.com/javase/6/docs/api/constant-values.html#java.awt.geom.PathIterator + """ + paths = [] + path = None + i = 0 + while i < len(shape_array): + segmentType = shape_array[i] + if segmentType == PATHITERATOR_TYPES["SEG_MOVETO"]: + # Move to + if path is not None: + paths.append(path) + # Start a new segment with a node at this point + path = [] + nCoords = 2 + elif segmentType == PATHITERATOR_TYPES["SEG_LINETO"]: + # Line to next point + nCoords = 2 + elif segmentType == PATHITERATOR_TYPES["SEG_QUADTO"]: + # Quadratic curve to next point + nCoords = 4 + elif segmentType == PATHITERATOR_TYPES["SEG_CUBICTO"]: + # Cubic curve to next point + nCoords = 6 + elif segmentType == PATHITERATOR_TYPES["SEG_CLOSE"]: + # Segment close + paths.append(path) + path = None + i += 1 + continue + if path is None: + raise ValueError("A path must begin with a move operation.") + path.append(tuple(shape_array[i + 1 : i + 1 + nCoords])) + i += 1 + nCoords + return paths + + def extract_basic_roi_data(data): size = len(data) code = '>' @@ -233,16 +318,38 @@ def extract_basic_roi_data(data): imageSize = get_uint32(data, hdr2Offset + HEADER_OFFSET['IMAGE_SIZE']) logging.debug("Entering in hdr2Offset") - is_composite = get_uint32(data, OFFSET['SHAPE_ROI_SIZE']) > 0 + roi_props = (hdr2Offset, n_coordinates, roi_type, channel, slice, frame, position, version, subtype, size) + + shape_roi_size = get_uint32(data, OFFSET['SHAPE_ROI_SIZE']) + is_composite = shape_roi_size > 0 - # Not implemented if is_composite: + roi = {'type': 'composite'} + + # Add bounding box rectangle details + if sub_pixel_rect: + roi.update(dict(left=xd, top=yd, width=widthd, height=heightd)) + else: + roi.update(dict(left=left, top=top, width=width, height=height)) + + # Load path iterator shape array and decode it into paths + base = OFFSET['COORDINATES'] + shape_array = [get_float(data, base + i * 4) for i in range(shape_roi_size)] + roi['paths'] = pathiterator2paths(shape_array) + + # NB: Handling position of roi is implemented in read_roi_file + if version >= 218: + # Not implemented + # Read stroke width, stroke color and fill color pass - if channel > 0 or slice > 0 or frame > 0: + if version >= 224: + # Not implemented + # Get ROI properties pass - roi_props = (hdr2Offset, n_coordinates, roi_type, channel, slice, frame, position, version, subtype, size) + return roi, roi_props + if roi_type == ROI_TYPE['rect']: roi = {'type': 'rectangle'} diff --git a/read_roi/test/data/composite-brush-donut.json b/read_roi/test/data/composite-brush-donut.json new file mode 100644 index 0000000..e043d45 --- /dev/null +++ b/read_roi/test/data/composite-brush-donut.json @@ -0,0 +1,73 @@ +{ + "composite-brush-donut": { + "type": "composite", + "left": 4, + "top": 5, + "width": 8, + "height": 3, + "paths": [ + [ + [ + 10.0, + 6.0 + ], + [ + 10.0, + 7.0 + ], + [ + 6.0, + 7.0 + ], + [ + 6.0, + 6.0 + ] + ], + [ + [ + 5.0, + 5.0 + ], + [ + 5.0, + 6.0 + ], + [ + 4.0, + 6.0 + ], + [ + 4.0, + 7.0 + ], + [ + 4.0, + 8.0 + ], + [ + 12.0, + 8.0 + ], + [ + 12.0, + 7.0 + ], + [ + 12.0, + 6.0 + ], + [ + 11.0, + 6.0 + ], + [ + 11.0, + 5.0 + ] + ] + ], + "name": "composite-brush-donut", + "position": 0 + } +} \ No newline at end of file diff --git a/read_roi/test/data/composite-brush-donut.roi b/read_roi/test/data/composite-brush-donut.roi new file mode 100644 index 0000000..bc4626e Binary files /dev/null and b/read_roi/test/data/composite-brush-donut.roi differ diff --git a/read_roi/test/data/composite-brush-yin-yang.json b/read_roi/test/data/composite-brush-yin-yang.json new file mode 100644 index 0000000..a800f61 --- /dev/null +++ b/read_roi/test/data/composite-brush-yin-yang.json @@ -0,0 +1,559 @@ +{ + "composite-brush-yin-yang": { + "type": "composite", + "left": 4, + "top": 0, + "width": 25, + "height": 42, + "paths": [ + [ + [ + 22.0, + 5.0 + ], + [ + 22.0, + 6.0 + ], + [ + 23.0, + 6.0 + ], + [ + 23.0, + 10.0 + ], + [ + 22.0, + 10.0 + ], + [ + 22.0, + 11.0 + ], + [ + 18.0, + 11.0 + ], + [ + 18.0, + 10.0 + ], + [ + 17.0, + 10.0 + ], + [ + 17.0, + 6.0 + ], + [ + 18.0, + 6.0 + ], + [ + 18.0, + 5.0 + ] + ], + [ + [ + 20.0, + 25.0 + ], + [ + 20.0, + 26.0 + ], + [ + 19.0, + 26.0 + ], + [ + 19.0, + 30.0 + ], + [ + 20.0, + 30.0 + ], + [ + 20.0, + 31.0 + ], + [ + 24.0, + 31.0 + ], + [ + 24.0, + 30.0 + ], + [ + 25.0, + 30.0 + ], + [ + 25.0, + 26.0 + ], + [ + 24.0, + 26.0 + ], + [ + 24.0, + 25.0 + ] + ], + [ + [ + 17.0, + 0.0 + ], + [ + 17.0, + 1.0 + ], + [ + 14.0, + 1.0 + ], + [ + 14.0, + 2.0 + ], + [ + 13.0, + 2.0 + ], + [ + 13.0, + 4.0 + ], + [ + 11.0, + 4.0 + ], + [ + 11.0, + 5.0 + ], + [ + 10.0, + 5.0 + ], + [ + 10.0, + 6.0 + ], + [ + 9.0, + 6.0 + ], + [ + 9.0, + 8.0 + ], + [ + 8.0, + 8.0 + ], + [ + 8.0, + 10.0 + ], + [ + 7.0, + 10.0 + ], + [ + 7.0, + 13.0 + ], + [ + 6.0, + 13.0 + ], + [ + 6.0, + 15.0 + ], + [ + 5.0, + 15.0 + ], + [ + 5.0, + 17.0 + ], + [ + 4.0, + 17.0 + ], + [ + 4.0, + 21.0 + ], + [ + 4.0, + 25.0 + ], + [ + 4.0, + 27.0 + ], + [ + 5.0, + 27.0 + ], + [ + 5.0, + 31.0 + ], + [ + 6.0, + 31.0 + ], + [ + 6.0, + 33.0 + ], + [ + 7.0, + 33.0 + ], + [ + 7.0, + 34.0 + ], + [ + 8.0, + 34.0 + ], + [ + 8.0, + 35.0 + ], + [ + 9.0, + 35.0 + ], + [ + 9.0, + 36.0 + ], + [ + 10.0, + 36.0 + ], + [ + 10.0, + 37.0 + ], + [ + 11.0, + 37.0 + ], + [ + 11.0, + 38.0 + ], + [ + 12.0, + 38.0 + ], + [ + 12.0, + 39.0 + ], + [ + 13.0, + 39.0 + ], + [ + 13.0, + 40.0 + ], + [ + 14.0, + 40.0 + ], + [ + 14.0, + 41.0 + ], + [ + 17.0, + 41.0 + ], + [ + 17.0, + 42.0 + ], + [ + 23.0, + 42.0 + ], + [ + 23.0, + 41.0 + ], + [ + 25.0, + 41.0 + ], + [ + 25.0, + 40.0 + ], + [ + 26.0, + 40.0 + ], + [ + 26.0, + 38.0 + ], + [ + 23.0, + 38.0 + ], + [ + 23.0, + 39.0 + ], + [ + 22.0, + 39.0 + ], + [ + 22.0, + 38.0 + ], + [ + 19.0, + 38.0 + ], + [ + 19.0, + 36.0 + ], + [ + 18.0, + 36.0 + ], + [ + 18.0, + 35.0 + ], + [ + 17.0, + 35.0 + ], + [ + 17.0, + 34.0 + ], + [ + 16.0, + 34.0 + ], + [ + 16.0, + 33.0 + ], + [ + 15.0, + 33.0 + ], + [ + 15.0, + 32.0 + ], + [ + 14.0, + 32.0 + ], + [ + 14.0, + 31.0 + ], + [ + 13.0, + 31.0 + ], + [ + 13.0, + 30.0 + ], + [ + 13.0, + 29.0 + ], + [ + 13.0, + 27.0 + ], + [ + 13.0, + 26.0 + ], + [ + 13.0, + 25.0 + ], + [ + 13.0, + 24.0 + ], + [ + 14.0, + 24.0 + ], + [ + 14.0, + 23.0 + ], + [ + 14.0, + 22.0 + ], + [ + 15.0, + 22.0 + ], + [ + 15.0, + 21.0 + ], + [ + 16.0, + 21.0 + ], + [ + 16.0, + 20.0 + ], + [ + 16.0, + 19.0 + ], + [ + 17.0, + 19.0 + ], + [ + 17.0, + 18.0 + ], + [ + 18.0, + 18.0 + ], + [ + 18.0, + 17.0 + ], + [ + 20.0, + 17.0 + ], + [ + 20.0, + 16.0 + ], + [ + 24.0, + 16.0 + ], + [ + 24.0, + 15.0 + ], + [ + 26.0, + 15.0 + ], + [ + 26.0, + 14.0 + ], + [ + 27.0, + 14.0 + ], + [ + 27.0, + 13.0 + ], + [ + 28.0, + 13.0 + ], + [ + 28.0, + 12.0 + ], + [ + 29.0, + 12.0 + ], + [ + 29.0, + 11.0 + ], + [ + 29.0, + 10.0 + ], + [ + 29.0, + 6.0 + ], + [ + 28.0, + 6.0 + ], + [ + 28.0, + 4.0 + ], + [ + 27.0, + 4.0 + ], + [ + 27.0, + 3.0 + ], + [ + 26.0, + 3.0 + ], + [ + 26.0, + 2.0 + ], + [ + 24.0, + 2.0 + ], + [ + 24.0, + 1.0 + ], + [ + 23.0, + 1.0 + ], + [ + 23.0, + 0.0 + ] + ] + ], + "name": "composite-brush-yin-yang", + "position": 0 + } +} \ No newline at end of file diff --git a/read_roi/test/data/composite-brush-yin-yang.roi b/read_roi/test/data/composite-brush-yin-yang.roi new file mode 100644 index 0000000..dcc6a3f Binary files /dev/null and b/read_roi/test/data/composite-brush-yin-yang.roi differ diff --git a/read_roi/test/data/composite-oval-in-rect.json b/read_roi/test/data/composite-oval-in-rect.json new file mode 100644 index 0000000..0dd48a8 --- /dev/null +++ b/read_roi/test/data/composite-oval-in-rect.json @@ -0,0 +1,209 @@ +{ + "composite-oval-in-rect": { + "type": "composite", + "left": 49, + "top": 31, + "width": 47, + "height": 26, + "paths": [ + [ + [ + 76.0, + 37.0 + ], + [ + 76.0, + 38.0 + ], + [ + 79.0, + 38.0 + ], + [ + 79.0, + 39.0 + ], + [ + 81.0, + 39.0 + ], + [ + 81.0, + 40.0 + ], + [ + 82.0, + 40.0 + ], + [ + 82.0, + 41.0 + ], + [ + 83.0, + 41.0 + ], + [ + 83.0, + 42.0 + ], + [ + 84.0, + 42.0 + ], + [ + 84.0, + 47.0 + ], + [ + 83.0, + 47.0 + ], + [ + 83.0, + 48.0 + ], + [ + 82.0, + 48.0 + ], + [ + 82.0, + 49.0 + ], + [ + 81.0, + 49.0 + ], + [ + 81.0, + 50.0 + ], + [ + 79.0, + 50.0 + ], + [ + 79.0, + 51.0 + ], + [ + 76.0, + 51.0 + ], + [ + 76.0, + 52.0 + ], + [ + 68.0, + 52.0 + ], + [ + 68.0, + 51.0 + ], + [ + 65.0, + 51.0 + ], + [ + 65.0, + 50.0 + ], + [ + 63.0, + 50.0 + ], + [ + 63.0, + 49.0 + ], + [ + 62.0, + 49.0 + ], + [ + 62.0, + 48.0 + ], + [ + 61.0, + 48.0 + ], + [ + 61.0, + 47.0 + ], + [ + 60.0, + 47.0 + ], + [ + 60.0, + 42.0 + ], + [ + 61.0, + 42.0 + ], + [ + 61.0, + 41.0 + ], + [ + 62.0, + 41.0 + ], + [ + 62.0, + 40.0 + ], + [ + 63.0, + 40.0 + ], + [ + 63.0, + 39.0 + ], + [ + 65.0, + 39.0 + ], + [ + 65.0, + 38.0 + ], + [ + 68.0, + 38.0 + ], + [ + 68.0, + 37.0 + ] + ], + [ + [ + 49.0, + 31.0 + ], + [ + 49.0, + 57.0 + ], + [ + 96.0, + 57.0 + ], + [ + 96.0, + 31.0 + ] + ] + ], + "name": "composite-oval-in-rect", + "position": 0 + } +} \ No newline at end of file diff --git a/read_roi/test/data/composite-oval-in-rect.roi b/read_roi/test/data/composite-oval-in-rect.roi new file mode 100644 index 0000000..0e1c4a3 Binary files /dev/null and b/read_roi/test/data/composite-oval-in-rect.roi differ diff --git a/read_roi/test/data/composite-rect-in-rect.json b/read_roi/test/data/composite-rect-in-rect.json new file mode 100644 index 0000000..df355a5 --- /dev/null +++ b/read_roi/test/data/composite-rect-in-rect.json @@ -0,0 +1,49 @@ +{ + "composite-rect-in-rect": { + "type": "composite", + "left": 40, + "top": 61, + "width": 61, + "height": 42, + "paths": [ + [ + [ + 84.0, + 75.0 + ], + [ + 84.0, + 93.0 + ], + [ + 53.0, + 93.0 + ], + [ + 53.0, + 75.0 + ] + ], + [ + [ + 40.0, + 61.0 + ], + [ + 40.0, + 103.0 + ], + [ + 101.0, + 103.0 + ], + [ + 101.0, + 61.0 + ] + ] + ], + "name": "composite-rect-in-rect", + "position": 0 + } +} \ No newline at end of file diff --git a/read_roi/test/data/composite-rect-in-rect.roi b/read_roi/test/data/composite-rect-in-rect.roi new file mode 100644 index 0000000..c7f71ee Binary files /dev/null and b/read_roi/test/data/composite-rect-in-rect.roi differ diff --git a/read_roi/test/data/composite-two-ellipses.json b/read_roi/test/data/composite-two-ellipses.json new file mode 100644 index 0000000..c8c3d24 --- /dev/null +++ b/read_roi/test/data/composite-two-ellipses.json @@ -0,0 +1,601 @@ +{ + "composite-two-ellipses": { + "type": "composite", + "left": 37, + "top": 11, + "width": 39, + "height": 72, + "paths": [ + [ + [ + 48.23475646972656, + 11.676057815551758 + ], + [ + 46.79706954956055, + 11.71623706817627 + ], + [ + 45.433231353759766, + 11.880345344543457 + ], + [ + 44.15361404418945, + 12.167133331298828 + ], + [ + 42.96796417236328, + 12.574419021606445 + ], + [ + 41.88529968261719, + 13.099102973937988 + ], + [ + 40.91386032104492, + 13.737192153930664 + ], + [ + 40.06104278564453, + 14.483829498291016 + ], + [ + 39.33333206176758, + 15.333333015441895 + ], + [ + 38.73627471923828, + 16.279237747192383 + ], + [ + 38.27440643310547, + 17.31434440612793 + ], + [ + 37.95124816894531, + 18.430776596069336 + ], + [ + 37.769256591796875, + 19.62003517150879 + ], + [ + 37.72981643676758, + 20.873069763183594 + ], + [ + 37.833229064941406, + 22.18034553527832 + ], + [ + 38.07870864868164, + 23.531911849975586 + ], + [ + 38.464385986328125, + 24.917482376098633 + ], + [ + 38.98732376098633, + 26.326513290405273 + ], + [ + 39.6435432434082, + 27.748281478881836 + ], + [ + 40.42804718017578, + 29.171964645385742 + ], + [ + 41.33487319946289, + 30.586729049682617 + ], + [ + 42.357112884521484, + 31.9818058013916 + ], + [ + 43.48699188232422, + 33.346580505371094 + ], + [ + 44.715904235839844, + 34.67066192626953 + ], + [ + 46.03450012207031, + 35.94397735595703 + ], + [ + 47.43274688720703, + 37.15683364868164 + ], + [ + 48.900001525878906, + 38.29999923706055 + ], + [ + 50.42509460449219, + 39.364776611328125 + ], + [ + 51.996421813964844, + 40.34306335449219 + ], + [ + 53.60202407836914, + 41.22740936279297 + ], + [ + 55.22968292236328, + 42.01108932495117 + ], + [ + 56.867008209228516, + 42.688133239746094 + ], + [ + 58.50154113769531, + 43.253395080566406 + ], + [ + 60.1208381652832, + 43.70256805419922 + ], + [ + 61.712581634521484, + 44.03223419189453 + ], + [ + 63.26465606689453, + 44.23988723754883 + ], + [ + 64.76524353027344, + 44.32394027709961 + ], + [ + 66.20292663574219, + 44.28376388549805 + ], + [ + 67.5667724609375, + 44.11965560913086 + ], + [ + 68.84638214111328, + 43.83286666870117 + ], + [ + 70.03203582763672, + 43.42557907104492 + ], + [ + 71.11470031738281, + 42.90089797973633 + ], + [ + 72.08614349365234, + 42.2628059387207 + ], + [ + 72.93895721435547, + 41.516170501708984 + ], + [ + 73.66666412353516, + 40.66666793823242 + ], + [ + 74.26372528076172, + 39.720760345458984 + ], + [ + 74.72559356689453, + 38.68565368652344 + ], + [ + 75.04875183105469, + 37.5692253112793 + ], + [ + 75.23074340820312, + 36.379966735839844 + ], + [ + 75.27017974853516, + 35.126930236816406 + ], + [ + 75.1667709350586, + 33.81965637207031 + ], + [ + 74.9212875366211, + 32.46809005737305 + ], + [ + 74.53561401367188, + 31.082517623901367 + ], + [ + 74.01268005371094, + 29.673486709594727 + ], + [ + 73.35646057128906, + 28.251718521118164 + ], + [ + 72.57195281982422, + 26.828035354614258 + ], + [ + 71.66512298583984, + 25.413270950317383 + ], + [ + 70.64288330078125, + 24.0181941986084 + ], + [ + 69.51300811767578, + 22.65342140197754 + ], + [ + 68.28409576416016, + 21.32933807373047 + ], + [ + 66.96549987792969, + 20.0560245513916 + ], + [ + 65.56725311279297, + 18.843168258666992 + ], + [ + 64.0999984741211, + 17.700000762939453 + ], + [ + 62.57490539550781, + 16.635221481323242 + ], + [ + 61.003578186035156, + 15.656936645507812 + ], + [ + 59.39797592163086, + 14.772589683532715 + ], + [ + 57.77031707763672, + 13.988910675048828 + ], + [ + 56.132991790771484, + 13.311864852905273 + ], + [ + 54.49845886230469, + 12.746604919433594 + ], + [ + 52.8791618347168, + 12.297431945800781 + ], + [ + 51.287418365478516, + 11.967765808105469 + ], + [ + 49.73534393310547, + 11.760114669799805 + ], + [ + 48.23475646972656, + 11.676057815551758 + ] + ], + [ + [ + 51.110687255859375, + 49.18461608886719 + ], + [ + 50.21076202392578, + 49.19566345214844 + ], + [ + 49.33333206176758, + 49.33333206176758 + ], + [ + 48.485076904296875, + 49.596580505371094 + ], + [ + 47.672454833984375, + 49.983394622802734 + ], + [ + 46.901641845703125, + 50.490840911865234 + ], + [ + 46.17851257324219, + 51.11505126953125 + ], + [ + 45.508567810058594, + 51.85127639770508 + ], + [ + 44.89690399169922, + 52.693912506103516 + ], + [ + 44.34817886352539, + 53.63655090332031 + ], + [ + 43.8665657043457, + 54.67201232910156 + ], + [ + 43.45573425292969, + 55.792415618896484 + ], + [ + 43.11880874633789, + 56.98923873901367 + ], + [ + 42.85835266113281, + 58.25337219238281 + ], + [ + 42.67634963989258, + 59.575191497802734 + ], + [ + 42.57418441772461, + 60.94464111328125 + ], + [ + 42.55263137817383, + 62.351295471191406 + ], + [ + 42.61186218261719, + 63.784446716308594 + ], + [ + 42.75141906738281, + 65.23319244384766 + ], + [ + 42.97024154663086, + 66.68650817871094 + ], + [ + 43.266666412353516, + 68.13333129882812 + ], + [ + 43.63843536376953, + 69.56265258789062 + ], + [ + 44.08272171020508, + 70.96358489990234 + ], + [ + 44.59614181518555, + 72.32547760009766 + ], + [ + 45.17478561401367, + 73.6379623413086 + ], + [ + 45.81425476074219, + 74.89104461669922 + ], + [ + 46.509681701660156, + 76.0751953125 + ], + [ + 47.25577163696289, + 77.181396484375 + ], + [ + 48.046844482421875, + 78.20123291015625 + ], + [ + 48.87688446044922, + 79.12693786621094 + ], + [ + 49.73957443237305, + 79.95147705078125 + ], + [ + 50.62834167480469, + 80.66857147216797 + ], + [ + 51.53643035888672, + 81.27275085449219 + ], + [ + 52.45692443847656, + 81.75943756103516 + ], + [ + 53.3828239440918, + 82.12490844726562 + ], + [ + 54.30707550048828, + 82.36639404296875 + ], + [ + 55.2226448059082, + 82.4820556640625 + ], + [ + 56.1225700378418, + 82.47100067138672 + ], + [ + 57.0, + 82.33333587646484 + ], + [ + 57.8482551574707, + 82.0700912475586 + ], + [ + 58.66088104248047, + 81.68327331542969 + ], + [ + 59.43169021606445, + 81.17582702636719 + ], + [ + 60.15481948852539, + 80.5516128540039 + ], + [ + 60.82476806640625, + 79.81539154052734 + ], + [ + 61.436431884765625, + 78.9727554321289 + ], + [ + 61.98515701293945, + 78.03011322021484 + ], + [ + 62.466766357421875, + 76.9946517944336 + ], + [ + 62.877601623535156, + 75.87425231933594 + ], + [ + 63.21452713012695, + 74.67742919921875 + ], + [ + 63.47498321533203, + 73.41329193115234 + ], + [ + 63.656986236572266, + 72.09147644042969 + ], + [ + 63.759151458740234, + 70.7220230102539 + ], + [ + 63.78070068359375, + 69.31537628173828 + ], + [ + 63.721473693847656, + 67.88221740722656 + ], + [ + 63.581912994384766, + 66.4334716796875 + ], + [ + 63.36309051513672, + 64.98015594482422 + ], + [ + 63.06666564941406, + 63.53333282470703 + ], + [ + 62.69489669799805, + 62.1040153503418 + ], + [ + 62.2506103515625, + 60.70307922363281 + ], + [ + 61.7371940612793, + 59.341190338134766 + ], + [ + 61.158546447753906, + 58.028709411621094 + ], + [ + 60.51907730102539, + 56.7756233215332 + ], + [ + 59.82365036010742, + 55.59147644042969 + ], + [ + 59.07756042480469, + 54.48527145385742 + ], + [ + 58.2864875793457, + 53.46543502807617 + ], + [ + 57.45644760131836, + 52.53972625732422 + ], + [ + 56.5937614440918, + 51.715187072753906 + ], + [ + 55.70499038696289, + 50.99810028076172 + ], + [ + 54.79690170288086, + 50.39391326904297 + ], + [ + 53.876407623291016, + 49.90723419189453 + ], + [ + 52.95051193237305, + 49.5417594909668 + ], + [ + 52.02626037597656, + 49.30027389526367 + ], + [ + 51.110687255859375, + 49.18461608886719 + ] + ] + ], + "name": "composite-two-ellipses", + "position": 0 + } +} \ No newline at end of file diff --git a/read_roi/test/data/composite-two-ellipses.roi b/read_roi/test/data/composite-two-ellipses.roi new file mode 100644 index 0000000..c82be4a Binary files /dev/null and b/read_roi/test/data/composite-two-ellipses.roi differ diff --git a/read_roi/test/data/composite-two-ovals.json b/read_roi/test/data/composite-two-ovals.json new file mode 100644 index 0000000..4563291 --- /dev/null +++ b/read_roi/test/data/composite-two-ovals.json @@ -0,0 +1,401 @@ +{ + "composite-two-ovals": { + "type": "composite", + "left": 3, + "top": 7, + "width": 32, + "height": 43, + "paths": [ + [ + [ + 21.0, + 7.0 + ], + [ + 21.0, + 8.0 + ], + [ + 18.0, + 8.0 + ], + [ + 18.0, + 9.0 + ], + [ + 17.0, + 9.0 + ], + [ + 17.0, + 10.0 + ], + [ + 16.0, + 10.0 + ], + [ + 16.0, + 11.0 + ], + [ + 15.0, + 11.0 + ], + [ + 15.0, + 13.0 + ], + [ + 14.0, + 13.0 + ], + [ + 14.0, + 17.0 + ], + [ + 15.0, + 17.0 + ], + [ + 15.0, + 19.0 + ], + [ + 16.0, + 19.0 + ], + [ + 16.0, + 20.0 + ], + [ + 17.0, + 20.0 + ], + [ + 17.0, + 21.0 + ], + [ + 18.0, + 21.0 + ], + [ + 18.0, + 22.0 + ], + [ + 21.0, + 22.0 + ], + [ + 21.0, + 23.0 + ], + [ + 28.0, + 23.0 + ], + [ + 28.0, + 22.0 + ], + [ + 31.0, + 22.0 + ], + [ + 31.0, + 21.0 + ], + [ + 32.0, + 21.0 + ], + [ + 32.0, + 20.0 + ], + [ + 33.0, + 20.0 + ], + [ + 33.0, + 19.0 + ], + [ + 34.0, + 19.0 + ], + [ + 34.0, + 17.0 + ], + [ + 35.0, + 17.0 + ], + [ + 35.0, + 13.0 + ], + [ + 34.0, + 13.0 + ], + [ + 34.0, + 11.0 + ], + [ + 33.0, + 11.0 + ], + [ + 33.0, + 10.0 + ], + [ + 32.0, + 10.0 + ], + [ + 32.0, + 9.0 + ], + [ + 31.0, + 9.0 + ], + [ + 31.0, + 8.0 + ], + [ + 28.0, + 8.0 + ], + [ + 28.0, + 7.0 + ] + ], + [ + [ + 11.0, + 27.0 + ], + [ + 11.0, + 28.0 + ], + [ + 9.0, + 28.0 + ], + [ + 9.0, + 29.0 + ], + [ + 7.0, + 29.0 + ], + [ + 7.0, + 30.0 + ], + [ + 6.0, + 30.0 + ], + [ + 6.0, + 31.0 + ], + [ + 5.0, + 31.0 + ], + [ + 5.0, + 33.0 + ], + [ + 4.0, + 33.0 + ], + [ + 4.0, + 35.0 + ], + [ + 3.0, + 35.0 + ], + [ + 3.0, + 42.0 + ], + [ + 4.0, + 42.0 + ], + [ + 4.0, + 44.0 + ], + [ + 5.0, + 44.0 + ], + [ + 5.0, + 46.0 + ], + [ + 6.0, + 46.0 + ], + [ + 6.0, + 47.0 + ], + [ + 7.0, + 47.0 + ], + [ + 7.0, + 48.0 + ], + [ + 9.0, + 48.0 + ], + [ + 9.0, + 49.0 + ], + [ + 11.0, + 49.0 + ], + [ + 11.0, + 50.0 + ], + [ + 18.0, + 50.0 + ], + [ + 18.0, + 49.0 + ], + [ + 20.0, + 49.0 + ], + [ + 20.0, + 48.0 + ], + [ + 22.0, + 48.0 + ], + [ + 22.0, + 47.0 + ], + [ + 23.0, + 47.0 + ], + [ + 23.0, + 46.0 + ], + [ + 24.0, + 46.0 + ], + [ + 24.0, + 44.0 + ], + [ + 25.0, + 44.0 + ], + [ + 25.0, + 42.0 + ], + [ + 26.0, + 42.0 + ], + [ + 26.0, + 35.0 + ], + [ + 25.0, + 35.0 + ], + [ + 25.0, + 33.0 + ], + [ + 24.0, + 33.0 + ], + [ + 24.0, + 31.0 + ], + [ + 23.0, + 31.0 + ], + [ + 23.0, + 30.0 + ], + [ + 22.0, + 30.0 + ], + [ + 22.0, + 29.0 + ], + [ + 20.0, + 29.0 + ], + [ + 20.0, + 28.0 + ], + [ + 18.0, + 28.0 + ], + [ + 18.0, + 27.0 + ] + ] + ], + "name": "composite-two-ovals", + "position": 0 + } +} \ No newline at end of file diff --git a/read_roi/test/data/composite-two-ovals.roi b/read_roi/test/data/composite-two-ovals.roi new file mode 100644 index 0000000..07bf1b1 Binary files /dev/null and b/read_roi/test/data/composite-two-ovals.roi differ diff --git a/read_roi/test/test_read_roi.py b/read_roi/test/test_read_roi.py index e756af1..48fc044 100644 --- a/read_roi/test/test_read_roi.py +++ b/read_roi/test/test_read_roi.py @@ -16,7 +16,15 @@ def load_data(name): def load_true_data(name): fname = os.path.join(data_dir, name + ".json") - return json.load(open(fname)) + data = json.load(open(fname)) + true_name = list(data.keys())[0] + if 'paths' in data[true_name]: + # Convert segment nodes from list to tuples + data[true_name]['paths'] = [ + [tuple(segment) for segment in path] + for path in data[true_name]['paths'] + ] + return data @nottest @@ -73,6 +81,12 @@ def test_line2(): def test_rois(): names = [ + "composite-brush-donut", + "composite-brush-yin-yang", + "composite-oval-in-rect", + "composite-rect-in-rect", + "composite-two-ellipses", + "composite-two-ovals", "ellipse", "ellipse-left", "ellipse-top",