restore bbox from VLM scale
Undo the grid math a vision LLM did before it answered
- bbox
- bbox
- x
- y
- width
- height
This is a specific, real fix for a real problem. Ask a vision-language model to locate something in an image and return its bounding box, and you often don't get coordinates in your original image's pixel space - you get coordinates relative to how the model actually saw the image internally, because many VLMs don't process an image at its native resolution. They tile it into a grid of fixed-size patches first, and the coordinates in the model's answer are in that tiled, resized space, not yours. This node reverses that: give it the box the VLM returned plus your original image's dimensions and the model's tiling parameters, and it maps the box back to real pixel coordinates.
The defaults aren't arbitrary
gridSize defaults to 448, minGridNum defaults to 1, and maxGridNum defaults to 12. That's not a round number picked at random - 448×448 tiles with a minimum of 1 and a maximum of 12 tiles is the exact dynamic-resolution tiling scheme InternVL's vision encoders use (a model family that also shows up directly in this pack's own KY_OpenAICaptionImage/KY_OpenAICaptionImages model dropdowns, as OpenGVLab/InternVL3-8B). That match is a strong signal this node was built specifically against InternVL-style output, even though it's generic enough to work with any VLM that tiles images the same way.
Inputs and outputs
Required: bbox (BBOX, default [0,0,0,0] - the box as the VLM returned it), originWidth/originHeight (INT, default 1920×1080 - your actual source image's real dimensions, not the model's internal resized view), gridSize (INT, default 448), minGridNum/maxGridNum (INT, default 1/12).
Outputs: a corrected bbox (BBOX), plus x, y, width, height unpacked as individual INTs - so you get both the packaged object and the raw numbers in one call.
Where this fits in a real pipeline
The natural chain: caption or query an image with this pack's KY_OpenAICaptionImage (or any vision LLM pointed at an InternVL-family model) asking it to locate an object and return a bounding box, parse that response into a raw BBOX (via KY_JSONToBBox if it comes back as JSON, or KY_Eval_Python for anything more custom), run it through this node to correct for the model's internal scaling, then feed the corrected box into KY_ImageCropByBBox or KY_CreateMask to actually crop or mask the real image. Skip this step and a box that looked syntactically valid will point at the wrong region - sometimes wildly so, since a 448-pixel-tile coordinate space and a 1920×1080 real image are very different scales.
Installing it
ComfyUI Manager: search ComfyUI-KYNode, install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/yorkane/ComfyUI-KYNode
Restart ComfyUI. Pure coordinate math - no models, no external calls.
Common issues
originWidth/originHeight have to match your actual source image exactly, not the model's internal resized view - get these wrong and every downstream number is wrong too, since the whole node exists to translate between those two spaces.
gridSize/minGridNum/maxGridNum aren't universal constants - they're specific to whichever VLM's tiling scheme actually produced the box. The 448/1/12 defaults match InternVL's scheme specifically; if you're using a different vision-language model with a different internal tiling convention (some use 336-pixel tiles, matching CLIP's classic patch size, or a different max-tile count entirely), you need to change these to match that model, and this node has no way to detect the mismatch automatically - it'll produce a confidently wrong answer rather than an error.
If your restored box still looks off after matching the tiling parameters, double-check the raw bbox you fed in is actually in the coordinate convention this node expects before the correction - a box that was already garbled coming out of KY_JSONToBBox (wrong key, wrong [x,y,w,h] vs [x1,y1,x2,y2] convention) will just come out garbled here too, since this node only corrects for scale, not for a fundamentally wrong parse upstream.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| bbox | BBOX | 0,0,0,0 | — |
| originWidth | INT | 1920 | — |
| originHeight | INT | 1080 | — |
| gridSize | INT | 448 | — |
| minGridNum | INT | 1 | — |
| maxGridNum | INT | 12 | — |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| bbox | BBOX | — |
| x | INT | — |
| y | INT | — |
| width | INT | — |
| height | INT | — |