예제 #1
0
#Connection to Cytomine Core
conn = Cytomine(cytomine_host,
                cytomine_public_key,
                cytomine_private_key,
                base_path='/api/',
                working_path='/tmp/',
                verbose=True)

#Replace XXX with Identifiers of image, project, annotation
annotation_id = XXX
image_id = XXX
project_id = XXX

#Methods to add properties to an existing annotation
#add
annotation_property = conn.add_annotation_property(annotation_id, "key_prop",
                                                   "value_prop")
assert annotation_property != None
#get one property
annotation_property2 = conn.get_annotation_property(annotation_id,
                                                    annotation_property.id)
assert annotation_property != None
#get property collection
annotation_properties = conn.get_annotation_properties(annotation_id)
for annotation_property in annotation_properties.data():
    print "%s => %s" % (annotation_property.key, annotation_property.value)
#edit
annotation_property = conn.edit_annotation_property(annotation_id,
                                                    annotation_property.id,
                                                    "key_prop", "value_prop2")
assert annotation_property != None
#delete
예제 #2
0
#Connection to Cytomine Core
conn = Cytomine(cytomine_host,
                cytomine_public_key,
                cytomine_private_key,
                base_path='/api/',
                working_path='/tmp/',
                verbose=True)

#Replace XXX by your values
id_image = XXX
id_term = XXX

#Create one geometrical object locally (using shapely)
#circle = Point(100,100).buffer(1000)
#annotation.location=circle.wkt
#rectangle = box(100, 100, 200, 200, ccw=True)
#annotation.location=rectangle.wkt
point = Point(
    1000,
    1000)  #point at position (1000,1000) where (0,0) is bottom left corner
annotation.location = point.wkt

#Add annotation to cytomine server
new_annotation = conn.add_annotation(annotation.location, id_image)
#Add term from the project's ontology
conn.add_user_annotation_term(new_annotation.id, term=id_term)
#Add property,value to the annotation
annotation_property = conn.add_annotation_property(new_annotation.id,
                                                   "my_property", 10)
        if index == 0:
            continue
        mask = (imageData == index).astype(np.uint8) * 255
        polygons = [polygon[0].buffer(2.0) for polygon in locobj.locate(mask)]
        polygon = cascaded_union(polygons).buffer(-2.0)
        if not polygon.is_empty and polygon.area > 0:
            objects[index] = polygon

    print("Found {} polygons in this images.".format(len(objects)))
    slide = conn.get_image_instance(image.id)

    # upload
    for index, polygon in objects.items():
        annotation = _upload_annotation(conn, slide, polygon, label=None)
        if annotation:
            conn.add_annotation_property(annotation.id, "index", str(index))

job = conn.update_job_status(job,
                             status=job.TERMINATED,
                             progress=50,
                             status_comment="Cleaning up..")

# cleanup - remove the downloaded images

for image in inputImages:
    file = str(image.id) + ".tif"
    path = inDir + "/" + file
    os.remove(path)

job = conn.update_job_status(job,
                             status=job.TERMINATED,