Skip to content

Rendering recipes

This guide is paste-and-tune code for drawing the three feature types in advanced visualization data:

Feature typeMetricsRecipe
Spotsacne, freckles, dark spots, hyperpigmentation→ Spots
Polylineswrinkles + sub-region variants→ Polylines
Polygon areasredness, melasma, shine, glow, texture, uneven skin tone, skin sagging, pore dilation→ Polygon areas

The renderers below are vanilla Canvas 2D, no dependencies. Same iteration shape, same render rules, simplified to the essentials of what works for these data types.

Every advanced-visualization render starts with the same nested iteration:

// 1. Find the metric in results[].
const finding = response.results.find((r) => r.description === "redness");
if (!finding) return;
// 2. Each measurement_locations[] entry can carry visualization_data[].
// Shine also has a "Global" entry covering the zone entries: draw Global only.
const locations = finding.measurement_locations ?? [];
const global = locations.filter((loc) => loc.description === "Global");
for (const loc of global.length ? global : locations) {
// 3. Sort features ascending by intensity before drawing.
// Higher-intensity polygons sit INSIDE lower-intensity ones —
// drawing low → high gives correct overpainting. Polylines carry an
// array of per-point intensities, so sort those by mean_intensity.
const level = (f) => (typeof f.intensity === "number" ? f.intensity : f.mean_intensity ?? 0);
const features = (loc.visualization_data ?? [])
.slice()
.sort((a, b) => level(a) - level(b));
for (const f of features) {
// mean_intensity is the canonical color-decision input;
// fall back to intensity if absent.
const colorIntensity = f.mean_intensity ?? f.intensity;
drawFeature(ctx, f, colorIntensity);
}
}

Four rules from this loop:

  1. Sort features ascending by intensity before drawing. Required for area metrics, harmless for spot/line. Keeps render order deterministic.
  2. Prefer mean_intensity ?? intensity for color decisions — mean_intensity is more stable than the raw per-coordinate intensity on multi-point features.
  3. Stay in original-image pixel space. All x / y arrays are in input-image coordinates. Render onto a canvas of the same dimensions as the source image, no transform required.
  4. Draw Global only when a metric also has zone entries. Shine’s Global entry carries the whole-face areas and its t-zone / u-zone entries the same areas cut to each zone, so drawing every entry draws most areas twice. Draw Global, or the zones, not both.

A spot feature is a single point (length: 1, x, y and intensity are length-1 arrays; mean_intensity holds the same value as a number).

// Recipe 1 — spots. Requires nothing. Used via renderMetric (render.js) or directly.
/**
* Draw a single spot — used for acne, freckles, dark spots,
* hyperpigmentation.
*
* `style` controls the marker shape:
* "dot" — two concentric circles (recommended for acne, freckles)
* "box" — square outline (dark spots / hyperpigmentation)
*/
function drawSpot(ctx, feature, intensity, { style, color, scale = 1 }) {
const x = feature.x[0];
const y = feature.y[0];
ctx.save();
ctx.strokeStyle = color;
ctx.fillStyle = color;
ctx.lineWidth = 2 * scale;
if (style === "dot") {
// Inner solid disc + outer stroke ring.
ctx.beginPath();
ctx.arc(x, y, 6 * scale, 0, Math.PI * 2);
ctx.fill();
ctx.beginPath();
ctx.arc(x, y, 12 * scale, 0, Math.PI * 2);
ctx.lineWidth = 2 * scale;
ctx.stroke();
} else if (style === "box") {
const size = 18 * scale;
ctx.lineWidth = 4 * scale;
ctx.strokeRect(x - size / 2, y - size / 2, size, size);
} else if (style === "cross") {
const size = 14 * scale;
ctx.lineWidth = 4 * scale;
ctx.beginPath();
ctx.moveTo(x - size / 2, y - size / 2);
ctx.lineTo(x + size / 2, y + size / 2);
ctx.moveTo(x + size / 2, y - size / 2);
ctx.lineTo(x - size / 2, y + size / 2);
ctx.stroke();
}
ctx.restore();
}

Used on: acne, freckles, dark spots, hyperpigmentation.

Marker size is fixed in viewBox-pixel terms (6/12 px for dots, 18 px for boxes, 14 px for crosses are workable defaults); pass a scale if you’re rendering on a downsized canvas.

A polyline feature is a connected line — one wrinkle, one fold. x and y are length-N arrays of points along the line. intensity is an array of length N (per-point intensity), and length_weighted_intensity is the canonical “how bad is this wrinkle” composite.

