MOSS-Image 教學:以 JSON 座標控制圖像中的物件佈局
Generate images by describing object positions in JSON — MOSS-Image walkthrough
作者示範以 JSON 指定物件座標、大小和可選細節,控制 MOSS-Image 生成圖像時的佈局。作者測試 MOSS-Image-SFT 時,JSON 佈局約有 80% 的生成結果能正確放置物件,自然語言描述約為 40%。作者建議要精確放置物件時使用 SFT 而非 Base,並提供 ComfyUI 工作流 JSON 和提示詞合集的 GitHub 連結。
Most image generation models understand prompts like "a red ball on the left and a blue cube on the right." The problem is, they understand it maybe half the time. The ball ends up on the right, or both objects merge into one, or the cube turns red too.
Last week OpenMOSS released MOSS-Image, a 5B diffusion model under Apache 2.0 that addresses this with a different approach: describe object positions in JSON, and the model respects the coordinates.
I put together a ComfyUI workflow and a prompt collection. Here's a walkthrough of how the JSON layout system works.
What's different about MOSS-Image
Two features most open-source image models struggle with:
- JSON layout control — specify where objects go with coordinates instead of prompt engineering
- Chinese and English text rendering — readable text in both languages
The text rendering is solid, but the layout system is what changes how you work.
JSON layout, explained
Instead of a prompt like:
"a cup of coffee on the left side of a wooden table and an open book on the right side, warm lighting"
You describe the scene in JSON:
{
"canvas": {"width": 1024, "height": 1024},
"objects": [
{
"label": "a cup of coffee on a wooden table",
"position": [0.3, 0.5],
"size": [0.4, 0.35],
"detail": "ceramic white mug, steam rising"
},
{
"label": "an open book",
"position": [0.55, 0.45],
"size": [0.3, 0.35],
"detail": "old leather-bound book, yellowed pages"
}
],
"style": "warm morning light, shallow depth of field"
}
Each object gets a position (x and y, normalized to 0–1 where top-left is 0,0), a size, and an optional detail field. The model uses these coordinates to place objects before generating the image.
Accuracy
From my testing with MOSS-Image-SFT:
- JSON layout: roughly 80% of generations place objects correctly
- Natural language alone: roughly 40%
The gap widens with more objects. Three objects with natural language is a dice roll. Three objects with JSON stays consistent.
Running it in ComfyUI
MOSS-Image integrates natively into ComfyUI. Install the custom node through ComfyUI Manager (search "MOSS-Image"), download the model from HuggingFace, and you're good.
I made a drag-and-drop workflow JSON that includes text-to-image, JSON layout control, prompt enhancer, and resolution presets from 512×512 to 1024×1024:
→ mossimage-workflow on GitHub
Try it online
No ComfyUI? Generate directly at mossimage.run — free, 3 images per day, no sign-up.
I also put together a prompt collection with verified examples for JSON layout, text rendering, and general generation:
What I learned
Use SFT for layout, not Base. JSON layout accuracy drops noticeably with the Base model. SFT is the one you want for precise placement.
Shorter prompts work better. MOSS-Image has a built-in prompt enhancer. A 15-word prompt often beats a 60-word one because the enhancer adds detail without conflicting with your instructions.
Tell it what kind of text to render. Say "a neon sign" or "a poster" instead of just "an image with text." The context helps the model choose the right rendering style.
Fixed seed for reproducibility. Same as any diffusion model. Start with square aspect ratio and change one variable at a time.
The JSON layout is the part worth paying attention to. Being able to specify "put this here and that there" and have it actually work is something open-source image models haven't done well before.
來源:DEV Community · dev.to