/
test_roi.py
22 lines (17 loc) · 2.72 KB
/
test_roi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import json
from cornerstone_widget import get_bbox_handles
_test_bbox_json = """
{"imageIdToolState": {"": {"rectangleRoi": {"data": [{"visible": true, "active": false, "invalidated": false, "handles": {"start": {"x": 553.3138489596392, "y": 449.722433543228, "highlight": true, "active": false}, "end": {"x": 835.5569648554714, "y": 705.8887398182495, "highlight": true, "active": false}, "textBox": {"active": false, "hasMoved": false, "movesIndependently": false, "drawnIndependently": true, "allowedOutsideImage": true, "hasBoundingBox": true, "x": 835.5569648554714, "y": 577.8055866807388, "boundingBox": {"width": 150.8333282470703, "height": 65, "left": 312.93333435058605, "top": 195.39999389648438}}}, "meanStdDev": {"count": 72731, "mean": 137.81189589033562, "variance": 484.0080783665253, "stdDev": 22.00018359847311}, "area": 72301.17647058812}]}}}, "elementToolState": {}, "elementViewport": {}, "viewing_time": 77.17544794082642}
"""
_test_bbox_json_2 = """
{"imageIdToolState": {"": {"rectangleRoi": {"data": [{"visible": true, "active": false, "invalidated": false, "handles": {"start": {"x": 196.03125, "y": 417.8125, "highlight": true, "active": false}, "end": {"x": 478.03125, "y": 625.8125, "highlight": true, "active": false}, "textBox": {"active": false, "hasMoved": false, "movesIndependently": false, "drawnIndependently": true, "allowedOutsideImage": true, "hasBoundingBox": true, "x": 478.03125, "y": 521.8125, "boundingBox": {"width": 150.9033203125, "height": 65, "left": 239.015625, "top": 228.40625}}}, "meanStdDev": {"count": 58656, "mean": 145.6067352181388, "variance": 1398.8774714024185, "stdDev": 37.40157044032267}, "area": 58656}, {"visible": true, "active": true, "invalidated": false, "handles": {"start": {"x": 658.03125, "y": 497.8125, "highlight": true, "active": false}, "end": {"x": 912.03125, "y": 577.8125, "highlight": true, "active": false}, "textBox": {"active": false, "hasMoved": false, "movesIndependently": false, "drawnIndependently": true, "allowedOutsideImage": true, "hasBoundingBox": true, "x": 912.03125, "y": 537.8125, "boundingBox": {"width": 150.9033203125, "height": 65, "left": 456.015625, "top": 236.40625}}}, "meanStdDev": {"count": 20320, "mean": 136.35415690597338, "variance": 813.4574721617173, "stdDev": 28.521175855173244}, "area": 20320}]}}}, "elementToolState": {}, "elementViewport": {}, "viewing_time": 63.09548878669739}"""
def test_bbox_parser():
a_bbox = get_bbox_handles(json.loads(_test_bbox_json))
assert len(a_bbox) == 1
assert len(a_bbox[0]['x']) == 2
assert a_bbox[0]['x'][0] > 500
assert a_bbox[0]['x'][1] < 900
b_bbox = get_bbox_handles(json.loads(_test_bbox_json_2))
assert len(b_bbox) == 2
assert b_bbox[0]['x'][0] < 200
assert b_bbox[0]['x'][1] > 450