class ProcessObjectDetectedImage extends ProcessAnnotatedImage

Traits

SerializesModels
InteractsWithQueue
Queueable
Dispatchable

Constants

CROP_MAX_EDGE_PX

Python PIL accepts images with at most 178956970 pixels. We set this arbitrary maximum dimension so the limit is not reached and feature vector computation does not consume a ridiculous amount of memory.

Properties

int $tries

The number of times the job may be attempted.

from  ProcessAnnotatedFile
protected bool $deleteWhenMissingModels

Ignore this job if the annotation does not exist any more.

from  ProcessAnnotatedFile

Methods

array
getAnnotationBoundingBox(array $points, Shape $shape, int $pointPadding = 112, int $boxPadding = 0, int $minSize = 32)

Get the bounding box of an annotation

array
ensureBoxAspectRatio(array $box, int $aspectWidth, int $aspectHeight)

Modify a bounding box so it adheres to the aspect ratio given by width and height.

makeBoxContained(array $box, int|null $maxWidth, int|null $maxHeight)

Adjust the position and size of the box so it is contained in a box with the given dimensions.

array
getPointBoundingBox(array $points, int $padding)

Get the bounding box of a point annotation.

array
getCircleBoundingBox(array $points)

Get the bounding box of a circle annotation.

array
getPolygonBoundingBox(array $points)

Get the bounding box of an annotation that is no point, circle or whole frame.

array
makeBoxIntegers(array $box)

Round and cast box values to int.

array
generateInput(array $files, array $paths, Collection $annotations)

Generate the input for the python script.

array
generateFileInput(VolumeFile $file, Collection $annotations)

No description

python(string $inputPath, string $outputPath)

Run the Python command.

readOutputCsv(string $path)

Generator to read the output CSV row by row.

__construct(VolumeFile $file, MaiaJob $maiaJob, array $only = [], bool $skipFeatureVectors = false, string|null $targetDisk = null)

Create a new job instance.

static string
getTargetPath(Annotation $annotation, string|null $format = null)

Assemble the target path for an annotation patch.

void
handle()

Execute the job.

handleFile(VolumeFile $file, string $path)

Handle a single file.

bool
shouldGiveUpAfterException(Exception $e)

Determine if the job should give up trying because the error will likely not be fixed the next time.

bool
shouldRetryAfterException(Exception $e)

Determine if this job should retry instead of fail after an exception

void
createSvgs()

Generate and upload annotation SVGs for the file.

void
createSvg(Annotation $annotation)

Generate and upload an SVG for the annotation.

string
getAnnotationPatch(Image $image, array $points, Shape $shape)

Get the annotation patch as buffer.

void
generateFeatureVectors(Collection $annotations, array|string $filePath)

Generates feature vectors for the specified annotations belonging to the file of this job. This method either creates new feature vector models or updates the existing ones for the annotations.

void
updateOrCreateFeatureVectors(Collection $annotations, Generator $output)

Create the feature vectors based on the Python script output.

Builder
getAnnotationQuery(VolumeFile $file)

Get the query builder for the annotations (maybe filtered by IDs).

SVGNodeContainer
getSVGAnnotation(array $points, Shape $shape)

Draw annotation as SVG

SVGRect
getRectangleSvgAnnotation(array $tuples)

Get an SVG rectangle element.

SVGEllipse
getEllipseSvgAnnotation(array $tuples)

Get an SVG ellipse element.

float
computeRotationAngle(array $v, array $u)

Computes angle between two vectors

array
getOrientedCoordinates(array $tuples, Shape $shape)

Determines position of coordinate

void
redispatch()

Dispatch a copy of this job with a delay.

getVipsImage(string $path, array $options = [])

Get the vips image instance.

Details

array getAnnotationBoundingBox(array $points, Shape $shape, int $pointPadding = 112, int $boxPadding = 0, int $minSize = 32)

Get the bounding box of an annotation

Parameters

array $points
Shape $shape
int $pointPadding

The default is half the patch size of 224 that is expected by DINO.

int $boxPadding
int $minSize

Each side of the box should have at least this number of pixels. Must be divisible by 2.

Return Value

array

array ensureBoxAspectRatio(array $box, int $aspectWidth, int $aspectHeight)

Modify a bounding box so it adheres to the aspect ratio given by width and height.

Parameters

array $box
int $aspectWidth
int $aspectHeight

Return Value

array

makeBoxContained(array $box, int|null $maxWidth, int|null $maxHeight)

Adjust the position and size of the box so it is contained in a box with the given dimensions.

Parameters

array $box
int|null $maxWidth
int|null $maxHeight

protected array getPointBoundingBox(array $points, int $padding)

Get the bounding box of a point annotation.

Parameters

array $points
int $padding

Return Value

array

protected array getCircleBoundingBox(array $points)

Get the bounding box of a circle annotation.

Parameters

array $points

Return Value

array

protected array getPolygonBoundingBox(array $points)

Get the bounding box of an annotation that is no point, circle or whole frame.

