0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Catch Reordered Photo References with a JavaScript Map Check

0
Posted at

Photo-reference prompts often contain positional tags such as @Image1 and @Image2. That makes the order of an image array part of the meaning of a request. A valid number of files is not enough: a reordered array can silently change which image each tag addresses.

I work with the MixVio team. This tutorial presents a small local JavaScript check for that planning problem. It does not call MixVio or a model provider, upload assets or expose an internal API schema. The method is reusable wherever a brief uses one-based reference tags.

Separate identity from position

Suppose the intended reference map is:

{
  "@Image1": "product-front",
  "@Image2": "desk-scene"
}

The labels are local aliases, not private asset IDs or signed URLs. The prompt says to keep the product from @Image1 on the desk from @Image2. If a person reorders the image pack, those tags still look plausible, but their meaning has changed.

Keep two things: the ordered labels you intend to upload and a separate expected map describing the roles. The check below resolves tags against the current order, then compares that result with the expected map.

Resolve tags and compare roles

Save this helper as reference-map-check.mjs. It reports missing references and mismatched aliases. It also rejects malformed planning objects and repeated aliases, since duplicate names make the review ambiguous.

// Educational local labels only. No upload, API request or model execution.
export function inspectReferenceMap(plan) {
  if (!plan || typeof plan !== 'object' || Array.isArray(plan)) {
    return { map: {}, errors: ['Provide a planning object'] };
  }
  const { images, prompt, expected } = plan;
  if (!Array.isArray(images) || !images.length ||
      images.some(key => typeof key !== 'string' || !key.trim()) ||
      typeof prompt !== 'string' || !prompt.trim() ||
      !expected || typeof expected !== 'object' || Array.isArray(expected)) {
    return { map: {}, errors: ['Provide ordered image labels, a prompt and an expected map'] };
  }
  const map = {};
  const errors = [];
  if (new Set(images).size !== images.length) errors.push('Use unique local image labels');
  for (const match of prompt.matchAll(/@Image(\d+)\b/g)) {
    const tag = match[0];
    const index = Number(match[1]);
    if (!Number.isSafeInteger(index) || index < 1 || index > images.length) {
      errors.push(`${tag} has no matching image`);
      continue;
    }
    map[tag] = images[index - 1];
  }
  for (const [tag, key] of Object.entries(expected)) {
    if (!Object.hasOwn(map, tag)) errors.push(`${tag} is absent or unresolved`);
    else if (map[tag] !== key) errors.push(`${tag} maps to ${map[tag]}, expected ${key}`);
  }
  return { map, errors: [...new Set(errors)] };
}

Reproduce the reorder failure

Put this example next to the helper, then run it with a current Node.js installation:

import assert from 'node:assert/strict';
import { inspectReferenceMap } from './reference-map-check.mjs';

const plan = {
  images: ['product-front', 'desk-scene'],
  prompt: 'Keep the product from @Image1 on the desk from @Image2.',
  expected: { '@Image1': 'product-front', '@Image2': 'desk-scene' }
};

assert.deepEqual(inspectReferenceMap(plan).errors, []);
const reversed = inspectReferenceMap({
  ...plan,
  images: [...plan.images].reverse()
});
console.log(reversed.errors);

The reversed pack reports:

@Image1 maps to desk-scene, expected product-front
@Image2 maps to product-front, expected desk-scene

The correct repair is to restore the intended order, or deliberately change the prompt and expected map together. Do not simply silence the check: an empty error list only means the local labels match the expected plan.

The local example checks passed for the original mapping, the reversed pack, absent and out-of-range tags, duplicate labels, repeated valid references and malformed plans. These are JavaScript checks, not a model generation test.

Keep the boundary explicit

This parser recognizes @Image followed by digits and a word boundary. It is not a complete prompt grammar: it does not validate every malformed tag, inspect image contents, prove ownership, check upload success or predict whether the output will preserve the subject. It only compares local reference labels. Use separately validated prompt syntax, file checks and the documented server validation process in a real integration.

For this concrete example, the current Vidu Q4 reference route on MixVio accepts 1–12 photos and up to three MP3 references. Its single-photo route takes exactly one photo, follows the photo ratio and includes native audio. Those controls were checked on October 10, 2026; they are not identical to the limits of every Vidu interface. The helper above intentionally does not hard-code them, because reference mapping and route validation solve different problems.

After generation, keep a separate output review with pass, fail or not reviewed for identity, text, motion and sound. Before a real clip exists, every result stays not reviewed. A correctly mapped request can still produce an unsuitable output.

Disclosure: written with AI assistance. The JavaScript examples were executed locally; no video was generated for this tutorial. Photo labels and the product scene are illustrative. This is an independent technical adaptation of the MixVio team's earlier shot-manifest guide, focused on reference ordering.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?