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). |
|
| $tries | The number of times the job may be attempted. |
Methods
Handle the job.
Get the filename for the embedding.
Attempt to load the bbox area from Zoomify tiles.
Load the full image, crop to bbox if set, and resize for the Python worker.
Get the byte string of the resized image 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 83
static string
getPendingJobsCacheKey(User $user)
Get the cache key for tracking pending jobs for a user.
at line 93
void
handle()
Handle the job.
at line 115
string
getFilename()
Get the filename for the embedding.
at line 127
protected string
generateEmbedding(Image $image)
Generate the embedding.
at line 150
protected Image|null
tryGetVipsImageFromTiles()
Attempt to load the bbox area from Zoomify tiles.
at line 176
protected Image
getVipsImageFromFullImage(string $path)
Load the full image, crop to bbox if set, and resize for the Python worker.
at line 196
protected string
bufferFromVipsImage(Image $image)
Get the byte string of the resized image for the Python worker.
at line 217
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 240
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 274
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 335
protected Image
getVipsImageFromZoomifyTiles(array $tileInfo)
Load and stitch Zoomify tiles for the bbox and resize for the Python worker.
at line 373
protected void
decrementPendingJobsCounter()
Decrement the pending jobs counter for the user.