Skip to content

Commit

Permalink
fixed the issue that polyline is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
nanli-emory committed May 30, 2024
1 parent eeb96e7 commit 134c75b
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions DicomAnnotUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,15 @@ def dicomToCamic(annot_path, image_dimensions, output_file, source_url=None, sli
#print("prev", prevIndex, "idx", idx)
# make a thing
points = coordinates_array[prevIndex:end_idx, :]
points = np.concatenate((points, [points[0]]))
polygon = np.concatenate((points, [points[0]]))
#print('len(points)', len(points))
if len(points) > 0:
newFeature = deepcopy(featureTemplate)
if x.GraphicType == "POLYLINE":
newFeature['geometry']['type'] = "Polyline"
newFeature['geometry']['coordinates'].append(points.tolist())
newFeature['geometry']['coordinates'].append(points.tolist())
else:
newFeature['geometry']['coordinates'].append(polygon.tolist())
bounding_box = _makeBound(points)
# [[min_x, min_y], [min_x, max_y], [max_x, max_y], [max_x, min_y],[min_x, min_y]]
newFeature['bound']['coordinates'].append(bounding_box)
Expand All @@ -403,12 +405,14 @@ def dicomToCamic(annot_path, image_dimensions, output_file, source_url=None, sli
# and the bound
# then add the last one
points = coordinates_array[prevIndex:, :]
points = np.concatenate((points, [points[0]]))
polygon = np.concatenate((points, [points[0]]))
if len(points) > 0:
newFeature = deepcopy(featureTemplate)
if x.GraphicType == "POLYLINE":
newFeature['geometry']['type'] = "Polyline"
newFeature['geometry']['coordinates'].append(points.tolist())
newFeature['geometry']['coordinates'].append(points.tolist())
else:
newFeature['geometry']['coordinates'].append(polygon.tolist())
bounding_box = _makeBound(points)
# [[min_x, min_y], [min_x, max_y], [max_x, max_y], [max_x, min_y],[min_x, min_y]]
newFeature['bound']['coordinates'].append(bounding_box)
Expand All @@ -426,11 +430,13 @@ def dicomToCamic(annot_path, image_dimensions, output_file, source_url=None, sli
else:
# whole thing at once. Only do area and circumference here.
points = coordinates_array
points = np.concatenate((points, [points[0]]))
polygon = np.concatenate((points, [points[0]]))
newFeature = deepcopy(featureTemplate)
if x.GraphicType == "POLYLINE":
newFeature['geometry']['type'] = "Polyline"
newFeature['geometry']['coordinates'].append(points.tolist())
newFeature['geometry']['coordinates'].append(points.tolist())
else:
newFeature['geometry']['coordinates'].append(polygon.tolist())
bounding_box = _makeBound(points)
# [[min_x, min_y], [min_x, max_y], [max_x, max_y], [max_x, min_y],[min_x, min_y]]
newFeature['bound']['coordinates'].append(bounding_box)
Expand Down

0 comments on commit 134c75b

Please sign in to comment.