Give a string with the name of the image-file that was annotated with the Annotation Compass; Select a specific area of the image, return a list of all labels in that specific area.

Input

  • image [str]
  • left [int]
  • right [int]
  • top [int]
  • bottom [int]

Output

  • area_map [list]

Endpoint

https://hub.xpub.nl/soupboat/si16/api/area_map/ ? image=<image> & left=<left> & right=<right> & top=<top> & bottom=<bottom>

Try it



area_map

Give a string with the name of the image-file that was annotated with the Annotation Compass; Select a specific area of the image, return a list of all labels in that specific area.

def area_map(image: str, left: int, right: int, top: int, bottom: int ) -> list:

    """Give a string with the name of the image-file that was annotated with the Annotation Compass; Select a specific area of the image, return a list of all labels in that specific area."""    

    from urllib.request import urlopen
    import json


    url = f"https://hub.xpub.nl/soupboat/si16/annotation-compass/get-labels/{image}/"
    response = urlopen(url)
    data_json = json.loads(response.read())    

    filtered_map = []
    for label in data_json['labels']:
        if left <= (label['position']['x']) <= right and top <= (label['position']['y']) <= bottom:
            filtered_map.append(label)

    return filtered_map

This function was built for a project where individuals are invited to add their annotations on a map using the Annotation Compass. Each annotation-label is stored in a json-file and includes the annotation-text itself, but also the name of the image-file as well as the position, size, index, timestamp and userID of the annotation.

Example for a label:

{'image': 'map.jpg',
'position': {'x': 12, 'y': 97},
'size': {'width': 43, 'height': 18},
'text': 'This is a text! Is this a text?',
'timestamp': 'Wed, 01 Dec 2021 14:04:00 GMT',
'userID': 5766039063}

If interested in the annotations in a specific area of the map, area_map() can help. The function needs a string with the name of the of the image-file that was annotated with the annotation compass tool as well as four specific values to define the left, right, top and bottom outlines of the selected area. The output is a list of all labels in the defined area of interest.

How to get a json-file with annotation-labels?

https://hub.xpub.nl/soupboat/generic-labels/

The Annotation Compass allows people to uplaod an image and ask others to annotate it. A json-file of the annotations is provided.

Examples

In this example, the function returns all annotation-labels in an area of interest that reaches from x = 70% to x = 90% and from y = 10% to y = 100%

area_map('rejection_map.jpg', 70, 90, 10, 100)
[{'image': 'rejection_map.jpg',
  'position': {'x': 76.25, 'y': 69.5246},
  'size': {'height': 12.3939, 'width': 15.625},
  'text': "I once went to view a house here but it didn't have the floor. crap.",
  'timestamp': 'Wed, 15 Dec 2021 11:36:51 GMT',
  'userID': '6286616941'},
 {'image': 'rejection_map.jpg',
  'position': {'x': 77.0, 'y': 63.7521},
  'size': {'height': 8.65874, 'width': 10.25},
  'text': 'other housing rejection situations here.\n',
  'timestamp': 'Wed, 15 Dec 2021 11:37:25 GMT',
  'userID': '6286616941'},
 {'image': 'rejection_map.jpg',
  'position': {'x': 75.285, 'y': 29.2254},
  'size': {'height': 19.0141, 'width': 17.513},
  'text': '어딘지 잘은 모르겠지만, Kralingen 쪽이었던 것 같아. bsn 거주등록을 위해 학교에 갔는데, 시청에서 나온 사람들이 나의 룸메이트 ID card가 필요하다며 거절했지. 나의 아침을 날렸어. 나의 룸메가 나에게 ID card 사진을 보내줬지만, 그들은 서명이 같지 않다면서 다시 거절했지. ',
  'timestamp': 'Wed, 15 Dec 2021 11:39:21 GMT',
  'userID': '8633793842'},
 {'image': 'rejection_map.jpg',
  'position': {'x': 73.703, 'y': 49.514},
  'size': {'height': 5.22479, 'width': 5.09839},
  'text': "i got rejected from a skateboard here. it's normal though because it's always trying to reject you and you love it anyway",
  'timestamp': 'Wed, 15 Dec 2021 11:44:35 GMT',
  'userID': '8918562766'}]