All lessons in Vision-Language Models: Build, Evaluate, and Adapt
Preserve Pixels, Coordinates, and Meaning
Trace image decoding, orientation, resizing, crops, and evidence coordinates.
40 minutes · Free lesson
What you will learn
- Trace a source image through orientation, resizing, padding, and cropping without losing coordinate meaning.
- Calculate a forward and inverse region transform and identify evidence lost by preprocessing.
- Specify the image metadata needed to reproduce a model answer.
A warehouse reviewer asks whether the red inspection mark is inside a damaged region. Your model returns a plausible answer and a rectangle. The reviewer opens the original photograph, but the rectangle points somewhere else. The model may have localized correctly on a resized crop while your application interpreted its numbers as original-image pixels. You have an interface failure before you have a model-quality question.
The Meridian Visual Desk needs an explicit image contract: the source bytes, their decoded orientation, the transformations the model receives, and the coordinate system attached to every reported region. This lesson uses original synthetic geometry. It does not assume a particular checkpoint can predict accurate rectangles; you must separately test that ability.
Define the image that actually enters the model
A file is an encoding, not a tensor. JPEG and PNG bytes must be decoded to pixels. A decoder may expose an orientation tag separately from the pixel array. An RGB image has three color channels; a grayscale image has one; an RGBA image has an extra transparency channel. A model processor expects a particular representation and may normalize pixel values before inference.
Record the source hash before decoding. Then apply a documented orientation policy, convert to a consistent color representation, and record the resulting width and height. If you apply orientation twice, a correctly stored portrait image can be rotated incorrectly. If you drop transparency without choosing a background, text intended for a white page can become difficult to read. Preserve the original bytes and treat a normalized image as a derived artifact.
For this workbook, the decoded source uses a top-left origin, x increasing rightward, y increasing downward, and continuous pixel-edge coordinates. A rectangle is left, top, right, bottom with nonzero width and height. The point at the right edge is a boundary, not another included pixel center. Store the image dimensions beside the rectangle rather than guessing them from a model name.
Distinguish resize, letterbox, and crop
Direct resizing can change aspect ratio. Converting a 1,200 × 800 image into a 600 × 600 image applies horizontal scale 0.5 and vertical scale 0.75. Circles become ellipses. Text and chart geometry can change enough to affect reading.
Letterboxing preserves aspect ratio and pads the unused space. For a 600 × 600 target, the same source uses scale 0.5, becomes 600 × 400, and receives 100 pixels of padding above and below. A region transform must include that offset. Padding is not observed scene content, even when it resembles a black border in the source.
A crop discards content. If you crop the right half of a page, a question about the left-column total becomes unanswerable from the crop. Upscaling the surviving crop changes its sampling grid; it does not reconstruct the omitted column or recover genuine detail from unreadable source text. Before increasing resolution, inspect what information is present in the source.
| Operation | Position rule | Information consequence |
|---|---|---|
| Direct resize | Multiply x and y by their separate scales | Changes aspect ratio when scales differ |
| Letterbox | Apply common scale, then add padding offsets | Preserves content but changes the usable fraction of the canvas |
| Crop | Subtract crop origin from retained points | Permanently excludes regions outside the crop |
| Crop then resize | Subtract crop origin, then scale | Requires the complete transform chain to invert |
The named checkpoint's processor is part of the model. Some processors generate several crops, a global view, or image-specific special tokens. A hand-written 224-pixel resize copied from another model is not a harmless convenience. Inspect the selected processor configuration and the actual prepared tensor shapes.
Carry a transform instead of guessing afterward
For an axis-aligned letterbox, write x_model = s × x_source + pad_x and y_model = s × y_source + pad_y. The inverse subtracts padding and divides by s. Apply the rule to both rectangle corners. For a crop, first subtract its origin in the source frame. Rotation requires a different transform; the simplified rule in this example does not cover it.
Worked example
Recover an inspection region from a letterboxed image
- The synthetic source is 1,200 pixels wide and 800 high. Its inspection region has source edges [240, 160, 720, 480].
- Fit the image inside 600 × 600 without stretching. The common scale is min(600 ÷ 1,200, 600 ÷ 800) = 0.5. The resized content is 600 × 400.
- Center the resized image. Horizontal padding is zero and vertical padding is (600 − 400) ÷ 2 = 100 on each side.
- Transform the source region. Its model-frame edges are [120, 180, 360, 340]: x values are halved, and y values are halved then increased by 100.
- Invert the model region. Subtract [0, 100, 0, 100], then divide all coordinates by 0.5. You recover [240, 160, 720, 480].
- If you only multiply the model region by two, you produce [240, 360, 720, 680]. The rectangle is shifted down 200 source pixels. It can remain inside the source bounds and still be wrong.
- Retain the source hash, dimensions, scale, padding, and convention with the region. Bounds validation alone would not detect the forgotten offset.
A normalized coordinate is dimensionless. If the model defines x in [0, 1], multiply by the width of its declared frame, not automatically by the source width. If it uses [0, 1,000], divide by 1,000 first. Different models and datasets can use different conventions; never infer the convention from numbers that happen to fit inside an image.
Check fidelity as well as arithmetic
A round-trip transform test verifies coordinate arithmetic. It cannot verify that the model saw a readable part number or selected the correct object. Keep software correctness and visual sufficiency as separate checks.
Inspect a full view and the actual resized view. Ask whether the smallest relevant text, mark, or boundary survives. A 12-pixel-tall character reduced by a factor of four is about three pixels high. That is a warning to test a crop or another acquisition procedure; it is not a universal three-pixel recognition threshold. Font, contrast, blur, and the task all matter.
For a document, keep document ID and page number with the image. Page 2 of one report is different from page 2 of another. For a crop, keep its parent image and crop edges. For a video frame, also keep the source timeline timestamp. File modification times are not video timestamps.
Write the image contract you will actually check
Store source SHA-256, decoded dimensions, normalized color mode, orientation policy, crop edges, resize method, target dimensions, padding, processor identity, and model revision. This record is useful when two runs disagree. Identical source bytes with a different processor can produce a different model input; the source hash alone does not prove preprocessing parity.
Reject an invalid decode before calling the model. Bound compressed size, decoded pixel count, and the number of images. A small compressed file can expand into a large allocation. The operations chapter will develop these checks; here the key point is that file size and decoded dimensions measure different resources.
Exercise
A 1,000 × 500 image is letterboxed into 400 × 400. Calculate its scale and vertical padding, then transform source region [100, 50, 500, 250].
Check your answer
The scale is 0.4, resized dimensions are 400 × 200, and top/bottom padding is 100. The model-frame region is [40, 120, 200, 200]. Subtracting padding and dividing by 0.4 recovers the original region.
Exercise
You crop source edges [200, 100, 800, 500] and resize the resulting 600 × 400 crop to 300 × 200. The model reports [50, 25, 150, 100] in resized-crop pixels. Recover the source region and name one limitation this calculation cannot detect.
Check your answer
Undo the 0.5 scale to obtain crop-relative [100, 50, 300, 200]. Add the crop origin to recover source [300, 150, 500, 300]. This cannot establish that the model selected the correct object or that omitted source content was irrelevant to the question.
Exercise
Two runs use identical source hashes but produce different answers. One run corrects orientation before resizing; the other passes unrotated pixels and orientation metadata to a processor that ignores that metadata. What should the comparison record, and can this be called nondeterministic decoding?
Check your answer
Record the normalization policies, oriented dimensions, processor versions, and prepared-input dimensions or hashes. These runs receive different visual inputs. The disagreement cannot be attributed to stochastic decoding without first matching preprocessing and generation settings.
Sources and further reading
The ViT paper motivates a precise pixel-to-patch contract. Idefics2 investigates aspect ratio and image splitting. The versioned Transformers image-text guide describes processor-bound multimodal inputs. The geometry and inspection scenario above are original teaching examples.
Summary
Preserve the source, normalize deliberately, and record the full transform chain. Coordinate correctness, evidence sufficiency, and model accuracy are separate questions. Reproduce the actual processor input before explaining a changed answer.
Next action
Build the original visual fixtures and their source manifest. Verify hashes, dimensions, and source-group membership before running any model.