GenerateEmbedding
class GenerateEmbedding
Traits
Constants
| MAX_TILES_THRESHOLD |
Maximum number of Zoomify tiles to load before falling back to full image. If a bbox requires more tiles than this, loading the full image is faster due to reduced request overhead. |
| ZOOMIFY_TILE_SIZE |
Zoomify tile size in pixels (standard for Zoomify format). |
Properties
| Image | $image | The image to generate an embedding of. |
|
| User | $user | The user who initiated the job. |
|
| array|null | $bbox | The bbox of the image to generate an embedding for (x, y, width, height). |
|
| protected bool | $deleteWhenMissingModels | Ignore this job if the image or user does not exist any more. |
|
| $tries | The number of times the job may be attempted. |
Methods
Handle the job.
Get the filename for the embedding.
Get the byte string of the resized image for the Python worker.
Load the full image, crop to bbox if set, and resize for the Python worker.
Send the scaled-down PNG image to the Python worker and return the embedding npy file as binary blob.
Calculate the maximum Zoomify zoom level (full resolution) for this image.
Prepare all information needed for loading Zoomify tiles.
Load and stitch Zoomify tiles for the bbox and resize for the Python worker.
Decrement the pending jobs counter for the user.
Details
at line 88
static string
getPendingJobsCacheKey(User $user)
Get the cache key for tracking pending jobs for a user.
at line 98
void
handle()
Handle the job.
at line 120
string
getFilename()
Get the filename for the embedding.
at line 132
protected string
generateEmbedding(Image $image)
Generate the embedding.
at line 145
protected string
getImageBufferForPyworker(string $path)
Get the byte string of the resized image for the Python worker.
at line 179
protected Image
getVipsImageFromFullImage(string $path)
Load the full image, crop to bbox if set, and resize for the Python worker.
at line 200
protected string
sendPyworkerRequest(string $buffer)
Send the scaled-down PNG image to the Python worker and return the embedding npy file as binary blob.
at line 223
protected int
getMaxZoomLevel()
Calculate the maximum Zoomify zoom level (full resolution) for this image.
The max level is determined by how many zoom levels are needed so that 256 × 2^maxLevel >= max(image_width, image_height).
See prepareTileLoadingInfo() fore more explanation.
at line 257
protected array
prepareTileLoadingInfo(array $bbox, int $modelInputSize)
Prepare all information needed for loading Zoomify tiles.
This calculates:
- Best zoom level to use (lowest resolution where bbox >= modelInputSize)
- Scale factor for that zoom level
- Bbox coordinates at that zoom level
- Which tiles (rows/cols) are needed
- Total tile count
- Number of tiles before this zoom level (for TileGroup index calculation)
- Number of tile columns at this zoom level (for TileGroup index calculation)
Zoomify structure:
- Level 0: Lowest resolution (single 256x256 tile)
- Level N: Higher resolution (dimension = 256 × 2^N)
- Max level: Full resolution
Zoom level selection math:
- At max zoom level (full res): bbox has dimensions from request
- At lower levels: bbox_dimension_at_level = bbox_dimension × 2^(level - maxLevel)
- We need: max(bbox_width, bbox_height) × 2^(level - maxLevel) >= modelInputSize
- Solving: level >= maxLevel + log2(modelInputSize / max(bbox_width, bbox_height))
at line 318
protected Image
getVipsImageFromZoomifyTiles(array $tileInfo)
Load and stitch Zoomify tiles for the bbox and resize for the Python worker.
at line 356
protected void
decrementPendingJobsCounter()
Decrement the pending jobs counter for the user.