biigle / annotations

:m: BIIGLE module to create, edit and explore image annotations
0 stars 1 forks source link

Show grid for regular sampling mode #118

Closed mzur closed 5 years ago

mzur commented 5 years ago

Tabitha from NOC requested the regular grid annotation mode (as mentioned here and here). During the implementation of the regular/random sampling modes, we actively decided against this as we though it was a bad practice for ground coverage estimation. Instead, users should use random sampling for this.

Renew this discussion so we can get a (documented) final decision if we want to have a grid like that or not.

mzur commented 5 years ago

People from Ifremer asked for this, too. I helped them to write a short Python script that uses the API to create a grid of rectangle annotations for each image (see the outline of the script below). They were satisfied with that. Maybe we can create a list of "BIIGLE recipies" somewhere, where scripts like these can be found by users.

import requests
from requests.auth import HTTPBasicAuth

# Enter your user email address here.
email = ''
# Enter your API token here.
token = ''
# ID of the volume to process.
volume_id = 678
# ID of the label to attach to new annotations.
label_id = 1558

base_url = 'https://biigle.de'
auth = HTTPBasicAuth(email, token)
headers = {'Accept': 'application/json'}

def api_url(uri):
   return '{}/api/v1/{}/'.format(base_url, uri)

# Get the available annotation shapes.
# https://biigle.de/doc/api/index.html#api-Shapes-IndexShapes
r = requests.get(api_url('shapes'), auth=auth)
shapes = {s['name']: s['id'] for s in r.json()}

# Get the list of image IDs that belong to the volume.
# https://biigle.de/doc/api/index.html#api-Volumes-IndexVolumeImages
r = requests.get(api_url('volumes/{}/images'.format(volume_id)), auth=auth)
image_ids = r.json()

# Get detailed information on an image, including width and height in pixels.
# https://biigle.de/doc/api/index.html#api-Images-ShowImages
r = requests.get(api_url('images/{}'.format(image_ids[0])), auth=auth)
image_info = r.json()
width, height = image_info['attrs']['width'], image_info['attrs']['height']

rectangle_width = width // 3
rectangle_height = height // 3
post_data = {
   'shape_id': shapes['Rectangle'],
   'label_id': label_id,
   'confidence': 1,
   'points': [
      0, 0,
      rectangle_width, 0,
      rectangle_width, rectangle_height,
      0, rectangle_height
   ],
}

# Create a new rectangle annotation on the first image of the volume.
# https://biigle.de/doc/api/index.html#api-Annotations-StoreImageAnnotations
r = requests.post(api_url('images/{}/annotations'.format(image_ids[0])),
      json=post_data, auth=auth, headers=headers)

if not r.ok: print(r.json())
dlangenk commented 5 years ago

I also have number of scripts, for reformatting output, importing data from amazon S3, .... Would be great to provide the scripts to users. However, what about the maintenance of these scripts?

mzur commented 5 years ago

We could publish them in a public GitHub repo and make it plain that the scripts are "community maintained". If anybody wants/needs to update them, they can send a pull request.

mzur commented 5 years ago

Create a new "community-scripts" repository. Make it plain that the scripts should be maintained by BIIGLE users and how they can contribute. In this repo, each script should have its own directory, containing the script and a readme. Start with a polished version of the grid annotations script.

mzur commented 5 years ago

Done.