// Recipe 2 — polylines. Requires nothing. Used via renderMetric (render.js) or directly.
const FILTER_STEP = 3;
const FILTER_THRESHOLD = 20;
/**
* Decimate dense point arrays for performance — wrinkles can carry
* hundreds of points along a single line. Filtering every Nth point
* above a threshold gives a visually identical render at a fraction
* of the cost.
*/
function decimate(arr, step = FILTER_STEP, threshold = FILTER_THRESHOLD) {
if (arr.length <= threshold) return arr;
return arr.filter((_, i) => i % step === 0 || i === arr.length - 1);
}
/**
* Draw a polyline — used for wrinkles and its sub-region variants
* (nasolabial folds, marionette lines, etc.).
*/
function drawPolyline(ctx, feature, intensity, { color, strokeWidth = 4, scale = 1 }) {
const xs = decimate(feature.x);
const ys = decimate(feature.y);
if (xs.length < 2) return;
ctx.save();
ctx.strokeStyle = color;
ctx.lineWidth = strokeWidth * scale;
ctx.lineCap = "round";
ctx.lineJoin = "round";
ctx.beginPath();
ctx.moveTo(xs[0], ys[0]);
for (let i = 1; i < xs.length; i++) ctx.lineTo(xs[i], ys[i]);
ctx.stroke();
ctx.restore();
}

Used on: wrinkles.

For ranking wrinkles (e.g., “show me the worst 5”), sort the features by length_weighted_intensity descending — that composite is built specifically for this use.

A polygon-area feature is an enclosed region whose intensity is a categorical integer indexing levels, counting up from 1. The top of the range varies by metric — 1..2 up to 1..9 — see the level table. Each level can come back as several features, one per separate region at that level.

For most of these metrics the levels are increasing thresholds on one field, so higher levels sit inside lower ones and layered fills read as a gradient. skin_sagging also draws polygons but its intensity is a continuous score, not a level. shine (1..4) and skin_type (1..9) are different again: their levels come from separate source fields, so treat the integer as a label and give each level its own colour rather than a position on one ramp.

// Recipe 3 — polygon areas. Requires nothing. Used via renderMetric (render.js) or directly.
/**
* Draw a polygon-area feature — used for redness, melasma, shine, skin type,
* texture, uneven skin tone, skin sagging, pore dilation.
*
* Colour: pick one outside the skin-tone gamut (blue, magenta, teal, green), so it reads
* as an annotation on every skin tone instead of fusing into it or looking like a skin
* condition. For the threshold-based metrics keep ONE colour and carry the level in
* opacityForLevel(intensity) — translucent fills of any colour pull towards skin, so keep
* them light and let the outline do the work. For shine and skin type (categories, not
* levels) map each level to its own colour with colorForLevel(intensity) instead.
*/
function drawPolygonArea(ctx, feature, intensity, { colorForLevel, opacity = 0.2, opacityForLevel, outline = 2, scale = 1 }) {
const xs = feature.x;
const ys = feature.y;
if (xs.length < 3) return;
const color = colorForLevel(intensity);
ctx.save();
ctx.beginPath();
ctx.moveTo(xs[0], ys[0]);
for (let i = 1; i < xs.length; i++) ctx.lineTo(xs[i], ys[i]);
ctx.closePath(); // polygon types are closed shapes — connect last to first
ctx.fillStyle = color;
ctx.globalAlpha = opacityForLevel ? opacityForLevel(intensity) : opacity;
ctx.fill();
if (outline > 0) {
ctx.globalAlpha = 0.9;
ctx.strokeStyle = color;
ctx.lineWidth = outline * scale;
ctx.stroke();
}
ctx.restore();
}

Used on: redness, melasma, texture, uneven skin tone, skin sagging, shine, glow.

Because the shared loop sorts features ascending by intensity, the highest level naturally lands on top. With one colour and opacityForLevel rising with the level (the recipes use 0.12, 0.22, 0.32), the layered fill reads as a density map — outer (low) areas stay faint, inner (high) areas dominate — while the outline keeps every region visible on every skin tone. Use a colour outside the skin-tone gamut (blue, magenta, teal, green): warm colours fuse into light skin and look like the condition itself. For shine and skin_type, keep the sort for deterministic draw order but pick colorForLevel per level rather than as a ramp, since their levels aren’t a severity sequence.

One function selects the finding and walks its features in the right order; each metric is then a single call that names the recipe and the colours:

render.js
// renderMetric: the shared loop. Requires one of the draw recipes to pass as options.draw.
function renderMetric(ctx, response, metric, options) {
const finding = response.results.find((r) => r.description === metric);
if (!finding) return;
// Shine has a "Global" entry with the whole-face areas plus "t-zone" / "u-zone" entries
// with the same areas cut to each zone. Draw Global only, or most areas draw twice.
const locations = finding.measurement_locations ?? [];
const global = locations.filter((loc) => loc.description === "Global");
for (const loc of global.length ? global : locations) {
// Polylines carry an array of per-point intensities; sort those by mean_intensity.
const level = (f) => (typeof f.intensity === "number" ? f.intensity : f.mean_intensity ?? 0);
const features = (loc.visualization_data ?? [])
.slice()
.sort((a, b) => level(a) - level(b));
for (const f of features) {
const intensity = f.mean_intensity ?? f.intensity;
options.draw(ctx, f, intensity, options);
}
}
}
metrics/redness.js
// Requires render.js and polygon-areas.js from /demos/recipes/ (or revieve-render.js).
// ctx: 2D context of a canvas sized to the analysed image. response: parsed analyzeImage JSON.
// Redness: polygon areas at levels 1..3, drawn low to high so higher levels sit on top; the level shows as a denser fill of the same colour.
renderMetric(ctx, response, "redness", {
draw: drawPolygonArea,
colorForLevel: () => "#3377FF", // one colour, outside the skin-tone gamut
opacityForLevel: (level) => [0.12, 0.22, 0.32][level - 1] ?? 0.32, // the level is the fill density
});

