Skip to content

Image Operations ​

This section covers all read operations available for images in the Rosepetal API.

Overview ​

Images are the core data elements in the Rosepetal system. They contain visual data along with metadata such as annotations, tags, and classification information. The API provides endpoints to retrieve, analyze, and download images.

Image Structure ​

Each image object contains the following key properties:

FieldTypeDescription
uristringGoogle Cloud Storage URI
namestringOriginal filename
datasetreferenceAssociated dataset reference
tagreferencePrimary classification tag
tagsarrayAdditional annotation tags
tagsContainedarrayReferences to all contained tags
setstringTraining set assignment
imageDatabufferThumbnail image data (WebP, 300px)
datenumberUpload timestamp
monitorreferenceSource monitor reference

Endpoints ​

Delete Image ​

Remove an image from storage and database.

http
GET /image/delete/image/{encoded_uri}

Parameters:

ParameterTypeDescription
encoded_uristringImage URI with / replaced by --

Example Request:

http
GET /image/delete/image/upload--monitor-1--20240115.png

Response:

json
{
  "error": false,
  "status": "success"
}

Error Response:

json
{
  "error": true,
  "status": "Permission denied or file not found"
}

Object Detection ​

Analyze an image for objects using Google Cloud Vision API.

http
GET /image/detect/image/{encoded_uri}

Parameters:

ParameterTypeDescription
encoded_uristringImage URI with / replaced by --

Example Request:

http
GET /image/detect/image/upload--monitor-1--20240115.png

Response:

json
{
  "result": [
    {
      "bbox": [0.1, 0.2, 0.3, 0.4],
      "class": "Person",
      "score": 0.95
    },
    {
      "bbox": [0.5, 0.6, 0.2, 0.3],
      "class": "Vehicle",
      "score": 0.87
    }
  ]
}

Bounding Box Format:

  • bbox[0]: X coordinate of top-left corner (normalized 0-1)
  • bbox[1]: Y coordinate of top-left corner (normalized 0-1)
  • bbox[2]: Width (normalized 0-1)
  • bbox[3]: Height (normalized 0-1)

Get Image as Base64 ​

Retrieve an image as a base64-encoded data URI.

http
GET /image/getb64/image/{encoded_uri}

Parameters:

ParameterTypeDescription
encoded_uristringImage URI with / replaced by --

Example Request:

http
GET /image/getb64/image/upload--monitor-1--20240115.png

Response:

json
{
  "result": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
}

Error Response:

json
{
  "error": true,
  "uri": "upload/monitor-1/20240115.png",
  "status": "File not found"
}

Image Sets ​

Images are organized into training sets for machine learning:

SetDescriptionTypical Usage
TRAINTraining data60-80% of dataset
TESTTesting data10-20% of dataset
VALIDATIONValidation data10-20% of dataset
PREDETERMINEDDefault assignmentBefore set splitting
REVIEWRequires manual reviewQuality control

Annotation Structure ​

Tags Array ​

Each image can have multiple annotations in the tags array:

json
{
  "tags": [
    {
      "type": "rect",
      "tag": "dataset/123/tag/defect",
      "x": 0.1,
      "y": 0.2,
      "w": 0.3,
      "h": 0.4,
      "labeled": "manual"
    }
  ]
}

Tag Properties:

FieldTypeDescription
typestringAnnotation type (rect, mask, point)
tagreferenceTag classification reference
x, ynumberTop-left coordinates (normalized 0-1)
w, hnumberWidth and height (normalized 0-1)
labeledstringSource of annotation (manual, inference)

Masks (Segmentation) ​

For segmentation datasets, images may contain mask information:

json
{
  "masks": [
    {
      "tag": "dataset/123/tag/defect-type",
      "uri": "gs://bucket/masks/mask_123.png"
    }
  ]
}

Image Metadata ​

Upload Information ​

FieldTypeDescription
datenumberUnix timestamp of upload
monitorreferenceSource monitor/camera
sessionstringRecording session ID
createdDatetimestampFirestore creation time
updatedAttimestampLast modification time

Processing Information ​

FieldTypeDescription
imageDatabufferThumbnail preview (WebP)
originalFormatstringOriginal file format
widthnumberImage width in pixels
heightnumberImage height in pixels

URI Encoding ​

When working with image URIs in API calls, replace forward slashes with double dashes:

Original URI:

gs://project/upload/monitor/image.png

Encoded for API:

upload--monitor--image.png

Error Handling ​

Common Error Responses ​

Image Not Found ​

json
{
  "error": true,
  "status": "File not found"
}

Invalid URI Format ​

json
{
  "error": "No defined image gsuri"
}

Processing Error ​

json
{
  "error": true,
  "status": "Permission denied"
}

Detection API Error ​

json
{
  "error": "Vision API quota exceeded"
}

Query Examples ​

Basic Image Retrieval ​

javascript
// Get image as base64
const response = await fetch('/image/getb64/image/upload--camera-1--image.png');
const data = await response.json();
console.log(data.result); // data:image/png;base64,...

Object Detection Analysis ​

javascript
// Detect objects in image
const response = await fetch('/image/detect/image/upload--camera-1--image.png');
const data = await response.json();
data.result.forEach(obj => {
  console.log(`${obj.class}: ${obj.score}`);
  console.log(`Bbox: ${obj.bbox}`);
});

Safe Image Deletion ​

javascript
// Delete image with error handling
const response = await fetch('/image/delete/image/upload--old-image.png');
const data = await response.json();
if (data.error) {
  console.error('Delete failed:', data.status);
} else {
  console.log('Image deleted successfully');
}