abstract class Annotation extends Model implements Annotation

An image annotation is a region of an image that can be labeled by the users.

It consists of one or many points and has a specific shape.

Traits

HasFactory

Properties

protected list<string> $hidden

The attributes excluded from the model's JSON form.

protected array<string, string> $casts

The attributes that should be casted to native types.

$labelBOTLabels

The additional labels suggested by the LabelBOT.

int $id
array $points
string $created_at
int $shape_id

Methods

validatePoints(array $points)

Validates a points array for the shape of this annotation.

validateCoordinatesAreNumeric(array $points)

Valies that all coordinates are either int or float

validateNumberOfCoordinates(array $points)

Validates that the number of coordinates matches the required number for the given shape

validateNumberOfPoints(array $points)

Validates that the number of points (sequential coordinate pairs) matches the expected number of points for the given shape

validateShape(array $points)

Validates some edgecases where the given points don't create a valid shape

setPointsAttribute(array $points)

Round the floats of the points array to 2 decimals before saving.

int
countDistinctPoints(array $points)

Counts number of distinct points

static int
estimatedCount()

Get an estimated count of all annotations from pg_class statistics.

Builder
scopeVisibleFor(Builder $query, User $user)

Scope a query to only include annotations that are visible for a certain user.

Builder
scopeWithLabel(Builder $query, Label $label)

Scope a query to only include annotations that have a certain label attached.

Builder
scopeAllowedBySession(Builder $query, AnnotationSession $session, User $user)

Scope a query to only include annotations allowed by the session for the user.

Annotation>
file()

The file, this annotation belongs to.

AnnotationLabel, $this>
labels()

The labels, this annotation got assigned by the users.

int
getFileIdAttribute()

Get the file_id attribute

Shape, $this>
shape()

The shape of this annotation.

array
getPoints()

Get the points array of the annotation.

getShape()

Get the shape of an annotation.

getFile()

Get the image/video, the annotation belongs to.

int
getId()

Get the ID of the annotation.

array
getLabelBOTLabelsAttribute()

Get the LabelBOT suggested labels.

Details

in HasPointsAttribute at line 19
validatePoints(array $points)

Validates a points array for the shape of this annotation.

Parameters

array $points

Points array like [x1, y1, x2, y2, x3, y3, ...]

Exceptions

InvalidShapeException

in HasPointsAttribute at line 31
protected validateCoordinatesAreNumeric(array $points)

Valies that all coordinates are either int or float

Parameters

array $points

Exceptions

InvalidCoordinateTypeException

in HasPointsAttribute at line 44
protected validateNumberOfCoordinates(array $points)

Validates that the number of coordinates matches the required number for the given shape

Parameters

array $points

Exceptions

InvalidNumberOfCoordinatesException

in HasPointsAttribute at line 69
protected validateNumberOfPoints(array $points)

Validates that the number of points (sequential coordinate pairs) matches the expected number of points for the given shape

Parameters

array $points

Exceptions

InvalidNumberOfPointsException

in HasPointsAttribute at line 102
protected validateShape(array $points)

Validates some edgecases where the given points don't create a valid shape

Parameters

array $points

Exceptions

InvalidShapeException

in HasPointsAttribute at line 143
setPointsAttribute(array $points)

Round the floats of the points array to 2 decimals before saving.

This is a more than sufficient precision for annotation point coordinates and saves memory in the DB as well as when processing the annotations in PHP.

Parameters

array $points

in HasPointsAttribute at line 154
protected int countDistinctPoints(array $points)

Counts number of distinct points

Parameters

array $points

Return Value

int

number of distinct points *

at line 54
static int estimatedCount()

Get an estimated count of all annotations from pg_class statistics.

This is much faster than a full table scan of a large table.

See: https://wiki.postgresql.org/wiki/Count_estimate

Return Value

int

at line 69
Builder scopeVisibleFor(Builder $query, User $user)

Scope a query to only include annotations that are visible for a certain user.

Parameters

Builder $query
User $user

The user to whom the restrictions should apply ('own' user)

Return Value

Builder

at line 102
Builder scopeWithLabel(Builder $query, Label $label)

Scope a query to only include annotations that have a certain label attached.

Parameters

Builder $query
Label $label

Return Value

Builder

at line 122
Builder scopeAllowedBySession(Builder $query, AnnotationSession $session, User $user)

Scope a query to only include annotations allowed by the session for the user.

Parameters

Builder $query
AnnotationSession $session
User $user

The user to whom the restrictions should apply ('own' user)

Return Value

Builder

at line 182
abstract Annotation> file()

The file, this annotation belongs to.

Return Value

Annotation>

at line 189
abstract AnnotationLabel, $this> labels()

The labels, this annotation got assigned by the users.

Return Value

AnnotationLabel, $this>

at line 196
abstract int getFileIdAttribute()

Get the file_id attribute

Return Value

int

at line 203
Shape, $this> shape()

The shape of this annotation.

Return Value

Shape, $this>

at line 211
array getPoints()

Get the points array of the annotation.

Return Value

array

at line 219
Shape getShape()

Get the shape of an annotation.

Return Value

Shape

at line 227
VolumeFile getFile()

Get the image/video, the annotation belongs to.

Return Value

VolumeFile

at line 235
int getId()

Get the ID of the annotation.

Return Value

int

at line 245
array getLabelBOTLabelsAttribute()

Get the LabelBOT suggested labels.

Return Value

array