Every concept page shows its own call like this one, in the Code tab beside its reference image. The preview below draws three of them at once: freckles, wrinkles and redness.

The preview runs on recorded partner-test responses for a set of licensed model photos, drawn on the analysed photo in source-image coordinates. Toggle the layers, switch model with the thumbnails, and hold the photo to see it without overlays. Note how freckle markers and wrinkle lines differ between faces, and how the redness levels nest.

Everything above in one file: upload a photo, request a metric with its visualization channel, draw the photo on a canvas of the same size, make one metric call.

index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="color-scheme" content="light dark">
<title>Revieve — draw an overlay</title>
<!-- The rendering recipes as one file. Also available per file, see the guide. -->
<script src="/demos/recipes/revieve-render.js"></script>
</head>
<body>
<input type="file" id="file" accept="image/jpeg" />
<button id="go" disabled>Analyze and draw redness</button>
<p id="status"></p>
<canvas id="canvas" style="max-width: 100%"></canvas>
<script type="module">
const PARTNER_ID = "jmlv6b2qtS";
const BASE = "https://partner-test.revieve.com/api/3";
const file = document.getElementById("file");
const go = document.getElementById("go");
const status = document.getElementById("status");
const canvas = document.getElementById("canvas");
file.addEventListener("change", () => { go.disabled = !file.files[0]; });
go.addEventListener("click", async () => {
status.textContent = "Analyzing…";
// 1. Ask for the metric and its visualization channel.
const url = new URL(`${BASE}/analyzeImage/`);
url.searchParams.set("skintone", "0");
url.searchParams.set("gender", "unknown");
url.searchParams.set("components", "redness,redness_visualization");
const form = new FormData();
form.append("partner_id", PARTNER_ID);
form.append("image", file.files[0]);
const res = await fetch(url, { method: "POST", body: form });
const response = await res.json();
if (response.message === "Error") {
status.textContent = `Failed: ${response.status?.[0]?.description ?? "unknown"}`;
return;
}
// 2. Draw the photo on a canvas the size of the photo. Feature coordinates are in
// the pixel space of the image you uploaded, so no scaling is needed.
const photo = await createImageBitmap(file.files[0]);
canvas.width = photo.width;
canvas.height = photo.height;
const ctx = canvas.getContext("2d");
ctx.drawImage(photo, 0, 0);
// 3. One call per metric: the recipe to use and the colours. (Same call as the
// Code panel on the redness concept page.)
renderMetric(ctx, response, "redness", {
draw: drawPolygonArea,
colorForLevel: () => "#3377FF",
opacityForLevel: (level) => [0.12, 0.22, 0.32][level - 1] ?? 0.32,
});
const finding = response.results.find((r) => r.description === "redness");
status.textContent = `redness ${Math.round(finding.value * 100)} / 100 — ${response.message}`;
});
</script>
</body>
</html>

The recipes are plain scripts with no dependencies, served from this site at stable URLs:

  • One file, classic script: https://api.revieve.com/demos/recipes/revieve-render.js (defines renderMetric, drawSpot, drawPolyline, drawPolygonArea, decimate as globals)
  • One file, ES module: https://api.revieve.com/demos/recipes/revieve-render.mjs (same functions as named exports)
  • Per recipe: https://api.revieve.com/demos/recipes/spots.js, polylines.js, polygon-areas.js, render.js
  • Per metric call, as shown on each concept page: https://api.revieve.com/demos/recipes/metrics/<slug>.js, for example metrics/redness.js

Each file starts with a comment saying what it requires. The functions expect a 2D context ctx on a canvas sized to the analysed image and the parsed analyzeImage JSON as response; nothing else is assumed. The current version is in the header of the bundle. Copy the files into your project and pin them; they are small enough to read in full.

  • Server-side / Python. Use OpenCV (cv2.fillPoly, cv2.polylines, cv2.circle) or matplotlib.pyplot — both are workable for batch rendering and report generation.
  • SVG. Build a <polygon>, <polyline>, or <circle> element per feature inside an <svg viewBox="0 0 W H"> matching the input image. Same iteration; different output target.
  • Native (iOS / Android). No first-party recommendation from Revieve at this time; use the platform’s native graphics APIs (Core Graphics on iOS, Canvas on Android) with the same iteration logic.
  • Visualization data — the three-tier model and feature-shape reference.
  • Masks — the tier-2 region-boundary format and its drawing program.
  • Sub-area divisions — face-region splits used by measurement_locations[].