Parameters

array $points

Return Value

array

protected array makeBoxIntegers(array $box)

Round and cast box values to int.

Parameters

array $box

Return Value

array

protected array generateInput(array $files, array $paths, Collection $annotations)

Generate the input for the python script.

Parameters

array $files

VolumeFile instances of the files to which the annotations belong.

array $paths

Paths of locally cached files.

Collection $annotations

Annotations grouped by their file ID (e.g. image_id).

Return Value

array

protected array generateFileInput(VolumeFile $file, Collection $annotations)

No description

Parameters

VolumeFile $file
Collection $annotations

Return Value

array

protected python(string $inputPath, string $outputPath)

Run the Python command.

Parameters

string $inputPath
string $outputPath

protected Generator readOutputCsv(string $path)

Generator to read the output CSV row by row.

Parameters

string $path

Return Value

Generator

at line 15
__construct(VolumeFile $file, MaiaJob $maiaJob, array $only = [], bool $skipFeatureVectors = false, string|null $targetDisk = null)

Create a new job instance.

Parameters

VolumeFile $file

The file to process.

MaiaJob $maiaJob
array $only

If filled with annotation IDs belonging to the file, only the annotations will be processed.

bool $skipFeatureVectors

Disable generation of annotation feature vectors.

string|null $targetDisk

The storage disk to store annotation patches to ( default is the configured largo.patch_storage_disk).

static string getTargetPath(Annotation $annotation, string|null $format = null)

Assemble the target path for an annotation patch.

Parameters

Annotation $annotation
string|null $format

Return Value

string

in ProcessAnnotatedFile at line 103
void handle()

Execute the job.

Return Value

void

handleFile(VolumeFile $file, string $path)

Handle a single file.

Parameters

VolumeFile $file
string $path

Path to the cached file.

in ProcessAnnotatedFile at line 148
protected bool shouldGiveUpAfterException(Exception $e)

Determine if the job should give up trying because the error will likely not be fixed the next time.

Parameters

Exception $e

Return Value

bool

in ProcessAnnotatedFile at line 179
protected bool shouldRetryAfterException(Exception $e)

Determine if this job should retry instead of fail after an exception

Parameters

Exception $e

Return Value

bool

in ProcessAnnotatedFile at line 199
void createSvgs()

Generate and upload annotation SVGs for the file.

Return Value

void

in ProcessAnnotatedFile at line 210
protected void createSvg(Annotation $annotation)

Generate and upload an SVG for the annotation.

Parameters

Annotation $annotation

Return Value

void

in ProcessAnnotatedFile at line 250
protected string getAnnotationPatch(Image $image, array $points, Shape $shape)

Get the annotation patch as buffer.

Parameters

Image $image
array $points
Shape $shape

Return Value

string

protected void generateFeatureVectors(Collection $annotations, array|string $filePath)

Generates feature vectors for the specified annotations belonging to the file of this job. This method either creates new feature vector models or updates the existing ones for the annotations.

Parameters

Collection $annotations
array|string $filePath

If a string, a file path to the local image to use for feature vector generation. If an array, a map of annotation IDs to a local image file path.

Return Value

void

at line 43
protected void updateOrCreateFeatureVectors(Collection $annotations, Generator $output)

Create the feature vectors based on the Python script output.

Parameters

Collection $annotations
Generator $output

Return Value

void

at line 33
protected Builder getAnnotationQuery(VolumeFile $file)

Get the query builder for the annotations (maybe filtered by IDs).

Parameters

VolumeFile $file

Return Value

Builder

in ProcessAnnotatedFile at line 358
protected SVGNodeContainer getSVGAnnotation(array $points, Shape $shape)

Draw annotation as SVG

Parameters

array $points

one dimensional array filled with coordinates of annotation

Shape $shape

Return Value

SVGNodeContainer

annotation as SVG

*

in ProcessAnnotatedFile at line 412
protected SVGRect getRectangleSvgAnnotation(array $tuples)

Get an SVG rectangle element.

Parameters

array $tuples

Return Value

SVGRect

in ProcessAnnotatedFile at line 433
protected SVGEllipse getEllipseSvgAnnotation(array $tuples)

Get an SVG ellipse element.

Parameters

array $tuples

Return Value

SVGEllipse

in ProcessAnnotatedFile at line 461
protected float computeRotationAngle(array $v, array $u)

Computes angle between two vectors

Parameters

array $v

first vector

array $u

second vector

Return Value

float

rotation angle in degree *

in ProcessAnnotatedFile at line 492
protected array getOrientedCoordinates(array $tuples, Shape $shape)

Determines position of coordinate

Parameters

array $tuples

coordinates array

Shape $shape

Return Value

array

with coordinates assigned to their position on the plane

*

at line 61
protected void redispatch()

Dispatch a copy of this job with a delay.

Return Value

void

protected getVipsImage(string $path, array $options = [])

Get the vips image instance.

Parameters

string $path
array $options