GPT-6.1-Sol · MagicBrush inpaint teacher audit

54 MagicBrush train samples previously flagged requires_inpaint. The teacher must write pixel code directly (cv2.inpaint / patch synthesis / seamlessClone), execute it, and produce the RGB result. Judge is GPT-5.5; pass = instruction ≥4, preservation ≥4, quality ≥3. Not the official MagicBrush metric.

54
samples
52
executed
36
judge pass
66.7%
overall pass rate
69.2%
of executed
remove the mesh screen
magicbrush_train_181992_2 · remove · execution=failed
EXEC FAIL
source
execution failed
no output
MagicBrush target (reference only)

no executed image

reasoning / plan
{
 "visual_evidence": [
  "A dark diamond-pattern mesh spans the lower part of the open cargo area.",
  "The mesh overlays the pale central luggage, the bags on the left, and the colorful bag on the right.",
  "A dark upper cord and lower edging outline the mesh."
 ],
 "target_object": "The cargo mesh screen and its visible edging",
 "target_region": "The foreground of the cargo opening, approximately the lower half of the image",
 "editing_intent": "Remove the mesh while reconstructing the luggage and bag surfaces visible behind it.",
 "editing_plan": [
  "Limit detection to the mesh panel, following its irregular upper and lower boundaries.",
  "Detect narrow, dark diagonal strands using local contrast and directional morphology.",
  "Include the visible upper cord, side edging, lower edging, and small lower mesh attachment.",
  "Inpaint the masked strands using surrounding colors and surface shading.",
  "Restore locally sampled fine texture and grain, and feather the repaired boundaries."
 ],
 "preservation_constraints": [
  "Keep the vehicle, open hatch, seats, and outdoor background unchanged.",
  "Preserve the positions, silhouettes, colors, and visible designs of the packed luggage.",
  "Do not remove the central vehicle latch or alter the bumper.",
  "Do not change pixels outside the screen and its edging."
 ]
}
pixel code
def edit(image):
    import cv2
    import numpy as np
    from PIL import Image

    w, h = image.size
    s = float(min(w, h))
    src = np.asarray(image.convert('RGB')).copy()
    def point(x, y):
        return (int(round(x * (w - 1))), int(round(y * (h - 1))))
    def odd_size(fraction, minimum=3):
        n = max(minimum, int(round(s * fraction)))
        return n if n % 2 else n + 1
    def ellipse(radius):
        radius = max(1, int(radius))
        return cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2 * radius + 1, 2 * radius + 1))

    # The mesh is restricted to the cargo opening, not the bumper or car frame.
    outline = [(0.119, 0.474), (0.238, 0.496), (0.367, 0.515),
               (0.515, 0.512), (0.669, 0.509), (0.807, 0.494),
               (0.991, 0.461), (0.977, 0.716), (0.948, 0.790),
               (0.907, 0.824), (0.794, 0.833), (0.629, 0.830),
               (0.454, 0.824), (0.173, 0.822), (0.131, 0.724),
               (0.116, 0.612)]
    panel = np.zeros((h, w), np.uint8)
    cv2.fillPoly(panel, [np.array([point(x, y) for x, y in outline], np.int32)], 255)

    lum = cv2.cvtColor(src, cv2.COLOR_RGB2GRAY)
    close_kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,
                                            (odd_size(0.027), odd_size(0.027)))
    closed = cv2.morphologyEx(lum, cv2.MORPH_CLOSE, close_kernel)
    contrast = closed.astype(np.float32) - lum.astype(np.float32)
    # A slightly lower threshold catches strands crossing dark fabric.
    threshold = np.full((h, w), 9.0, np.float32)
    threshold[int(h * 0.54):int(h * 0.82), int(w * 0.36):int(w * 0.63)] = 7.0
    ridges = ((contrast > threshold) & (lum < 225) & (panel > 0)).astype(np.uint8) * 255

    # Mesh strands run in two diagonal families, with local perspective changes.
    directional = np.zeros_like(panel)
    n = odd_size(0.015, 5)
    c = n // 2
    for sign in (-1, 1):
        for slope in (0.55, 0.70, 0.85, 1.00, 1.18):
            kernel = np.zeros((n, n), np.uint8)
            for dx in range(-c, c + 1):
                yy = c + int(round(sign * slope * dx))
                if 0 <= yy < n:
                    kernel[yy, c + dx] = 1
            opened = cv2.morphologyEx(ridges, cv2.MORPH_OPEN, kernel)
            directional = cv2.bitwise_or(directional, opened)

    # Recover short gaps at diamond corners without masking whole luggage areas.
    near_diagonal = cv2.dilate(directional, ellipse(round(s * 0.004)))
    strands = cv2.bitwise_or(directional, cv2.bitwise_and(ridges, near_diagonal))
    lines = cv2.HoughLinesP(directional, 1, np.pi / 180,
                           threshold=max(6, int(s * 0.018)),
                           minLineLength=max(8, int(s * 0.025)),
                           maxLineGap=max(2, int(s * 0.006)))
    if lines is not None:
        line_layer = np.zeros_like(panel)
        for entry in lines[:, 0]:
            x1, y1, x2, y2 = map(int, entry)
            dx, dy = x2 - x1, y2 - y1
            if dx == 0:
                continue
            slope = abs(dy / float(dx))
            if not 0.45 <= slope <= 1.35:
                continue
            count = max(abs(dx), abs(dy)) + 1
            xx = np.clip(np.rint(np.linspace(x1, x2, count)).astype(int), 0, w - 1)
            yy = np.clip(np.rint(np.linspace(y1, y2, count)).astype(int), 0, h - 1)
            if np.mean(near_diagonal[yy, xx] > 0) > 0.78:
                cv2.line(line_layer, (x1, y1), (x2, y2), 255,
                         max(1, int(round(s * 0.003))))
        strands = cv2.bitwise_or(strands, cv2.bitwise_and(line_layer, panel))
    strands = cv2.dilate(strands, ellipse(round(s * 0.0025)))
    strands = cv2.bitwise_and(strands, panel)

    # Explicit edging masks follow visible cords rather than broad rectangles.
    edging = np.zeros_like(panel)
    def cord(vertices, thickness):
        pts = np.array([point(x, y) for x, y in vertices], np.int32)
        cv2.polylines(edging, [pts], False, 255,
                      max(2, int(round(s * thickness))), cv2.LINE_AA)
    cord([(0.120, 0.479), (0.239, 0.498), (0.363, 0.517),
          (0.508, 0.513), (0.658, 0.510), (0.801, 0.498),
          (0.985, 0.466)], 0.010)
    cord([(0.120, 0.479), (0.125, 0.611), (0.138, 0.720),
          (0.176, 0.813)], 0.010)
    cord([(0.176, 0.815), (0.325, 0.822), (0.470, 0.823),
          (0.624, 0.827), (0.790, 0.825), (0.878, 0.819)], 0.009)
    # The small attachment on the left belongs to the mesh; the car latch does not.
    clip = np.array([point(0.296, 0.815), point(0.325, 0.815),
                     point(0.324, 0.845), point(0.291, 0.845)], np.int32)
    cv2.fillPoly(edging, [clip], 255)
    mask = cv2.bitwise_or(strands, np.where(edging > 20, 255, 0).astype(np.uint8))

    # Preserve the vehicle latch and the bright bumper below the mesh.
    protected = np.zeros_like(mask)
    cv2.rectangle(protected, point(0.548, 0.843), point(0.649, 0.900), 255, -1)
    mask[protected > 0] = 0
    mask[int(round(h * 0.849)):, :] = 0
    if not np.any(mask):
        return Image.fromarray(src)

    radius = max(2, int(round(s * 0.007)))
    telea = cv2.inpaint(src, mask, radius, cv2.INPAINT_TELEA).astype(np.float32)
    navier = cv2.inpaint(src, mask, radius, cv2.INPAINT_NS).astype(np.float32)
    repaired = 0.78 * telea + 0.22 * navier

    # Extract clean local detail using a normalized blur that excludes screen pixels.
    safe_mask = cv2.dilate(mask, ellipse(round(s * 0.004)))
    valid = (safe_mask == 0).astype(np.float32)
    sigma = max(0.8, s * 0.004)
    weights = cv2.GaussianBlur(valid, (0, 0), sigma)
    smooth = np.empty_like(repaired)
    for channel in range(3):
        weighted = src[:, :, channel].astype(np.float32) * valid
        numerator = cv2.GaussianBlur(weighted, (0, 0), sigma)
        smooth[:, :, channel] = numerator / np.maximum(weights, 1e-5)
    texture = np.clip(src.astype(np.float32) - smooth, -10.0, 10.0)
    texture[valid == 0] = 0

    # Transfer only high-frequency detail from the nearest unoccluded source pixels.
    distance_input = (safe_mask > 0).astype(np.uint8)
    _, labels = cv2.distanceTransformWithLabels(distance_input, cv2.DIST_L2, 5,
                                               labelType=cv2.DIST_LABEL_PIXEL)
    yy, xx = np.nonzero(distance_input == 0)
    lookup = np.zeros((int(labels.max()) + 1, 3), np.float32)
    lookup[labels[yy, xx]] = texture[yy, xx]
    copied_detail = lookup[labels]
    rng = np.random.default_rng(1647)
    grain = rng.normal(0.0, 0.65, (h, w, 1)).astype(np.float32)
    repaired += 0.48 * copied_detail + grain

    # Feather inside the removal mask so untouched source pixels remain exact.
    inside_distance = cv2.distanceTransform((mask > 0).astype(np.uint8), cv2.DIST_L2, 5)
    feather_width = max(1.0, s * 0.002)
    alpha = np.clip(inside_distance / feather_width, 0.0, 1.0)[:, :, None]
    result = src.astype(np.float32) * (1.0 - alpha) + repaired * alpha
    return Image.fromarray(np.clip(np.rint(result), 0, 255).astype(np.uint8), 'RGB')
let the dogs wear jackets
magicbrush_train_275542_2 · add / insert · execution=failed
EXEC FAIL
source
execution failed
no output
MagicBrush target (reference only)

no executed image

reasoning / plan
{
 "visual_evidence": [
  "A brown dog on the left has a large visible torso and a blue collar.",
  "A second brown dog faces forward, with its upper back visible behind its head.",
  "A light-colored dog's head and a small portion of its neck enter from the right edge.",
  "The dogs are holding a pale toy over grass."
 ],
 "target_object": "The three dogs' visible clothing areas",
 "target_region": "The left dog's torso, the center dog's exposed upper back, and the small cropped neckline of the right dog",
 "editing_intent": "Add realistically shaded fabric jackets, leaving the dogs' faces, legs, tails, and shared toy unchanged.",
 "editing_plan": [
  "Trace curved garment masks inside the visible dog silhouettes.",
  "Exclude the center dog's head and preserve the left dog's existing blue collar.",
  "Synthesize teal, navy, and rust-colored fabric using the original shading, woven texture, and fine grain.",
  "Add curved fabric folds, seams, narrow binding, and a zipper on the center jacket.",
  "Feather the garment boundaries and composite without changing the grass or toy."
 ],
 "preservation_constraints": [
  "Keep all faces, eyes, ears, noses, and mouths unchanged.",
  "Preserve the pale toy and the dogs' interaction with it.",
  "Keep the blue collar visible.",
  "Do not change the legs, tail, grass, framing, or lighting.",
  "Only show a small jacket neckline on the right dog because its body is outside the frame."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    image = image.convert('RGB')
    w, h = image.size
    src = np.asarray(image).astype(np.float32)
    result = src.copy()
    rng = np.random.default_rng(37)

    def curve_points(start, segments):
        current = np.array(start, dtype=np.float64)
        points = [current.copy()]
        for segment in segments:
            if segment[0] == 'L':
                current = np.array(segment[1], dtype=np.float64)
                points.append(current.copy())
            else:
                a = current.copy()
                b = np.array(segment[1], dtype=np.float64)
                c = np.array(segment[2], dtype=np.float64)
                d = np.array(segment[3], dtype=np.float64)
                for t in np.linspace(0, 1, 28)[1:]:
                    points.append((1-t)**3*a + 3*(1-t)**2*t*b + 3*(1-t)*t*t*c + t**3*d)
                current = d
        return np.array(points)

    def shape(start, segments):
        points = curve_points(start, segments)
        high = np.zeros((h*3, w*3), np.uint8)
        vertices = np.rint(points * [w*3, h*3]).astype(np.int32)
        cv2.fillPoly(high, [vertices], 255, lineType=cv2.LINE_AA)
        return cv2.resize(high, (w, h), interpolation=cv2.INTER_AREA).astype(np.float32)/255

    def line(start, segments, width):
        points = curve_points(start, segments)
        high = np.zeros((h*3, w*3), np.uint8)
        vertices = np.rint(points * [w*3, h*3]).astype(np.int32)
        cv2.polylines(high, [vertices], False, 255, max(1, int(round(width*w*3))), cv2.LINE_AA)
        return cv2.resize(high, (w, h), interpolation=cv2.INTER_AREA).astype(np.float32)/255

    left = shape((0, .380), [
        ('C', (.059,.380), (.148,.392), (.206,.401)),
        ('C', (.187,.437), (.189,.494), (.204,.552)),
        ('C', (.215,.593), (.236,.625), (.260,.647)),
        ('C', (.278,.670), (.260,.697), (.237,.717)),
        ('C', (.192,.733), (.151,.703), (.104,.698)),
        ('C', (.061,.705), (.024,.729), (0,.735)),
        ('L', (0,.380))])

    center = shape((.689,.207), [
        ('C', (.691,.175), (.723,.149), (.766,.146)),
        ('C', (.809,.142), (.840,.164), (.858,.194)),
        ('C', (.878,.238), (.883,.298), (.873,.348)),
        ('C', (.864,.390), (.843,.429), (.808,.459)),
        ('C', (.778,.442), (.740,.421), (.699,.412)),
        ('C', (.669,.371), (.668,.274), (.689,.207))])

    head = shape((.537,.289), [
        ('C', (.551,.250), (.593,.223), (.630,.221)),
        ('C', (.680,.215), (.728,.232), (.766,.257)),
        ('C', (.795,.283), (.806,.331), (.803,.381)),
        ('C', (.807,.422), (.780,.460), (.758,.493)),
        ('C', (.747,.533), (.708,.541), (.676,.526)),
        ('C', (.643,.510), (.622,.469), (.616,.434)),
        ('C', (.592,.428), (.578,.446), (.553,.456)),
        ('C', (.542,.423), (.543,.372), (.552,.341)),
        ('C', (.540,.329), (.530,.312), (.537,.289))])
    center *= 1-head

    right = shape((1,.574), [
        ('C', (.989,.585), (.978,.603), (.961,.615)),
        ('C', (.971,.632), (.990,.645), (1,.650)),
        ('L', (1,.574))])

    # Color checks keep traced fabric inside fur rather than on the grass.
    smooth_rgb = cv2.GaussianBlur(src, (0,0), max(.6,w*.0015))
    r, g, b = [smooth_rgb[:,:,i] for i in range(3)]
    brown = ((r-g > 8) & (b-g > 1)).astype(np.uint8)
    k = max(3, int(round(w*.010)) | 1)
    brown = cv2.morphologyEx(brown, cv2.MORPH_CLOSE, np.ones((k,k), np.uint8)).astype(np.float32)
    brown = cv2.GaussianBlur(brown, (0,0), max(.35,w*.0007))
    left *= brown
    center *= brown
    pale_fur = ((r-g > 11) & (g-b > 5) & (r > 155)).astype(np.float32)
    pale_fur = cv2.GaussianBlur(pale_fur, (0,0), max(.35,w*.0007))
    right *= pale_fur

    yy, xx = np.mgrid[0:h, 0:w].astype(np.float32)
    collar = ((xx > .185*w) & (xx < .307*w) & (yy > .377*h) & (yy < .663*h) & (src[:,:,2] > src[:,:,0]*1.12) & (src[:,:,2] > src[:,:,1]*1.08)).astype(np.float32)
    collar = cv2.dilate(collar, np.ones((3,3),np.uint8))
    left *= 1-collar

    lum = src[:,:,0]*.299 + src[:,:,1]*.587 + src[:,:,2]*.114
    broad = cv2.GaussianBlur(lum, (0,0), max(1,w*.012))
    highpass = lum-cv2.GaussianBlur(lum, (0,0), max(.5,w*.0015))
    weave = .012*np.sin(xx*2*np.pi/max(1.3,w*.0032)) + .009*np.sin((yy+.15*xx)*2*np.pi/max(1.4,h*.0036))
    noise = rng.normal(0,.9,(h,w)).astype(np.float32)

    left_seams = [
        ((.012,.436), [('C',(.083,.447),(.145,.463),(.192,.486)]),
        ((.012,.519), [('C',(.070,.535),(.137,.552),(.205,.565)]),
        ((.009,.603), [('C',(.077,.619),(.147,.634),(.236,.653)]),
        ((.052,.400), [('C',(.081,.481),(.095,.593),(.127,.700)]),
        ((.010,.707), [('C',(.089,.675),(.174,.699),(.236,.699)])]
    center_seams = [
        ((.704,.209), [('C',(.755,.190),(.810,.204),(.861,.247)]),
        ((.756,.151), [('C',(.787,.208),(.809,.276),(.837,.352)]),
        ((.806,.298), [('C',(.828,.322),(.849,.334),(.873,.339)]),
        ((.801,.408), [('C',(.823,.418),(.840,.404),(.855,.386)])]
    right_seams = [
        ((.976,.620), [('C',(.984,.628),(.993,.633),(1,.635)])]

    def dress(mask, color, binding, seams, seed_offset):
        nonlocal result
        if np.sum(mask) < 1:
            return
        mean = float(np.sum(broad*mask)/np.sum(mask))
        shade = np.clip((broad+12)/(mean+12), .56, 1.38)**.58
        # Fine fabric texture keeps source shading but replaces the furry surface.
        textile = shade*(1+weave)
        material = np.array(color,np.float32)[None,None,:]*textile[:,:,None]
        material += (noise + np.clip(highpass,-14,14)*.12)[:,:,None]

        distance = cv2.distanceTransform((mask>.48).astype(np.uint8), cv2.DIST_L2, 5)
        edge_shade = np.exp(-distance/max(1,w*.004))*0.12
        material *= (1-edge_shade[:,:,None])

        for j, (start, segments) in enumerate(seams):
            seam = line(start, segments, .0022)
            fold = cv2.GaussianBlur(seam, (0,0), max(.65,w*.004))
            peak = max(float(fold.max()), 1e-5)
            material *= (1-.075*fold[:,:,None]/peak)
            material *= (1-.16*seam[:,:,None])
            # Offset highlight makes each seam look raised rather than drawn on.
            shift = max(1,int(round(w*.0018)))
            highlight = np.roll(seam, shift, axis=1)*.08
            material += highlight[:,:,None]*np.array([100,105,103],np.float32)
            if j == len(seams)-1:
                stitch = line(start, segments, .0011)
                dashed = ((xx+yy*.55+seed_offset) % max(3,w*.010) < max(1,w*.003))
                stitch *= dashed
                material = material*(1-stitch[:,:,None]*.40) + np.array(binding,np.float32)[None,None,:]*stitch[:,:,None]*.40

        # Narrow, textured binding sits just inside the jacket silhouette.
        scale = max(.7,w*.0021)
        piping = np.exp(-((distance-1.65*scale)/(.67*scale))**2)*.66
        piping *= (distance>0)
        piping[:, :max(1,int(w*.005))] = 0
        piping[:, w-max(1,int(w*.005)):] = 0
        trim = np.array(binding,np.float32)[None,None,:]*shade[:,:,None]
        trim += noise[:,:,None]*.65
        material = material*(1-piping[:,:,None]) + trim*piping[:,:,None]
        material = np.clip(material,0,255)
        alpha = cv2.GaussianBlur(mask,(0,0),max(.25,w*.0006))
        alpha = np.minimum(alpha,mask)
        result = result*(1-alpha[:,:,None]) + material*alpha[:,:,None]

    dress(left, (43,103,101), (151,158,132), left_seams, 0)
    dress(center, (49,67,92), (173,133,69), center_seams, 2)
    dress(right, (143,72,57), (189,151,119), right_seams, 1)

    # A restrained zipper follows the center dog's curved exposed back.
    zip_start = (.772,.161)
    zip_path = [('C',(.804,.193),(.826,.247),(.839,.304)]
    zipper = line(zip_start,zip_path,.0030)*center
    result *= (1-zipper[:,:,None]*.40)
    teeth = line(zip_start,zip_path,.0015)*center
    teeth *= ((yy+xx*.38) % max(3,h*.008) < max(1,h*.0027))
    result = result*(1-teeth[:,:,None]*.65) + np.array([162,158,141],np.float32)[None,None,:]*teeth[:,:,None]*.65

    # Restore the original collar exactly after compositing.
    result = result*(1-collar[:,:,None]) + src*collar[:,:,None]
    return Image.fromarray(np.clip(result,0,255).astype(np.uint8), 'RGB')
leave only the scissor on the cup
magicbrush_train_513551_1 · remove · execution=passed
FAILinstr 2preserve 2quality 2
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The edit does not leave only the scissor on the cup; other pen-like objects and large ghosted remnants remain. The local area is heavily smeared and blurred, and some unrelated content around the cup/tools is noticeably altered.

l1=0.0398 · gain=0.0205 · mask_l1=0.0235 · preserve_l1=0.0401

reasoning / plan
{
 "visual_evidence": [
  "Blue-handled scissors extend diagonally from the upper left toward the cup.",
  "Several writing instruments, including a silver-topped dark pen, a black pen, and a red pen, stand beside the scissors.",
  "The cup has a yellow left side and a red front, with its rim visible beneath the tools.",
  "The surrounding background is softly focused and gray."
 ],
 "target_object": "The writing instruments beside the blue-handled scissors",
 "target_region": "The cluster above the cup, extending from the upper-middle area to the lower-right rim",
 "editing_intent": "Remove the writing instruments so that only the scissors remain in the cup.",
 "editing_plan": [
  "Mask the visible writing instruments and their narrow edge halos.",
  "Protect the blue scissors, their visible blades, and the foreground cup rim.",
  "Inpaint the masked areas, supplementing the fill with surrounding background shading and sampled photographic grain.",
  "Restore narrow metal blade continuations only where the removed pens previously obscured the scissors.",
  "Feather the edited boundaries and return the image at its original size."
 ],
 "preservation_constraints": [
  "Keep the blue scissor handles unchanged.",
  "Preserve all originally visible portions of the scissors.",
  "Keep the cup's yellow and red exterior and foreground rim unchanged.",
  "Do not alter visible background lettering outside the removal mask.",
  "Preserve the original framing, soft focus, and photographic texture."
 ]
}
pixel code
def edit(image):
    import cv2
    import numpy as np
    from PIL import Image

    original = np.asarray(image.convert('RGB')).copy()
    h, w = original.shape[:2]
    scale = min(w, h)
    rng = np.random.default_rng(17)

    def polygon(points):
        out = np.zeros((h, w), np.uint8)
        pts = np.array([[round(x * (w - 1)), round(y * (h - 1))] for x, y in points], np.int32)
        cv2.fillPoly(out, [pts], 255)
        return out

    outlines = [
        [(0.375,0.294),(0.397,0.265),(0.431,0.268),(0.458,0.318),
         (0.491,0.404),(0.519,0.489),(0.516,0.547),(0.478,0.525),
         (0.435,0.425),(0.397,0.355)],
        [(0.405,0.263),(0.419,0.244),(0.446,0.237),(0.479,0.243),
         (0.507,0.263),(0.530,0.310),(0.544,0.351),(0.562,0.415),
         (0.598,0.498),(0.650,0.615),(0.703,0.727),(0.739,0.779),
         (0.721,0.795),(0.674,0.775),(0.644,0.733),(0.595,0.628),
         (0.548,0.522),(0.505,0.444),(0.478,0.398),(0.454,0.365),
         (0.426,0.355),(0.411,0.318)],
        [(0.556,0.373),(0.578,0.353),(0.608,0.345),(0.638,0.359),
         (0.659,0.391),(0.674,0.423),(0.709,0.453),(0.736,0.506),
         (0.780,0.602),(0.827,0.704),(0.884,0.806),(0.861,0.821),
         (0.816,0.808),(0.778,0.752),(0.739,0.673),(0.702,0.599),
         (0.672,0.553),(0.634,0.551),(0.605,0.531),(0.585,0.487),
         (0.568,0.438)],
        [(0.676,0.323),(0.689,0.307),(0.715,0.305),(0.734,0.322),
         (0.743,0.354),(0.769,0.373),(0.803,0.424),(0.847,0.501),
         (0.890,0.590),(0.935,0.689),(0.966,0.756),(0.968,0.781),
         (0.960,0.796),(0.978,0.816),(0.933,0.819),(0.908,0.776),
         (0.875,0.705),(0.839,0.629),(0.800,0.552),(0.763,0.493),
         (0.730,0.451),(0.709,0.415),(0.687,0.387),(0.678,0.359)],
        [(0.665,0.393),(0.690,0.383),(0.729,0.426),(0.764,0.510),
         (0.803,0.587),(0.855,0.682),(0.935,0.815),(0.897,0.822),
         (0.842,0.737),(0.792,0.649),(0.752,0.571),(0.711,0.501)]
    ]
    removal = np.zeros((h, w), np.uint8)
    for points in outlines:
        removal = cv2.bitwise_or(removal, polygon(points))
    grow = max(1, round(scale * 0.004))
    removal = cv2.dilate(removal, cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2*grow+1, 2*grow+1)))

    yy, xx = np.mgrid[0:h, 0:w]
    xn = xx / max(w-1, 1)
    yn = yy / max(h-1, 1)
    hsv = cv2.cvtColor(original, cv2.COLOR_RGB2HSV)
    blue = ((hsv[:,:,0] >= 92) & (hsv[:,:,0] <= 128) &
            (hsv[:,:,1] > 95) & (xn < 0.515) & (yn < 0.665)).astype(np.uint8) * 255
    blue = cv2.dilate(blue, np.ones((3,3), np.uint8))
    removal[blue > 0] = 0

    rim_x = np.array([0.0,0.529,0.556,0.630,0.699,0.786,1.0])
    rim_y = np.array([0.682,0.682,0.724,0.766,0.799,0.813,0.815])
    front_limit = np.interp(xn, rim_x, rim_y)
    removal[(xn >= 0.529) & (yn >= front_limit)] = 0

    visible_blades = polygon([(0.453,0.598),(0.475,0.604),(0.645,0.745),
                              (0.677,0.765),(0.660,0.765),(0.471,0.634)])
    blade_hsv = cv2.cvtColor(original, cv2.COLOR_RGB2HSV)
    metal_visible = (visible_blades > 0) & (removal == 0) & (blade_hsv[:,:,1] < 145)

    radius = max(3, round(scale * 0.014))
    telea = cv2.inpaint(original, removal, radius, cv2.INPAINT_TELEA).astype(np.float32)
    ns = cv2.inpaint(original, removal, radius, cv2.INPAINT_NS).astype(np.float32)
    filled = 0.55 * telea + 0.45 * ns

    # Read clean shading from the narrow, unobstructed right-hand background.
    xa = min(w-1, max(0, round(w*0.973)))
    xb = max(xa+1, min(w, round(w*0.999)))
    reference = np.median(original[:,xa:xb].astype(np.float32), axis=1)
    reference = cv2.GaussianBlur(reference[:,None,:], (1,0), sigmaX=0,
                                 sigmaY=max(1.0,h*0.023)).reshape(h,3)
    background = np.broadcast_to(reference[:,None,:], (h,w,3)).copy()
    smooth_fill = cv2.GaussianBlur(filled, (0,0), max(1.0,scale*0.014))
    # Keep local illumination, while avoiding propagation of dark ink or blue edges.
    delta = np.clip(smooth_fill-background, -30, 24)
    clean_fill = background + delta
    mix = np.where(yn < 0.38, 0.22, 0.48).astype(np.float32)
    mix *= np.clip((front_limit-yn)/0.045, 0, 1)
    filled = filled*(1-mix[:,:,None]) + clean_fill*mix[:,:,None]

    # Restore subtle correlated sensor/JPEG grain using pixels from the same image.
    ya, yb = round(h*0.54), max(round(h*0.54)+1, round(h*0.70))
    grain_patch = original[ya:yb,xa:xb].astype(np.float32)
    if grain_patch.size:
        low = cv2.GaussianBlur(grain_patch, (0,0), max(0.7,scale*0.002))
        residual = grain_patch-low
        ph,pw = residual.shape[:2]
        ry = rng.integers(0,ph,size=(h,w))
        rx = rng.integers(0,pw,size=(h,w))
        grain = residual[ry,rx]
        grain = np.clip(grain,-4,4)*0.55
    else:
        grain = np.zeros((h,w,3),np.float32)
    noise = rng.normal(0,0.65,(h,w,1)).astype(np.float32)
    filled += grain+noise

    distance = cv2.distanceTransform(removal, cv2.DIST_L2, 3)
    feather = max(1.0,scale*0.003)
    alpha = np.clip(distance/feather,0,1)[:,:,None]
    result = original.astype(np.float32)*(1-alpha)+filled*alpha

    # Reconstruct only the portions of the slim scissor blades hidden by the pens.
    blades = [
        ([(0.462,0.603),(0.480,0.603),(0.731,0.786),(0.720,0.792)],
         np.array([159.,160.,153.]), np.array([112.,116.,112.])),
        ([(0.475,0.627),(0.487,0.621),(0.704,0.778),(0.695,0.785)],
         np.array([143.,124.,94.]), np.array([104.,102.,91.]))
    ]
    for points, light, dark in blades:
        blade = polygon(points)
        blade[(yn >= front_limit) & (xn >= 0.529)] = 0
        blade[blue > 0] = 0
        hidden = (blade.astype(np.float32)/255.0)*(removal.astype(np.float32)/255.0)
        hidden[metal_visible] = 0
        edge = cv2.GaussianBlur(hidden,(0,0),max(0.45,scale*0.001))
        edge *= removal.astype(np.float32)/255.0
        along = np.clip((xn-0.47)/0.26,0,1)
        color = light[None,None,:]*(1-along[:,:,None])+dark[None,None,:]*along[:,:,None]
        axis = 0.608 + 0.72*(xn-0.47)
        highlight = 12*np.exp(-((yn-axis)/0.0028)**2)
        color = color+highlight[:,:,None]+grain*0.55+noise*0.45
        # A narrow soft shadow supplies depth, without touching preserved pixels.
        shift = max(1,round(scale*0.003))
        shadow = np.zeros_like(hidden)
        shadow[shift:,shift:] = hidden[:-shift,:-shift]
        shadow = cv2.GaussianBlur(shadow,(0,0),max(0.7,scale*0.002))
        shadow *= (removal.astype(np.float32)/255.0)*(1-edge)
        result *= 1-0.09*shadow[:,:,None]
        result = result*(1-edge[:,:,None])+color*edge[:,:,None]

    result[removal == 0] = original[removal == 0]
    result[blue > 0] = original[blue > 0]
    return Image.fromarray(np.clip(result,0,255).astype(np.uint8))
Add a big dog.
magicbrush_train_503855_3 · add / insert · execution=passed
PASSinstr 4preserve 5quality 3
source
GPT-6.1-Sol output
MagicBrush target (reference only)

A large dog was added to the scene in the foreground. The rest of the image is essentially unchanged, but the dog is cartoon-like and does not fully match the photographic style or lighting of the original image.

l1=0.0174 · gain=-0.0067 · mask_l1=0.0109 · preserve_l1=0.0262

reasoning / plan
{
 "visual_evidence": [
  "The foreground is a sunlit green lawn.",
  "A small blue umbrella stands left of center, and a larger blue umbrella occupies the lower center.",
  "There is open grass below the small umbrella and to the left of the large umbrella.",
  "Tree trunks, a paved path, and a fenced court are visible farther back."
 ],
 "target_object": "A new large golden-brown dog",
 "target_region": "Open lower-left foreground grass, below the small umbrella and left of the large blue umbrella",
 "editing_intent": "Add a large, standing dog facing right, with natural proportions, textured fur, shaded anatomy, and a grounded cast shadow.",
 "editing_plan": [
  "Construct a supersampled dog silhouette using curved anatomical shapes.",
  "Add a soft cast shadow and darker paw-contact shadows while retaining the grass texture.",
  "Render overlapping legs, tail, torso, neck, head, floppy ear, and muzzle with directional shading and fine fur texture.",
  "Add small realistic eye, nose, mouth, and paw details.",
  "Downsample and alpha-blend the dog into the original image, leaving the umbrellas and background unchanged."
 ],
 "preservation_constraints": [
  "Preserve both blue umbrellas and their poles.",
  "Preserve all tree trunks, the paved path, and the fenced background court.",
  "Keep the original image dimensions.",
  "Do not alter pixels outside the dog and its localized ground shadow."
 ]
}
pixel code
def edit(image):
    import math
    import numpy as np
    import cv2
    from PIL import Image, ImageDraw

    original = image.convert('RGB')
    w, h = image.size
    scale = 3
    W, H = w * scale, h * scale
    rng = np.random.default_rng(1847)
    source = np.asarray(original, dtype=np.float32)
    yy, xx = np.mgrid[0:H, 0:W].astype(np.float32)
    X, Y = xx / W, yy / H
    layer = np.zeros((H, W, 3), np.float32)
    opacity = np.zeros((H, W), np.float32)

    def path_mask(commands):
        points = []
        current = None
        for cmd in commands:
            if cmd[0] == 'M':
                current = np.array(cmd[1:3], dtype=float)
                points.append(tuple(current))
            elif cmd[0] == 'L':
                current = np.array(cmd[1:3], dtype=float)
                points.append(tuple(current))
            elif cmd[0] == 'C':
                p0 = current.copy()
                p1 = np.array(cmd[1:3], dtype=float)
                p2 = np.array(cmd[3:5], dtype=float)
                p3 = np.array(cmd[5:7], dtype=float)
                length = np.linalg.norm((p1-p0)*[W,H]) + np.linalg.norm((p2-p1)*[W,H]) + np.linalg.norm((p3-p2)*[W,H])
                count = max(10, min(160, int(length / 2)))
                for t in np.linspace(0, 1, count + 1)[1:]:
                    q = (1-t)**3*p0 + 3*(1-t)**2*t*p1 + 3*(1-t)*t*t*p2 + t**3*p3
                    points.append(tuple(q))
                current = p3
        im = Image.new('L', (W, H), 0)
        ImageDraw.Draw(im).polygon([(float(x*W), float(y*H)) for x,y in points], fill=255)
        return np.asarray(im, dtype=np.float32) / 255.0

    def over(rgb, a):
        nonlocal layer, opacity
        a = np.clip(a, 0, 1).astype(np.float32)
        if np.ndim(rgb) == 1:
            rgb = np.asarray(rgb, dtype=np.float32)[None, None, :]
        layer = layer * (1-a[...,None]) + rgb * a[...,None]
        opacity = opacity * (1-a) + a

    fine = rng.normal(0, 1, (H, W)).astype(np.float32)
    coarse = cv2.GaussianBlur(fine, (0,0), max(1.0, W*.003))
    coarse /= max(float(coarse.std()), .001)
    strands = cv2.GaussianBlur(fine, (0,0), .45*scale, 1.35*scale)
    strands /= max(float(strands.std()), .001)
    sample = source[int(.60*h):int(.70*h), int(.015*w):int(.16*w)]
    noise_level = 2.2
    if sample.size:
        residual = sample - cv2.GaussianBlur(sample, (0,0), 1.0)
        noise_level = float(np.clip(residual.std()*.24, 1.5, 3.0))

    def fur(commands, color, direction=0.0, contrast=1.0, hair=True):
        raw = path_mask(commands)
        ids = np.where(raw > .5)
        if not len(ids[0]):
            return
        x0, x1 = int(ids[1].min()), int(ids[1].max())+1
        y0, y1 = int(ids[0].min()), int(ids[0].max())+1
        u = (xx-x0)/max(x1-x0,1)
        v = (yy-y0)/max(y1-y0,1)
        distance = cv2.distanceTransform((raw > .5).astype(np.uint8), cv2.DIST_L2, 3)
        edge = np.clip(distance / max(2.0, min(x1-x0,y1-y0)*.13), 0, 1)
        roundness = np.sin(np.pi*np.clip(v, 0, 1))
        lighting = .91 + .20*roundness + .10*(1-u) - .20*v
        lighting -= .10*(1-edge)
        lighting = 1 + (lighting-1)*contrast
        highlight = np.exp(-((u-.35)/.42)**2-((v-.28)/.31)**2)
        texture = 2.3*coarse + 2.0*strands + fine*noise_level
        rgb = np.array(color, dtype=np.float32)[None,None,:] * lighting[...,None]
        rgb += highlight[...,None] * np.array([11, 12, 10], np.float32)
        rgb += texture[...,None] * np.array([1.0,.88,.66], np.float32)
        if hair:
            hair_im = Image.new('L', (x1-x0, y1-y0), 128)
            draw = ImageDraw.Draw(hair_im)
            count = int(min(5500, (x1-x0)*(y1-y0)/(scale*scale)*.28))
            for _ in range(count):
                px = int(rng.integers(x0, x1))
                py = int(rng.integers(y0, y1))
                if raw[py,px] < .5:
                    continue
                angle = direction + float(rng.normal(0,.24))
                length = float(rng.uniform(.7,2.4))*scale
                dx, dy = math.cos(angle)*length, math.sin(angle)*length
                tone = int(rng.choice([110,118,137,145]))
                draw.line((px-x0,py-y0,px-x0+dx,py-y0+dy), fill=tone, width=max(1,scale//2))
            detail = (np.asarray(hair_im, dtype=np.float32)-128)*.30
            rgb[y0:y1,x0:x1] += detail[...,None]*np.array([1,.9,.68],np.float32)
        a = cv2.GaussianBlur(raw, (0,0), .30*scale)
        over(np.clip(rgb, 0, 255), a)

    def ellipse(cx, cy, rx, ry, color, strength=1, angle=0, shiny=False):
        c, s = math.cos(angle), math.sin(angle)
        dx, dy = X-cx, Y-cy
        u = (c*dx+s*dy)/rx
        v = (-s*dx+c*dy)/ry
        radius = u*u+v*v
        a = np.clip((1-radius)*min(rx*W,ry*H)*.7,0,1)*strength
        lighting = .72 + .30*np.sqrt(np.clip(1-radius,0,1)) - .10*v - .06*u
        rgb = np.asarray(color,dtype=np.float32)[None,None,:]*lighting[...,None]
        if shiny:
            glint = np.exp(-((u+.32)/.36)**2-((v+.36)/.25)**2)
            rgb += glint[...,None]*np.array([31,31,29],np.float32)
        rgb += fine[...,None]*.75
        a = cv2.GaussianBlur(a.astype(np.float32),(0,0),.23*scale)
        over(np.clip(rgb,0,255),a)

    def line(points, color, width, strength=1):
        im = Image.new('L',(W,H),0)
        draw = ImageDraw.Draw(im)
        draw.line([(float(x*W),float(y*H)) for x,y in points], fill=255, width=max(1,int(width*min(W,H))), joint='curve')
        a = cv2.GaussianBlur(np.asarray(im,dtype=np.float32)/255,(0,0),.25*scale)*strength
        over(np.asarray(color,dtype=np.float32),a)

    # Ground shadows multiply the existing grass instead of replacing its texture.
    shadow = np.zeros((H,W),np.float32)
    shadow += .19*np.exp(-(((X-.219)/.180)**2+((Y-.951)/.024)**2)*1.7)
    shadow += .08*np.exp(-(((X-.258)/.140)**2+((Y-.967)/.020)**2)*1.5)
    for cx,cy,rx in [(.131,.951,.029),(.163,.941,.023),(.281,.948,.026),(.307,.958,.029)]:
        shadow += .24*np.exp(-(((X-cx)/rx)**2+((Y-cy)/.007)**2)*1.5)
    shadow = np.clip(shadow,0,.43)
    native_shadow = cv2.resize(shadow,(w,h),interpolation=cv2.INTER_AREA)
    ground = source*(1-native_shadow[...,None]*np.array([.94,1.0,.97],np.float32))

    # Far hind leg.
    fur([('M',.125,.825),('C',.152,.823,.167,.846,.161,.866),('C',.156,.885,.144,.903,.145,.922),('L',.151,.935),('C',.165,.935,.176,.940,.176,.947),('C',.161,.951,.143,.950,.136,.945),('C',.132,.929,.129,.913,.129,.897),('C',.113,.874,.110,.844,.125,.825)], [153,101,47], 1.25)
    # Far front leg.
    fur([('M',.260,.816),('C',.279,.816,.287,.836,.281,.856),('L',.270,.917),('L',.272,.937),('C',.290,.939,.299,.944,.297,.951),('C',.283,.954,.266,.953,.257,.947),('C',.252,.923,.256,.894,.257,.871),('C',.251,.849,.250,.828,.260,.816)], [153,101,48], 1.52)
    # Tapered lifted tail.
    fur([('M',.111,.789),('C',.083,.787,.062,.764,.048,.742),('C',.039,.727,.031,.713,.022,.710),('C',.022,.727,.032,.750,.044,.768),('C',.057,.790,.078,.813,.104,.818),('C',.116,.816,.122,.799,.111,.789)], [187,133,67], .88)
    # Main torso, with a rounded back and tucked belly.
    fur([('M',.095,.766),('C',.127,.746,.175,.748,.215,.753),('C',.242,.752,.272,.758,.288,.778),('C',.306,.795,.310,.821,.296,.844),('C',.282,.863,.259,.866,.235,.856),('C',.210,.845,.182,.851,.160,.862),('C',.128,.870,.096,.855,.084,.831),('C',.073,.811,.077,.784,.095,.766)], [188,133,68], .12)
    # A subtly lighter shoulder and neck rising to the head.
    fur([('M',.245,.809),('C',.254,.783,.280,.757,.300,.744),('C',.310,.731,.312,.714,.326,.710),('C',.341,.713,.357,.731,.355,.752),('C',.350,.772,.335,.793,.326,.813),('C',.320,.835,.309,.849,.291,.853),('C',.270,.850,.252,.833,.245,.809)], [193,143,78], -.92)
    # Near rear leg includes the muscular thigh and bent hock.
    fur([('M',.106,.814),('C',.129,.807,.155,.825,.160,.846),('C',.163,.863,.149,.883,.134,.901),('C',.127,.913,.126,.928,.130,.938),('C',.140,.939,.154,.941,.159,.948),('C',.160,.956,.139,.958,.115,.954),('C',.105,.952,.104,.943,.105,.931),('C',.106,.913,.113,.896,.109,.883),('C',.097,.870,.088,.849,.091,.834),('C',.093,.825,.099,.819,.106,.814)], [183,128,62], 1.1)
    # Near foreleg and broad supporting paw.
    fur([('M',.279,.811),('C',.295,.807,.311,.822,.311,.841),('C',.310,.861,.302,.880,.301,.902),('L',.300,.938),('C',.303,.947,.320,.944,.329,.952),('C',.335,.959,.326,.964,.309,.964),('C',.298,.964,.285,.962,.282,.955),('C',.279,.942,.282,.918,.282,.900),('C',.280,.879,.269,.860,.268,.840),('C',.267,.827,.270,.817,.279,.811)], [198,145,78], 1.57)
    # Head and gently tapered muzzle.
    fur([('M',.311,.715),('C',.315,.702,.332,.693,.347,.699),('C',.364,.703,.377,.718,.380,.734),('C',.380,.743,.376,.748,.384,.751),('C',.394,.751,.409,.754,.414,.761),('C',.418,.769,.414,.780,.404,.785),('C',.394,.790,.383,.793,.374,.796),('C',.357,.797,.341,.791,.329,.783),('C',.313,.774,.305,.755,.307,.738),('C',.307,.728,.308,.721,.311,.715)], [200,148,84], -.12)
    # Creamier chin and soft fur around the muzzle.
    fur([('M',.359,.776),('C',.372,.779,.389,.777,.405,.778),('C',.405,.784,.393,.791,.380,.794),('C',.368,.799,.356,.793,.351,.786),('C',.350,.781,.353,.778,.359,.776)], [208,171,114], .12, .7)
    fur([('M',.374,.752),('C',.386,.751,.402,.754,.409,.759),('C',.410,.766,.405,.773,.393,.776),('C',.382,.779,.372,.776,.367,.770),('C',.364,.762,.367,.756,.374,.752)], [211,163,99], .05, .7)
    # Floppy ear, darker in its fold, with its lit outer surface.
    fur([('M',.324,.717),('C',.311,.720,.301,.737,.302,.756),('C',.302,.779,.311,.796,.326,.801),('C',.338,.802,.345,.788,.345,.771),('C',.347,.751,.345,.734,.335,.722),('C',.331,.719,.327,.717,.324,.717)], [153,98,43], 1.4)
    fur([('M',.320,.722),('C',.309,.730,.306,.746,.309,.763),('C',.312,.780,.319,.789,.327,.791),('C',.335,.787,.337,.774,.336,.758),('C',.335,.741,.332,.728,.320,.722)], [177,121,58], 1.4, .8)
    # Mouth, nose, and small eye details are kept proportional to the head.
    line([(.370,.779),(.382,.781),(.394,.777),(.404,.775)], [73,47,27], .0015, .85)
    line([(.371,.779),(.365,.785)], [100,66,35], .0010, .55)
    ellipse(.409,.765,.0103,.0100,[37,33,28],1,-.10,True)
    ellipse(.413,.768,.0032,.0030,[14,14,12],.9)
    ellipse(.4055,.7605,.0035,.0017,[114,108,94],.55,-.25)
    ellipse(.364,.733,.0061,.0041,[88,58,28],.95,-.1)
    ellipse(.365,.733,.0036,.0030,[27,23,17],1)
    ellipse(.3658,.7334,.0018,.0023,[89,61,28],.9)
    ellipse(.3663,.7331,.0010,.0018,[15,15,12],1)
    ellipse(.3638,.7318,.00115,.0010,[235,234,210],.9)
    line([(.358,.7285),(.363,.7275),(.368,.729)], [119,78,36], .0012, .55)
    # Whisker pores and a handful of very fine short whiskers.
    for px,py in [(.389,.768),(.385,.771),(.394,.769),(.390,.774)]:
        ellipse(px,py,.00075,.00065,[107,80,45],.5)
    for a,b in [((.390,.773),(.404,.779)),((.391,.770),(.406,.771)),((.385,.773),(.399,.783))]:
        line([a,b],[226,206,163],.00055,.38)
    # Subtle paw creases, rather than outlined feet.
    for pts in [[(.143,.948),(.144,.953)],[(.132,.949),(.132,.954)],[(.317,.955),(.318,.961)],[(.307,.955),(.307,.962)],[(.286,.946),(.287,.951)]]:
        line(pts,[116,81,43],.0010,.45)

    # Composite only the synthesized layer, keeping untouched source pixels intact.
    dog_rgb = cv2.resize(layer,(w,h),interpolation=cv2.INTER_AREA)
    dog_alpha = cv2.resize(opacity,(w,h),interpolation=cv2.INTER_AREA)
    result = ground*(1-dog_alpha[...,None]) + dog_rgb
    result = np.clip(np.rint(result),0,255).astype(np.uint8)
    return Image.fromarray(result,'RGB')
let the car be a sports car
magicbrush_train_181992_1 · replace / change · execution=passed
FAILinstr 2preserve 4quality 3
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The edit adds a sporty-looking rear bumper, diffuser, exhaust tips, and tail lights, but the vehicle still clearly appears to be the same open SUV/trunk rather than a sports car. Most unrelated cargo and interior content are preserved, and the added elements are fairly clean but somewhat mismatched in perspective and context.

l1=0.1475 · gain=-0.0084 · mask_l1=0.0195 · preserve_l1=0.1759

reasoning / plan
{
 "visual_evidence": [
  "The car is viewed from the rear with its hatch raised.",
  "Bags, boxes, and other luggage fill the cargo area behind a black mesh net.",
  "Dark exterior panels and the rear bumper are visible around and below the opening."
 ],
 "target_object": "The car's visible rear exterior",
 "target_region": "The exterior shoulders beside the cargo opening and the bumper beneath the loading sill",
 "editing_intent": "Give the car a sports-car rear appearance with sculpted metallic bodywork, slim red tail lights, a vented performance bumper, a rear diffuser, and four polished exhaust tips.",
 "editing_plan": [
  "Mask the visible lower bumper and narrow exterior shoulder panels without covering the luggage or mesh net.",
  "Synthesize curved, glossy dark-blue metallic bodywork using scene-derived brightness, smooth reflections, and fine grain.",
  "Add recessed slim tail lights with textured lenses and bright red internal strips.",
  "Construct a shaded central vent, carbon-textured diffuser, and perspective-aligned diffuser fins.",
  "Add four elliptical exhaust tips with metallic rims, dark interiors, and contact shadows.",
  "Feather the edited boundaries and preserve the raised hatch, cargo, loading sill, and surrounding scene."
 ],
 "preservation_constraints": [
  "Keep the luggage, bags, boxes, and cargo net unchanged.",
  "Keep the hatch open.",
  "Preserve the seats, cabin, and background visible through the car.",
  "Preserve the loading sill above the new bumper.",
  "Do not add wheels, people, logos, or objects outside the visible rear exterior."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image, ImageDraw

    w, h = image.size
    original = np.asarray(image.convert('RGB')).astype(np.float32)
    out = original.copy()
    yy, xx = np.mgrid[0:h, 0:w].astype(np.float32)
    u, v = xx / w, yy / h
    rng = np.random.default_rng(21)
    noise = rng.normal(0, 0.75, (h, w)).astype(np.float32)
    scale = 3
    changed = np.zeros((h, w), np.float32)

    def polygon(points):
        im = Image.new('L', (w * scale, h * scale), 0)
        ImageDraw.Draw(im).polygon([(int(x * w * scale), int(y * h * scale)) for x, y in points], fill=255)
        return np.asarray(im.resize((w, h), Image.Resampling.LANCZOS)).astype(np.float32) / 255.0

    def curve(start, segments):
        points = [start]
        a = np.asarray(start, np.float32)
        for b, c, d in segments:
            b, c, d = np.asarray(b), np.asarray(c), np.asarray(d)
            for t in np.linspace(0, 1, 30)[1:]:
                p = (1-t)**3*a + 3*(1-t)**2*t*b + 3*(1-t)*t*t*c + t**3*d
                points.append(tuple(p))
            a = d
        return polygon(points)

    def stroke(points, width):
        im = Image.new('L', (w * scale, h * scale), 0)
        ImageDraw.Draw(im).line([(int(x*w*scale), int(y*h*scale)) for x, y in points], fill=255, width=max(1, int(width*min(w,h)*scale)), joint='curve')
        return np.asarray(im.resize((w,h), Image.Resampling.LANCZOS)).astype(np.float32)/255.0

    def blend(color, mask, feather=0.0007):
        nonlocal out, changed
        mask = np.clip(mask, 0, 1).astype(np.float32)
        if feather > 0:
            mask = cv2.GaussianBlur(mask, (0,0), max(0.3, feather*min(w,h)))
        if np.ndim(color) == 1:
            color = np.asarray(color, np.float32)[None,None,:]
        out = out*(1-mask[...,None]) + np.clip(color,0,255)*mask[...,None]
        changed = np.maximum(changed, mask)

    bumper = curve((0.004,0.861), [
        ((0.019,0.881),(0.048,0.900),(0.132,0.899)),
        ((0.345,0.895),(0.689,0.885),(0.859,0.874)),
        ((0.940,0.868),(0.983,0.854),(1.000,0.848)),
        ((1.000,0.882),(1.000,0.925),(1.000,0.951)),
        ((0.827,0.979),(0.478,0.995),(0.216,0.993)),
        ((0.086,0.993),(0.024,0.973),(0.005,0.942)),
        ((0.001,0.915),(0.001,0.887),(0.004,0.861))])
    left = curve((0.005,0.624), [
        ((0.019,0.603),(0.028,0.602),(0.038,0.633)),
        ((0.046,0.675),(0.048,0.744),(0.064,0.788)),
        ((0.073,0.823),(0.093,0.858),(0.129,0.877)),
        ((0.156,0.889),(0.160,0.909),(0.138,0.923)),
        ((0.071,0.916),(0.028,0.892),(0.010,0.855)),
        ((0.001,0.804),(0.003,0.682),(0.005,0.624))])
    right = curve((1.000,0.632), [
        ((0.991,0.632),(0.988,0.653),(0.986,0.690)),
        ((0.982,0.756),(0.970,0.806),(0.945,0.833)),
        ((0.926,0.848),(0.899,0.857),(0.881,0.870)),
        ((0.889,0.886),(0.937,0.898),(0.974,0.889)),
        ((0.991,0.884),(0.998,0.864),(1.000,0.843)),
        ((1.000,0.783),(1.000,0.694),(1.000,0.632))])
    body = np.maximum(bumper, np.maximum(left, right))
    luminance = original @ np.array([0.299,0.587,0.114], np.float32)
    softlight = cv2.GaussianBlur(luminance, (0,0), max(1.0,0.011*w))
    t = (v-(0.895-0.019*u))/0.093
    top_reflect = np.exp(-((t-0.13)/0.12)**2)
    lower_reflect = np.exp(-((t-0.76)/0.075)**2)
    broad = np.exp(-((u-0.49)/0.47)**2)
    light = 11 + 32*top_reflect + 13*lower_reflect + 8*broad - 8*np.exp(-((t-0.43)/0.15)**2)
    light += 0.16*(softlight-cv2.GaussianBlur(softlight,(0,0),max(1.0,0.04*w)))
    paint = np.empty_like(original)
    paint[...,0] = 13 + light*0.68 + noise
    paint[...,1] = 24 + light*0.91 + noise
    paint[...,2] = 37 + light*1.12 + noise
    side_light = 15 + 35*np.exp(-((u-0.045)/0.019)**2) + 25*np.exp(-((u-0.979)/0.017)**2)
    side_rgb = np.stack([12+side_light*0.55+noise,22+side_light*0.74+noise,33+side_light*0.94+noise],axis=-1)
    sides = np.maximum(left,right)*(1-bumper)
    paint = paint*(1-sides[...,None])+side_rgb*sides[...,None]
    blend(paint,body,0.0012)

    # Reflected shoulder creases and a shaded seam below the original loading sill.
    seam = stroke([(0.073,0.883),(0.15,0.900),(0.35,0.897),(0.60,0.889),(0.82,0.878),(0.965,0.862)],0.003)
    blend([7,12,19],seam*body,0.0010)
    highlight = stroke([(0.078,0.887),(0.15,0.904),(0.35,0.901),(0.60,0.893),(0.82,0.882),(0.963,0.866)],0.0015)
    blend([101,116,128],highlight*body*0.47,0.0008)
    blend([82,100,117],stroke([(0.027,0.683),(0.035,0.754),(0.051,0.815),(0.077,0.853)],0.002)*left*0.40)
    blend([83,99,114],stroke([(0.995,0.694),(0.988,0.768),(0.971,0.815),(0.946,0.840)],0.002)*right*0.38)

    # Slim, recessed red tail lamps follow the rear bumper's perspective.
    lamp_left = curve((0.052,0.879), [
        ((0.096,0.886),(0.159,0.891),(0.246,0.889)),
        ((0.246,0.896),(0.241,0.908),(0.232,0.914)),
        ((0.156,0.916),(0.091,0.908),(0.064,0.898)),
        ((0.057,0.892),(0.053,0.884),(0.052,0.879))])
    lamp_right = curve((0.761,0.873), [
        ((0.831,0.870),(0.923,0.857),(0.981,0.845)),
        ((0.983,0.854),(0.978,0.866),(0.974,0.871)),
        ((0.913,0.885),(0.833,0.894),(0.775,0.895)),
        ((0.769,0.890),(0.765,0.880),(0.761,0.873))])
    lamps = np.maximum(lamp_left,lamp_right)*body
    blend([4,7,11],lamps,0.0008)
    kr = max(1,int(min(w,h)*0.003))
    kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(2*kr+1,2*kr+1))
    lenses = cv2.erode(lamps,kernel)
    ridges = 3*np.sin(u*w*2.1) + 2*np.sin(v*h*2.0)
    lenslight = 12*np.exp(-((v-(0.900-0.021*u))/0.009)**2)
    lensrgb = np.stack([68+lenslight+ridges+noise,5+0.10*lenslight+noise*0.4,10+0.13*lenslight+noise*0.4],axis=-1)
    blend(lensrgb,lenses,0.0004)
    tracks = [([(0.066,0.887),(0.099,0.894),(0.151,0.898),(0.227,0.898)],0.0045),
              ([(0.072,0.894),(0.104,0.900),(0.158,0.905),(0.226,0.906)],0.0025),
              ([(0.781,0.880),(0.838,0.877),(0.912,0.866),(0.968,0.854)],0.0045),
              ([(0.783,0.887),(0.839,0.884),(0.910,0.874),(0.966,0.862)],0.0025)]
    for pts, width in tracks:
        line = stroke(pts,width)*lenses
        blend([185,15,24],cv2.GaussianBlur(line,(0,0),max(0.4,w*0.0018))*0.48,0)
        blend([246,38,43],line,0.0004)
        blend([255,105,88],stroke(pts,width*0.25)*lenses*0.65,0.0003)
    blend([172,135,140],stroke([(0.068,0.883),(0.13,0.892),(0.221,0.892)],0.0012)*lenses*0.35)
    blend([174,136,141],stroke([(0.792,0.876),(0.873,0.870),(0.965,0.849)],0.0012)*lenses*0.35)

    # A deeply recessed center intake with individual shaded slats.
    vent = curve((0.266,0.917), [
        ((0.413,0.916),(0.660,0.906),(0.771,0.901)),
        ((0.771,0.911),(0.766,0.923),(0.755,0.930)),
        ((0.591,0.938),(0.393,0.945),(0.282,0.941)),
        ((0.276,0.934),(0.270,0.924),(0.266,0.917))]) * bumper
    blend([6,9,12],vent,0.0010)
    ventinner = cv2.erode(vent,kernel)
    mesh = (np.sin((u+v)*w*1.8)*np.sin((u-v)*w*1.8))
    ventrgb = np.stack([8+mesh*2+noise*0.45,11+mesh*2+noise*0.45,14+mesh*2+noise*0.45],axis=-1)
    blend(ventrgb,ventinner,0.0005)
    for x in np.linspace(0.295,0.745,20):
        top = 0.922-0.022*x
        bottom = 0.948-0.022*x
        blend([29,36,41],stroke([(x,top),(x-0.006,bottom)],0.0022)*ventinner,0.0004)
        blend([2,4,6],stroke([(x+0.003,top),(x-0.003,bottom)],0.0024)*ventinner,0.0004)
    blend([74,90,101],stroke([(0.289,0.916),(0.492,0.912),(0.754,0.902)],0.0012)*bumper*0.48)

    # Curved lower carbon diffuser; its restrained weave and grain keep it photographic.
    diffuser = curve((0.226,0.943), [
        ((0.368,0.951),(0.656,0.936),(0.790,0.926)),
        ((0.801,0.938),(0.807,0.951),(0.808,0.966)),
        ((0.648,0.986),(0.390,0.994),(0.238,0.981)),
        ((0.231,0.971),(0.227,0.954),(0.226,0.943))]) * bumper
    shadow = cv2.GaussianBlur(diffuser,(0,0),max(0.7,w*0.0028))
    blend([5,8,12],shadow*bumper*0.65,0)
    weave = 1.7*np.sin((xx+yy)*2.0)*np.sin((xx-yy)*1.7)
    difflight = 13 + 12*np.exp(-((v-(0.951-0.019*u))/0.009)**2)-5*np.clip((v-0.951)/0.03,0,1)
    diffrgb = np.stack([difflight+weave+noise*0.7,difflight+2+weave+noise*0.7,difflight+4+weave+noise*0.7],axis=-1)
    blend(diffrgb,diffuser,0.0008)
    for x in [0.30,0.40,0.50,0.60,0.70]:
        top = 0.946-0.020*x
        bottom = 0.993-0.020*x
        fin = polygon([(x-0.005,top),(x+0.003,top),(x+0.015,bottom-0.002),(x+0.002,bottom)])*diffuser
        blend([3,5,8],cv2.GaussianBlur(fin,(0,0),max(0.4,w*0.0015))*diffuser*0.7,0)
        finrgb = np.stack([9+6*np.clip((v-top)/(bottom-top),0,1)+noise*0.4,12+7*np.clip((v-top)/(bottom-top),0,1)+noise*0.4,16+8*np.clip((v-top)/(bottom-top),0,1)+noise*0.4],axis=-1)
        blend(finrgb,fin,0.0005)
        blend([62,70,77],stroke([(x-0.003,top+0.002),(x+0.004,bottom-0.002)],0.0014)*fin*0.6,0.0005)

    # Four real-looking exhaust mouths: contact recesses, curved chrome and dark bores.
    for cx, cy in [(0.117,0.952),(0.176,0.955),(0.844,0.944),(0.904,0.937)]:
        rx, ry = 0.025, 0.014
        ex = (u-cx)/rx
        ey = (v-cy+0.040*(u-cx))/ry
        distance = np.sqrt(ex*ex+ey*ey)
        recess = np.clip((1.31-distance)/0.075,0,1)*bumper
        blend([3,5,8],recess,0.0010)
        drop = np.sqrt(((u-cx)/rx)**2+((v-cy-0.004)/ry)**2)
        blend([2,4,6],np.clip((1.13-drop)/0.07,0,1)*bumper*0.75,0.0012)
        rim = np.clip((1.0-distance)/0.035,0,1)*bumper
        ang = np.arctan2(ey,ex)
        shine = 55 + 112*np.exp(-((ey+0.64)/0.24)**2) + 37*np.exp(-((ey-0.76)/0.15)**2)
        shine += 20*np.cos(ang-2.5) + noise*1.1
        chrome = np.stack([shine*0.91,shine*0.98+3,shine+8],axis=-1)
        blend(chrome,rim,0.0004)
        bore = np.clip((0.73-distance)/0.035,0,1)*bumper
        inside = 3+8*np.exp(-((ey-0.47)/0.20)**2)+noise*0.38
        blend(np.stack([inside,inside+1,inside+2],axis=-1),bore,0.0004)
        lip = np.exp(-((distance-0.92)/0.025)**2)*np.clip(-ey+0.2,0,1)*rim
        blend([207,215,221],lip*0.7,0.0003)
        lower_reflection = np.exp(-((distance-0.70)/0.025)**2)*np.clip(ey,0,1)*rim
        blend([77,86,94],lower_reflection*0.55,0.0004)

    # A subtle lower-edge reflection separates the redesigned body from the ground.
    lowerline = stroke([(0.040,0.966),(0.090,0.983),(0.202,0.989),(0.245,0.989)],0.0015)
    lowerline = np.maximum(lowerline,stroke([(0.815,0.974),(0.904,0.964),(0.985,0.951)],0.0015))
    blend([69,83,94],lowerline*bumper*0.38,0.0007)
    out = np.clip(out,0,255).astype(np.uint8)
    return Image.fromarray(out, 'RGB')
change the table for a dog
magicbrush_train_327726_1 · replace / change · execution=passed
PASSinstr 4preserve 4quality 3
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The coffee table has been removed and replaced with a dog in the intended area. Most unrelated room elements are preserved, though there are some visible red artifacts where the table was and the dog looks somewhat stylized/poorly integrated with the scene.

l1=0.0202 · gain=0.0045 · mask_l1=0.0067 · preserve_l1=0.0306

reasoning / plan
{
 "visual_evidence": [
  "A small light-colored table with black legs stands near the center foreground.",
  "The table is on a red rug in front of a dark sofa.",
  "A white chair with a red cushion is behind the table.",
  "The room has soft illumination, with a bright window area on the right."
 ],
 "target_object": "The small foreground table, including its tabletop contents and legs",
 "target_region": "The central area of the red rug between the white chair and the sofa",
 "editing_intent": "Replace the table with a seated, golden-brown dog, restoring the rug around it and adding textured fur, facial details, and a soft contact shadow.",
 "editing_plan": [
  "Mask the tabletop, objects on it, legs, and nearby table shadow.",
  "Remove the table and reconstruct the exposed rug using nearby rug texture and locally estimated color variation.",
  "Construct a seated dog using overlapping shaded, fur-textured anatomical shapes.",
  "Add eyes, nose, muzzle, paws, fine fur, and a soft shadow on the rug.",
  "Feather the replacement boundaries and preserve pixels outside the edited region."
 ],
 "preservation_constraints": [
  "Keep the sofa, cushions, white chair, bookshelves, lamps, and window unchanged outside natural dog occlusion.",
  "Preserve the red rug's boundary, color variation, and visible texture.",
  "Do not alter the foreground side table or its objects.",
  "Maintain the original image dimensions and room lighting."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    w, h = image.size
    original = np.asarray(image.convert('RGB')).astype(np.float32)
    W, H = w * 2, h * 2
    base = cv2.resize(original, (W, H), interpolation=cv2.INTER_CUBIC)
    yy, xx = np.mgrid[0:H, 0:W].astype(np.float32)
    X, Y = xx / W, yy / H
    rng = np.random.default_rng(1248)
    changed = np.zeros((H, W), np.float32)

    def polygon(points):
        m = np.zeros((H, W), np.uint8)
        pts = np.array([(round(x * W), round(y * H)) for x, y in points], np.int32)
        cv2.fillPoly(m, [pts], 255)
        return m

    def oval(cx, cy, rx, ry, angle=0):
        a = np.deg2rad(angle)
        dx, dy = X - cx, Y - cy
        u = (dx * np.cos(a) + dy * np.sin(a)) / rx
        v = (-dx * np.sin(a) + dy * np.cos(a)) / ry
        return u, v, np.sqrt(u * u + v * v)

    def blend(rgb, alpha):
        nonlocal base, changed
        alpha = np.clip(alpha, 0, 1).astype(np.float32)
        base = base * (1 - alpha[..., None]) + rgb * alpha[..., None]
        changed = 1 - (1 - changed) * (1 - alpha)

    # The mask follows the tabletop and each leg, rather than a rectangular crop.
    removal = polygon([(.219,.653),(.293,.592),(.430,.600),(.475,.626),
                       (.470,.668),(.400,.697),(.218,.680)])
    leg_shapes = [
        [(.215,.663),(.237,.675),(.221,.776),(.204,.778),(.209,.738)],
        [(.379,.674),(.398,.681),(.394,.752),(.385,.822),(.372,.824),(.375,.759)],
        [(.451,.636),(.470,.638),(.472,.724),(.459,.733),(.452,.728)]
    ]
    for pts in leg_shapes:
        removal = cv2.bitwise_or(removal, polygon(pts))
    _, _, sd = oval(.324,.761,.112,.044,-5)
    old_shadow = (sd < 1).astype(np.uint8) * 255
    old_shadow[X > .444] = 0
    removal = cv2.bitwise_or(removal, old_shadow)
    k = max(3, int(round(.006 * W)))
    removal = cv2.dilate(removal, np.ones((k,k), np.uint8))

    # Recover the rug with color-fit patch synthesis; use inpainting only for
    # the narrow boundary and any non-rug pixels exposed by removal.
    rug = polygon([(.286,.582),(.570,.632),(.430,.986),
                   (.000,.878),(.000,.782)])
    rug_safe = cv2.erode(rug, np.ones((max(3,int(.014*W)),)*2, np.uint8))
    sample = (rug_safe > 0) & (removal == 0)
    sample &= (X > .055) & (X < .439) & (Y > .645) & (Y < .904)
    # Reject furniture and non-red pixels from the photometric fit.
    sample &= (base[...,0] > base[...,1] * 1.65)
    sample &= (base[...,0] > base[...,2] * 1.5)
    sample &= (base[...,0] > 75)
    positions = np.flatnonzero(sample)
    if len(positions) > 14000:
        positions = rng.choice(positions, 14000, replace=False)
    xfit = X.ravel()[positions] - .3
    yfit = Y.ravel()[positions] - .75
    design = np.column_stack([np.ones_like(xfit), xfit, yfit,
                              xfit*xfit, xfit*yfit, yfit*yfit])
    values = base.reshape(-1,3)[positions]
    if len(positions) >= 30:
        keep = np.ones(len(positions), bool)
        for _ in range(3):
            coefficients = np.linalg.lstsq(design[keep], values[keep], rcond=None)[0]
            errors = np.linalg.norm(values - design @ coefficients, axis=1)
            keep = errors < max(14, np.percentile(errors, 87))
        dx, dy = X - .3, Y - .75
        colorfield = (coefficients[0] + dx[...,None]*coefficients[1]
                      + dy[...,None]*coefficients[2]
                      + (dx*dx)[...,None]*coefficients[3]
                      + (dx*dy)[...,None]*coefficients[4]
                      + (dy*dy)[...,None]*coefficients[5])
    else:
        donor_mean = base[int(.815*H):int(.875*H),int(.06*W):int(.18*W)].mean(axis=(0,1))
        colorfield = np.broadcast_to(donor_mean, (H,W,3)).copy()

    donor = base[int(.814*H):int(.881*H), int(.057*W):int(.181*W)].copy()
    donor_low = cv2.GaussianBlur(donor, (0,0), max(1,.005*W))
    donor_detail = donor - donor_low
    dh, dw = donor.shape[:2]
    # Mirrored sampling avoids hard seams between repetitions.
    ix = (np.arange(W) + int(.037*W)) % max(2,2*dw-2)
    iy = (np.arange(H) + int(.019*H)) % max(2,2*dh-2)
    ix = np.where(ix < dw, ix, 2*dw-2-ix)
    iy = np.where(iy < dh, iy, 2*dh-2-iy)
    texture = donor_detail[iy[:,None],ix[None,:]]
    low_noise = cv2.resize(rng.normal(0,1,(24,24)).astype(np.float32),
                          (W,H), interpolation=cv2.INTER_CUBIC)
    rug_fill = np.clip(colorfield + texture * .95 + low_noise[...,None]*1.2, 0,255)
    inpainted = cv2.inpaint(np.clip(base,0,255).astype(np.uint8), removal,
                           max(3,int(.01*W)), cv2.INPAINT_TELEA).astype(np.float32)
    reconstructed = inpainted.copy()
    inside_rug = rug > 0
    reconstructed[inside_rug] = rug_fill[inside_rug]
    removal_alpha = cv2.GaussianBlur(removal.astype(np.float32)/255,
                                    (0,0), max(.7,.0011*W))
    blend(reconstructed, removal_alpha)

    # A broad soft cast shadow and a smaller contact shadow sit on the rug.
    _, _, d = oval(.341,.812,.105,.029,-4)
    shadow = np.exp(-d*d*2.2) * .29
    _, _, d2 = oval(.346,.813,.068,.010,0)
    shadow += np.exp(-d2*d2*2.0) * .21
    shadow *= rug.astype(np.float32)/255
    shadow *= (X < .446).astype(np.float32)
    shadow = cv2.GaussianBlur(shadow,(0,0),max(1,.0025*W))
    blend(base * np.array([.58,.52,.53],np.float32), np.clip(shadow,0,.48))

    # Multiscale irregularities give the fur both fine grain and soft clumps.
    fine = rng.normal(0,1,(H,W)).astype(np.float32)
    medium = cv2.resize(rng.normal(0,1,(max(12,H//9),max(12,W//9))).astype(np.float32),
                        (W,H), interpolation=cv2.INTER_CUBIC)
    coarse = cv2.resize(rng.normal(0,1,(35,35)).astype(np.float32),
                        (W,H), interpolation=cv2.INTER_CUBIC)

    def part(cx,cy,rx,ry,angle,color,hairs=0,flow=88,fuzz=.018):
        u,v,d = oval(cx,cy,rx,ry,angle)
        edge_noise = fuzz*(medium*.65 + fine*.25)
        alpha = np.clip((1 + edge_noise - d)/max(.009,fuzz),0,1)
        alpha = cv2.GaussianBlur(alpha,(0,0),max(.35,.00055*W))
        # Diffuse window light comes from above and to the right.
        light = .98 + .14*u - .15*v - .19*np.maximum(d-.56,0)
        light += .055*np.exp(-((u-.30)**2+(v+.32)**2)*3)
        light = np.clip(light,.63,1.19)
        col = np.asarray(color,np.float32)
        rgb = light[...,None]*col
        rgb += (medium*2.1 + coarse*2.0 + fine*1.45)[...,None]
        rgb[...,0] += np.maximum(v,0)*2.5
        if hairs:
            hair_rgb = np.zeros((H,W,3),np.float32)
            hair_a = np.zeros((H,W),np.uint8)
            theta = np.deg2rad(angle)
            for _ in range(hairs):
                az = rng.uniform(0,2*np.pi)
                rr = np.sqrt(rng.uniform(0,.985))
                uu, vv = rr*np.cos(az), rr*np.sin(az)
                px = cx + rx*uu*np.cos(theta) - ry*vv*np.sin(theta)
                py = cy + rx*uu*np.sin(theta) + ry*vv*np.cos(theta)
                direction = np.deg2rad(flow + rng.normal(0,17) + uu*12)
                length = rng.uniform(.0024,.0090) * H
                p = (int(px*W),int(py*H))
                q = (int(p[0]+np.cos(direction)*length),
                     int(p[1]+np.sin(direction)*length))
                l = float(np.clip(.98+.14*uu-.15*vv-.19*max(rr-.56,0),.63,1.19))
                hc = col*l + rng.normal(0,15) + np.array([5,3,0])
                hc = tuple(float(z) for z in np.clip(hc,0,255))
                thickness = max(1,int(round(W*rng.uniform(.00035,.0008))))
                opacity = int(rng.integers(45,125))
                cv2.line(hair_rgb,p,q,hc,thickness,cv2.LINE_AA)
                cv2.line(hair_a,p,q,opacity,thickness,cv2.LINE_AA)
            ha = hair_a.astype(np.float32)/255
            rgb = rgb*(1-ha[...,None]) + hair_rgb*ha[...,None]
        blend(np.clip(rgb,0,255),alpha)

    # Rear anatomy first: tail, haunch, torso, and the dark far leg.
    part(.397,.782,.045,.016,-15,(151,105,57),380,175)
    part(.400,.768,.037,.043,-13,(169,119,64),620,95)
    part(.366,.702,.052,.095,-12,(176,125,70),1400,100)
    part(.373,.761,.038,.052,-12,(182,130,74),650,112)
    part(.359,.772,.016,.039,2,(145,99,52),240,88)
    part(.366,.804,.025,.014,0,(160,113,65),260,15)

    # Neck and chest overlap the torso, with longer pale chest fur.
    part(.324,.663,.036,.053,-12,(189,141,83),600,88)
    part(.320,.711,.040,.074,-8,(195,148,93),950,94)
    part(.315,.697,.026,.056,-5,(213,169,111),520,92)
    part(.301,.766,.016,.044,-4,(194,147,88),420,89)
    part(.342,.767,.016,.044,-3,(201,156,98),420,87)
    part(.299,.808,.027,.016,0,(202,157,101),350,14)
    part(.343,.808,.025,.015,-3,(207,162,104),350,12)

    # Floppy ears, skull, cheeks and a short, rounded muzzle.
    part(.253,.593,.018,.045,-18,(132,87,45),520,110)
    part(.344,.596,.020,.047,-4,(155,104,52),540,93)
    part(.297,.589,.046,.051,-6,(191,139,78),1000,94)
    part(.267,.612,.023,.029,-20,(174,121,66),420,119)
    part(.326,.610,.024,.031,10,(199,147,85),450,65)
    part(.291,.637,.029,.022,0,(181,131,76),280,95)
    part(.280,.625,.021,.018,-12,(220,178,121),340,126)
    part(.307,.624,.022,.018,10,(224,182,125),340,48)
    part(.295,.645,.022,.012,0,(192,148,96),230,87)

    # Brows and small dark eyes are embedded in the coat rather than outlined.
    part(.278,.588,.016,.010,-9,(164,110,54),150,12,.011)
    part(.317,.585,.015,.010,8,(176,121,62),150,165,.011)
    part(.278,.592,.0090,.0068,-10,(65,43,26),0,0,.008)
    part(.317,.589,.0090,.0068,7,(66,44,25),0,0,.008)
    part(.279,.592,.0048,.0052,0,(28,23,18),0,0,.006)
    part(.316,.589,.0048,.0051,0,(28,23,17),0,0,.006)
    part(.281,.590,.0017,.0015,0,(226,218,196),0,0,.005)
    part(.318,.587,.0016,.0014,0,(235,227,207),0,0,.005)

    # The nose has a curved, mottled surface and subdued window reflections.
    part(.295,.619,.013,.0095,-3,(48,39,31),0,0,.008)
    part(.291,.616,.0067,.0030,-9,(84,77,68),0,0,.006)
    part(.285,.621,.0034,.0023,-15,(22,19,16),0,0,.005)
    part(.304,.620,.0032,.0022,12,(22,19,16),0,0,.005)
    part(.293,.614,.0025,.0009,-8,(148,137,117),0,0,.004)

    def detail_curve(points,color,width,opacity=.65):
        layer = np.zeros((H,W,3),np.float32)
        a = np.zeros((H,W),np.uint8)
        pts = np.array([(int(x*W),int(y*H)) for x,y in points],np.int32)
        t = max(1,int(width*W))
        cv2.polylines(layer,[pts],False,tuple(float(v) for v in color),t,cv2.LINE_AA)
        cv2.polylines(a,[pts],False,255,t,cv2.LINE_AA)
        aa = cv2.GaussianBlur(a.astype(np.float32)/255,(0,0),max(.3,.00045*W))*opacity
        # A premultiplied blur keeps fine dark lines from acquiring a black halo.
        blurred = cv2.GaussianBlur(layer,(0,0),max(.3,.00045*W))
        norm = cv2.GaussianBlur(a.astype(np.float32)/255,(0,0),max(.3,.00045*W))
        rgb = blurred / np.maximum(norm[...,None],1e-5)
        blend(rgb,aa)

    detail_curve([(.295,.626),(.295,.632),(.288,.635),(.279,.633)],(74,49,32),.0016,.70)
    detail_curve([(.295,.632),(.303,.635),(.314,.631)],(78,51,33),.0015,.65)
    # Small toe divisions, softened into the surrounding paw fur.
    for x in [.288,.302,.333,.347]:
        detail_curve([(x,.807),(x-.001,.815)],(137,94,52),.0011,.42)
    # Restrained whiskers catch light without becoming graphic white lines.
    for side in [-1,1]:
        for j in range(4):
            x0 = .295 + side*(.015+rng.uniform(0,.004))
            y0 = .627 + j*.0024
            detail_curve([(x0,y0),(x0+side*.013,y0-.002),
                          (x0+side*.023,y0-.003+rng.uniform(-.002,.002))],
                         (218,185,141),.00065,.26)

    # Downsample only the edited area so every distant source pixel is retained.
    result = cv2.resize(np.clip(base,0,255),(w,h),interpolation=cv2.INTER_AREA)
    coverage = cv2.resize(changed,(w,h),interpolation=cv2.INTER_AREA)
    coverage = np.clip(coverage,0,1)
    final = original*(1-coverage[...,None]) + result*coverage[...,None]
    return Image.fromarray(np.clip(np.rint(final),0,255).astype(np.uint8), 'RGB')
make the airplane a toy airplane
magicbrush_train_166761_2 · replace / change · execution=passed
PASSinstr 5preserve 4quality 4
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The airplane has been clearly transformed into a colorful toy-like plane with simplified plastic-looking shapes and bright colors. The background, water, pier, and buildings are mostly preserved, with changes localized primarily to the airplane. Visual quality is good overall, though there are some integration artifacts and slight unnatural geometry/blur around the wings and landing gear.

l1=0.0680 · gain=0.0004 · mask_l1=0.0013 · preserve_l1=0.1689

reasoning / plan
{
 "visual_evidence": [
  "A silver airplane fills the center of the image, with wings extending to both edges.",
  "The airplane has a red nose, a blurred propeller, a transparent canopy, and a red tail.",
  "Two prominent black landing wheels hang below the wings.",
  "Hangars, trees, and a striped foreground barrier surround the airplane."
 ],
 "target_object": "The airplane",
 "target_region": "The airplane silhouette, including its fuselage, wings, propeller, tail, canopy, and landing wheels.",
 "editing_intent": "Turn the airplane into a brightly colored molded-plastic toy while retaining its position, orientation, recognizable shape, and scene lighting.",
 "editing_plan": [
  "Mask the individual airplane components using their visible outlines.",
  "Remove the blurred propeller streaks and existing fuselage markings using local inpainting.",
  "Give the fuselage a glossy yellow plastic finish, the wings a blue plastic finish, and the nose and tail a red plastic finish.",
  "Construct solid, rounded toy propeller blades with shaded surfaces and yellow tips.",
  "Add restrained molded seams, a toy-style fuselage decal, and rounded plastic wheel hubs.",
  "Feather all edited boundaries and preserve the surrounding scenery."
 ],
 "preservation_constraints": [
  "Keep the hangars, trees, sky, and foreground barrier unchanged outside the propeller cleanup mask.",
  "Preserve the airplane's overall position and perspective.",
  "Keep the canopy recognizable and retain the landing-gear arrangement.",
  "Retain directional shading and the dark undersides of the airplane."
 ]
}
pixel code
def edit(image):
    import cv2
    import numpy as np
    from PIL import Image
    import math

    w, h = image.size
    s = min(w, h)
    original = np.asarray(image.convert('RGB')).copy()
    rng = np.random.default_rng(17)

    def polygon(points):
        m = np.zeros((h, w), np.uint8)
        p = np.array([(round(x*w), round(y*h)) for x, y in points], np.int32)
        cv2.fillPoly(m, [p], 255, lineType=cv2.LINE_AA)
        return m

    def ellipse(cx, cy, rx, ry, angle=0):
        m = np.zeros((h, w), np.uint8)
        cv2.ellipse(m, (round(cx*w), round(cy*h)),
                    (max(1, round(rx*w)), max(1, round(ry*h))),
                    angle, 0, 360, 255, -1, cv2.LINE_AA)
        return m

    def feather(m, amount=0.0011):
        return cv2.GaussianBlur(m.astype(np.float32)/255.0, (0, 0), max(0.35, amount*s))

    def blend(canvas, layer, mask, amount=1.0):
        a = feather(mask)[..., None]*amount
        return canvas*(1-a) + np.asarray(layer, np.float32)*a

    # Remove only the original motion-blurred propeller streaks.
    prop_cleanup = np.maximum.reduce([
        polygon([(0.281,0.280),(0.318,0.271),(0.346,0.365),(0.356,0.444),(0.332,0.453),(0.301,0.372)]),
        polygon([(0.379,0.434),(0.519,0.371),(0.539,0.416),(0.421,0.473)]),
        polygon([(0.165,0.515),(0.299,0.469),(0.329,0.491),(0.193,0.567),(0.173,0.558)])
    ])
    cleaned = cv2.inpaint(original, prop_cleanup, max(3, round(s*0.022)), cv2.INPAINT_TELEA)
    noise = rng.normal(0, 0.55, (h,w,1)).astype(np.float32)
    canvas = blend(original.astype(np.float32), cleaned.astype(np.float32)+noise, prop_cleanup)

    body = polygon([(0.370,0.444),(0.475,0.454),(0.527,0.477),(0.589,0.494),
                    (0.643,0.526),(0.722,0.585),(0.775,0.606),(0.858,0.600),
                    (0.904,0.622),(0.899,0.677),(0.858,0.709),(0.767,0.696),
                    (0.646,0.682),(0.552,0.653),(0.467,0.624),(0.411,0.587),
                    (0.379,0.550),(0.348,0.501)])
    left_wing = polygon([(0,0.568),(0.152,0.574),(0.238,0.583),(0.327,0.600),
                         (0.440,0.618),(0.573,0.641),(0.563,0.654),(0.470,0.654),
                         (0.337,0.634),(0.183,0.614),(0.061,0.596),(0,0.591)])
    right_wing = polygon([(0.451,0.642),(0.598,0.608),(0.697,0.596),(0.796,0.585),
                          (0.905,0.578),(1,0.574),(1,0.651),(0.869,0.653),
                          (0.771,0.667),(0.623,0.677),(0.530,0.674)])
    tail_top = polygon([(0.828,0.582),(0.858,0.498),(0.877,0.495),(0.899,0.514),
                        (0.906,0.550),(0.900,0.580),(0.901,0.606)])
    tail_bottom = polygon([(0.849,0.652),(0.900,0.654),(0.904,0.700),
                           (0.895,0.721),(0.865,0.720),(0.846,0.688)])
    canopy = polygon([(0.525,0.468),(0.549,0.461),(0.569,0.472),(0.588,0.491),
                      (0.609,0.502),(0.638,0.520),(0.658,0.541),(0.662,0.554),
                      (0.633,0.549),(0.596,0.532),(0.562,0.510),(0.538,0.493)])
    spinner = polygon([(0.314,0.455),(0.327,0.441),(0.352,0.433),(0.386,0.437),
                       (0.407,0.455),(0.419,0.482),(0.414,0.509),(0.396,0.536),
                       (0.374,0.544),(0.349,0.524),(0.328,0.493),(0.312,0.473)])

    # Remove lettering rather than leaving realistic aircraft markings in the plastic.
    lettering = np.maximum(
        polygon([(0.432,0.499),(0.493,0.500),(0.568,0.535),(0.590,0.577),
                 (0.495,0.582),(0.437,0.547)]),
        polygon([(0.628,0.551),(0.696,0.573),(0.710,0.613),(0.635,0.603)])
    )
    lettering = cv2.bitwise_and(lettering, body)
    lettering = cv2.bitwise_and(lettering, cv2.bitwise_not(canopy))
    smooth_source = cv2.inpaint(original, lettering, max(3, round(s*0.015)), cv2.INPAINT_TELEA)
    smooth_source = cv2.bilateralFilter(smooth_source, 9, 55, max(3, s*0.013)).astype(np.float32)
    yy, xx = np.mgrid[0:h, 0:w].astype(np.float32)
    X, Y = xx/w, yy/h
    luminance = (0.2126*smooth_source[...,0] + 0.7152*smooth_source[...,1] + 0.0722*smooth_source[...,2])/255
    luminance = cv2.GaussianBlur(luminance, (0,0), max(0.7,s*0.003))
    fine_noise = rng.normal(0,0.45,(h,w,1)).astype(np.float32)

    def plastic(mask, color, lightness=0.0, gloss=None):
        nonlocal canvas
        illumination = np.clip(0.34 + 0.77*luminance + lightness, 0.27, 1.12)
        layer = illumination[...,None]*np.array(color,np.float32)
        if gloss is not None:
            cx,cy,rx,ry,amp = gloss
            g = np.exp(-((X-cx)/rx)**2-((Y-cy)/ry)**2)*amp
            layer += g[...,None]*np.array([1.0,1.0,0.94],np.float32)
        layer += fine_noise
        canvas = blend(canvas, np.clip(layer,0,255), mask)

    plastic(tail_top, (243,49,42), 0.04, (0.862,0.532,0.012,0.046,42))
    plastic(tail_bottom, (230,39,35), -0.02, (0.870,0.678,0.015,0.022,28))
    plastic(body, (255,199,35), 0.01, (0.515,0.522,0.115,0.023,48))
    plastic(left_wing, (31,132,228), 0.06, (0.236,0.589,0.27,0.008,45))
    plastic(right_wing, (28,128,230), 0.02, (0.818,0.597,0.21,0.009,65))

    # Reuse the canopy structure as a translucent blue toy cockpit.
    glass = original.astype(np.float32)*np.array([0.68,0.87,1.02],np.float32)
    glass += np.array([9,13,19],np.float32)
    canvas = blend(canvas, np.clip(glass,0,255), canopy)

    airplane_mask = np.maximum.reduce([body,left_wing,right_wing,tail_top,tail_bottom])

    def seam(points, color, width=0.0016, opacity=0.4):
        nonlocal canvas
        m = np.zeros((h,w),np.uint8)
        pts = np.array([(round(x*w),round(y*h)) for x,y in points],np.int32)
        cv2.polylines(m,[pts],False,255,max(1,round(width*s)),cv2.LINE_AA)
        m = cv2.bitwise_and(m,airplane_mask)
        canvas = blend(canvas,np.array(color,np.float32),m,opacity)

    # Fine molded joints, with a nearby light lip rather than drawn outlines.
    seam([(0.423,0.481),(0.425,0.525),(0.447,0.570),(0.470,0.606)], (123,84,14), 0.002,0.42)
    seam([(0.426,0.480),(0.429,0.522),(0.451,0.565),(0.474,0.603)], (255,239,137),0.0014,0.65)
    seam([(0.072,0.584),(0.189,0.596),(0.328,0.615)],(137,211,255),0.002,0.5)
    seam([(0.706,0.623),(0.839,0.610),(0.978,0.604)],(147,219,255),0.002,0.52)
    seam([(0.714,0.646),(0.843,0.637),(0.972,0.634)],(11,60,122),0.0013,0.35)

    # A small glossy inset decal on the fuselage.
    badge = ellipse(0.515,0.556,0.025,0.027,-22)
    badge = cv2.bitwise_and(badge,body)
    badge_layer = np.stack([230+12*luminance,233+12*luminance,221+16*luminance],axis=-1)
    canvas = blend(canvas,badge_layer,badge)
    star_points = []
    for i in range(10):
        a = -math.pi/2+i*math.pi/5
        r = 0.018 if i%2 == 0 else 0.0078
        star_points.append((0.515+r*math.cos(a),0.556+r*math.sin(a)))
    star = cv2.bitwise_and(polygon(star_points),badge)
    canvas = blend(canvas,np.array([25,105,207],np.float32),star,0.95)

    # Solid rounded blades replace the photographic motion blur.
    def toy_blade(tip):
        nonlocal canvas
        cx,cy = 0.363,0.477
        dx,dy = tip[0]-cx,tip[1]-cy
        length = math.hypot(dx,dy)
        ux,uy = dx/length,dy/length
        vx,vy = -uy,ux
        bx,by = cx+ux*0.015,cy+uy*0.015
        ex,ey = tip
        bwidth,ewidth = 0.009,0.014
        m = polygon([(bx+vx*bwidth,by+vy*bwidth),(ex+vx*ewidth,ey+vy*ewidth),
                     (ex-vx*ewidth,ey-vy*ewidth),(bx-vx*bwidth,by-vy*bwidth)])
        m = np.maximum(m,ellipse(ex,ey,ewidth,ewidth))
        m = np.maximum(m,ellipse(bx,by,bwidth,bwidth))
        along = ((X-cx)*ux+(Y-cy)*uy)/length
        cross = ((X-cx)*vx+(Y-cy)*vy)/ewidth
        roundness = np.sqrt(np.clip(1-cross*cross,0,1))
        shading = np.clip(0.57+0.35*roundness-0.08*cross+0.05*along,0.4,1.1)
        layer = shading[...,None]*np.array([27,98,207],np.float32)
        highlight = np.exp(-((cross+0.34)/0.20)**2)*18
        layer += highlight[...,None]
        tip_area = np.clip((along-0.83)/0.025,0,1)[...,None]
        yellow = shading[...,None]*np.array([255,202,43],np.float32)+highlight[...,None]
        layer = layer*(1-tip_area)+yellow*tip_area+fine_noise
        canvas = blend(canvas,np.clip(layer,0,255),m)

    toy_blade((0.306,0.297))
    toy_blade((0.514,0.401))
    toy_blade((0.188,0.539))
    toy_blade((0.405,0.613))
    plastic(spinner,(250,42,37),0.015,(0.349,0.454,0.027,0.013,82))
    # Rounded molded center cap on the spinner.
    cap = ellipse(0.342,0.467,0.011,0.016,-20)
    cap_shade = np.clip(0.79-4*(X-0.338)-3*(Y-0.460),0.55,1.12)
    canvas = blend(canvas,cap_shade[...,None]*np.array([240,54,43],np.float32),cap,0.87)

    # Retain the original struts, but give the wheels simple solid toy hubs.
    def toy_wheel(cx,cy,rx,ry):
        nonlocal canvas
        tire = ellipse(cx,cy,rx,ry,12)
        u=(X-cx)/rx
        v=(Y-cy)/ry
        rr=np.sqrt(u*u+v*v)
        rimlight=np.exp(-((rr-0.77)/0.17)**2)*13
        light=np.clip(1-0.16*u-0.22*v,0.6,1.4)
        tire_layer=np.stack([24*light+rimlight,29*light+rimlight,34*light+rimlight],axis=-1)
        canvas=blend(canvas,tire_layer+fine_noise,tire)
        hub=ellipse(cx-0.001,cy-0.001,rx*0.47,ry*0.48,12)
        hub_light=np.clip(0.9-0.21*u-0.20*v,0.48,1.3)
        hub_layer=hub_light[...,None]*np.array([43,144,233],np.float32)
        hub_layer += np.exp(-((u+0.16)/0.20)**2-((v+0.23)/0.23)**2)[...,None]*52
        canvas=blend(canvas,hub_layer,hub)
        axle=ellipse(cx-0.002,cy-0.002,rx*0.16,ry*0.17,12)
        canvas=blend(canvas,hub_light[...,None]*np.array([248,193,43],np.float32),axle)

    toy_wheel(0.274,0.721,0.025,0.043)
    toy_wheel(0.662,0.733,0.024,0.041)
    toy_wheel(0.765,0.761,0.012,0.020)

    return Image.fromarray(np.uint8(np.clip(canvas,0,255)), 'RGB')
remove the microwave and stove and put a refrigerator in it's place
magicbrush_train_10909_1 · add / insert · execution=passed
PASSinstr 4preserve 4quality 3
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The microwave and stove were removed and replaced with a refrigerator in the correct central area. Most unrelated kitchen elements are preserved, though some nearby countertop items are covered/removed. The refrigerator looks somewhat pasted in, flat, and imperfectly scaled/realistic, but the intended edit is clear.

l1=0.1027 · gain=-0.0336 · mask_l1=0.0081 · preserve_l1=0.1893

reasoning / plan
{
 "visual_evidence": [
  "A black microwave occupies the central opening beneath the wooden upper cabinets.",
  "A black stove is directly below the microwave and extends beyond the bottom of the image.",
  "A kettle sits on the stove.",
  "The kitchen has warm lighting, wooden cabinets, and a utensil holder immediately to the right of the stove."
 ],
 "target_object": "The microwave and stove, including the kettle resting on the stove",
 "target_region": "The central appliance opening, below the small upper cabinets and extending to the bottom edge",
 "editing_intent": "Replace both appliances with a stainless-steel refrigerator whose lower portion continues beyond the image, retaining the surrounding kitchen and foreground utensils.",
 "editing_plan": [
  "Mask the existing microwave and stove within the central appliance opening.",
  "Inpaint the narrow background areas needed around the replacement silhouette.",
  "Construct a refrigerator with separate freezer and refrigerator doors, a narrow side panel, recessed seams, and raised metal handles.",
  "Add warm metallic reflections, brushed texture, edge shading, and a soft cast shadow.",
  "Restore the foreground utensils and feather the replacement into the original image."
 ],
 "preservation_constraints": [
  "Preserve the wooden upper cabinets and the miniature village display above them.",
  "Preserve the ceiling, left wall decorations, and surrounding cabinetry.",
  "Preserve the coffee maker and countertop outside the replacement footprint.",
  "Keep the utensil holder and visible utensils in front of the refrigerator."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image, ImageDraw

    image = image.convert('RGB')
    w, h = image.size
    original = np.asarray(image).copy()
    W, H = w * 2, h * 2
    rng = np.random.default_rng(24)

    def rectangle_mask(box, width=w, height=h):
        m = np.zeros((height, width), np.uint8)
        x0, y0, x1, y1 = box
        cv2.rectangle(m, (int(x0 * width), int(y0 * height)),
                      (int(x1 * width), min(height - 1, int(y1 * height))), 255, -1)
        return m

    repair = rectangle_mask((0.273, 0.496, 0.735, 1.0))
    repaired = cv2.inpaint(original, repair, max(2, int(w * 0.006)), cv2.INPAINT_TELEA)
    canvas = cv2.resize(repaired, (W, H), interpolation=cv2.INTER_CUBIC).astype(np.float32)
    source = cv2.resize(original, (W, H), interpolation=cv2.INTER_CUBIC).astype(np.float32)
    yy, xx = np.mgrid[0:H, 0:W].astype(np.float32)
    X, Y = xx / W, yy / H

    def rounded(box, radius=0.006, feather=0.0006):
        m = Image.new('L', (W, H), 0)
        d = ImageDraw.Draw(m)
        a, b, c, e = box
        d.rounded_rectangle((int(a * W), int(b * H), int(c * W), int(e * H)),
                            radius=max(1, int(radius * W)), fill=255)
        arr = np.asarray(m).astype(np.float32) / 255.0
        if feather > 0:
            arr = cv2.GaussianBlur(arr, (0, 0), max(0.3, feather * W))
        return arr

    def polygon(points, feather=0.0005):
        m = np.zeros((H, W), np.uint8)
        pts = np.array([(int(a * W), int(b * H)) for a, b in points], np.int32)
        cv2.fillPoly(m, [pts], 255)
        arr = m.astype(np.float32) / 255.0
        return cv2.GaussianBlur(arr, (0, 0), max(0.3, feather * W)) if feather else arr

    def paint(mask, color):
        nonlocal canvas
        col = np.asarray(color, np.float32)
        canvas = canvas * (1 - mask[..., None]) + col * mask[..., None]

    def shifted(mask, dx, dy):
        transform = np.float32([[1, 0, dx * W], [0, 1, dy * H]])
        return cv2.warpAffine(mask, transform, (W, H), flags=cv2.INTER_LINEAR)

    body = rounded((0.273, 0.496, 0.735, 1.12), 0.006)
    shadow = cv2.GaussianBlur(shifted(body, 0.004, 0.003), (0, 0), W * 0.0035)
    shadow *= (Y >= 0.496).astype(np.float32)
    canvas *= (1 - 0.29 * shadow[..., None])

    fine = rng.normal(0, 1.0, (H, W)).astype(np.float32)
    brushed = cv2.GaussianBlur(rng.normal(0, 1, (H, W)).astype(np.float32),
                               (0, 0), sigmaX=W * 0.012, sigmaY=0.45)
    brushed /= max(float(brushed.std()), 0.001)
    grain = 0.75 * fine + 0.85 * brushed
    shell_lum = 61 + 10 * np.exp(-((X - 0.28) / 0.018) ** 2) + grain
    shell = np.stack([shell_lum * 1.04, shell_lum, shell_lum * 0.94], axis=-1)
    paint(body, shell)

    side = polygon([(0.718, 0.499), (0.735, 0.503), (0.735, 1.12), (0.718, 1.12)]) * body
    side_lum = 92 - 27 * np.clip((X - 0.718) / 0.017, 0, 1)
    side_lum += 7 * np.exp(-((X - 0.722) / 0.0025) ** 2) + grain
    side_rgb = np.stack([side_lum * 1.025, side_lum, side_lum * 0.96], axis=-1)
    paint(side, side_rgb)

    u = np.clip((X - 0.280) / 0.438, 0, 1)
    luminance = 173 - 26 * u - 10 * np.clip((Y - 0.5) / 0.65, 0, 1)
    luminance += 25 * np.exp(-((X - 0.305) / 0.038) ** 2)
    luminance -= 17 * np.exp(-((X - 0.485) / 0.057) ** 2)
    luminance += 10 * np.exp(-((X - 0.642) / 0.040) ** 2)
    luminance += 3 * np.sin(Y * 13) + grain
    warm_left = np.exp(-((X - 0.287) / 0.065) ** 2)
    metal = np.stack([luminance * 1.035 + 5 * warm_left,
                      luminance * 1.008 + 1.5 * warm_left,
                      luminance * 0.958 - 4 * warm_left], axis=-1)

    def door(box):
        x0, y0, x1, y1 = box
        mask = rounded(box, 0.007, 0.0005)
        edge = 14 * np.exp(-((X - (x0 + 0.003)) / 0.0022) ** 2)
        edge += 15 * np.exp(-((Y - (y0 + 0.003)) / 0.0018) ** 2)
        edge -= 22 * np.exp(-((X - (x1 - 0.002)) / 0.0024) ** 2)
        edge -= 15 * np.exp(-((Y - (y1 - 0.002)) / 0.0018) ** 2)
        paint(mask, np.clip(metal + edge[..., None], 0, 255))
        return mask

    door((0.280, 0.505, 0.718, 0.700))
    door((0.280, 0.710, 0.718, 1.12))

    seam = rounded((0.284, 0.702, 0.713, 0.708), 0.002, 0.0005)
    seam_lum = 39 + 7 * u + grain * 0.5
    paint(seam, np.stack([seam_lum * 1.04, seam_lum, seam_lum * 0.95], axis=-1))
    seam_highlight = rounded((0.288, 0.708, 0.710, 0.710), 0.001, 0.0004)
    paint(seam_highlight, [164, 162, 153])

    top_lip = polygon([(0.278, 0.500), (0.717, 0.500), (0.730, 0.504), (0.283, 0.506)])
    lip_lum = 115 + 36 * (1 - u) + grain
    paint(top_lip, np.stack([lip_lum * 1.045, lip_lum, lip_lum * 0.95], axis=-1))

    def handle(y0, y1):
        x0, x1 = 0.309, 0.322
        bar = rounded((x0, y0, x1, y1), 0.006, 0.00055)
        mount_a = rounded((0.309, y0 + 0.005, 0.330, y0 + 0.021), 0.003)
        mount_b = rounded((0.309, y1 - 0.021, 0.330, y1 - 0.005), 0.003)
        combined = np.maximum(bar, np.maximum(mount_a, mount_b))
        cast = cv2.GaussianBlur(shifted(combined, 0.005, 0.002), (0, 0), W * 0.0025)
        canvas_before = canvas.copy()
        paint(cast * 0.38, [44, 43, 39])
        mount_lum = 104 + 55 * np.exp(-((X - 0.315) / 0.005) ** 2) + grain
        paint(np.maximum(mount_a, mount_b), np.stack([mount_lum * 1.03, mount_lum, mount_lum * 0.95], -1))
        q = np.clip((X - x0) / (x1 - x0), 0, 1)
        cylindrical = 128 + 91 * np.exp(-((q - 0.32) / 0.24) ** 2) - 31 * q
        cylindrical += 10 * np.exp(-((Y - y0 - 0.005) / 0.004) ** 2)
        cylindrical += grain * 0.65
        rgb = np.stack([cylindrical * 1.025, cylindrical * 1.005, cylindrical * 0.958], axis=-1)
        paint(bar, rgb)
        glint = rounded((0.311, y0 + 0.009, 0.313, y1 - 0.008), 0.001, 0.0006)
        paint(glint * 0.43, [235, 232, 220])

    handle(0.550, 0.663)
    handle(0.754, 0.956)

    # These objects sit in front of the appliance opening and must remain visible.
    foreground = np.zeros((H, W), np.float32)
    spatula = polygon([(0.706, 0.801), (0.716, 0.790), (0.728, 0.794),
                       (0.731, 0.807), (0.726, 0.825), (0.721, 0.831),
                       (0.731, 0.856), (0.723, 0.867), (0.714, 0.858),
                       (0.704, 0.847), (0.697, 0.828), (0.697, 0.812)], 0.0004)
    holder = polygon([(0.716, 0.866), (0.739, 0.874), (0.776, 0.874),
                      (0.798, 0.866), (0.794, 0.919), (0.784, 0.949),
                      (0.765, 0.966), (0.738, 0.960), (0.723, 0.939)], 0.0005)
    foreground = np.maximum(spatula, holder)
    canvas = canvas * (1 - foreground[..., None]) + source * foreground[..., None]

    rendered = cv2.resize(np.clip(canvas, 0, 255).astype(np.uint8), (w, h), interpolation=cv2.INTER_AREA)
    footprint = np.maximum(body, shadow)
    footprint = np.maximum(footprint, cv2.resize(repair.astype(np.float32) / 255, (W, H)))
    footprint = cv2.resize(footprint, (w, h), interpolation=cv2.INTER_AREA)
    footprint[:int(0.496 * h), :] = 0
    footprint = np.clip(footprint, 0, 1)
    result = original.astype(np.float32) * (1 - footprint[..., None]) + rendered.astype(np.float32) * footprint[..., None]
    return Image.fromarray(np.clip(result, 0, 255).astype(np.uint8), 'RGB')
The background should be of a mountain.
magicbrush_train_504170_1 · other · execution=passed
PASSinstr 5preserve 4quality 3
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The original background has been replaced with a mountain scene, satisfying the instruction. The tennis player, racket, ball, and foreground are mostly preserved, though there are some cutout/edge artifacts. The edit is visually understandable but the illustrated mountains and sky look somewhat unrealistic and mismatched with the photo.

l1=0.1306 · gain=-0.0315 · mask_l1=0.0113 · preserve_l1=0.1571

reasoning / plan
{
 "visual_evidence": [
  "A tennis player wearing a white shirt and blue shorts fills the foreground.",
  "A green tennis ball is visible near the upper left.",
  "The player holds a racket along the left side.",
  "The background contains a metal fence, vehicles, and a rust-stained barrier.",
  "A narrow red court strip is visible along the bottom."
 ],
 "target_object": "The background behind the tennis player",
 "target_region": "The fence, vehicles, and barrier surrounding the player, racket, and ball",
 "editing_intent": "Replace the existing background with a textured mountain landscape while preserving the tennis action.",
 "editing_plan": [
  "Create separate foreground masks for the player, ball, racket rim, and visible racket strings.",
  "Generate a softly graded sky and distant atmospheric ridges.",
  "Construct a large rocky mountain range with irregular ridgelines, directional shading, snow, gullies, and multiscale texture.",
  "Add textured foothills and match the background's lighting and photographic grain.",
  "Feather the foreground boundaries and composite the original player and equipment over the mountain background.",
  "Retain the visible red court strip at the bottom."
 ],
 "preservation_constraints": [
  "Keep the player's face, skin, pose, clothing, and hands unchanged.",
  "Preserve the green tennis ball.",
  "Preserve the racket rim and visible strings.",
  "Keep the foreground court strip.",
  "Do not add people, buildings, or other equipment."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    image = image.convert('RGB')
    w, h = image.size
    src = np.asarray(image).astype(np.float32)
    rng = np.random.default_rng(41)
    yy, xx = np.mgrid[0:h, 0:w].astype(np.float32)
    X = xx / max(w - 1, 1)
    Y = yy / max(h - 1, 1)

    def noise(nx, ny):
        a = rng.normal(0, 1, (max(2, ny), max(2, nx))).astype(np.float32)
        a = cv2.resize(a, (w, h), interpolation=cv2.INTER_CUBIC)
        a -= a.mean()
        a /= max(float(a.std()), 0.001)
        return a

    broad = noise(9, 7)
    medium = noise(35, 29)
    fine = noise(115, 95)
    micro = noise(max(2, w // 2), max(2, h // 2))

    def ridge(points, roughness=0.004):
        p = np.asarray(points, np.float32)
        r = np.interp(X[0], p[:, 0], p[:, 1]).astype(np.float32)
        r = cv2.GaussianBlur(r[None, :], (0, 0), max(0.35, w * 0.0015))[0]
        irregular = 0.65 * medium[h // 3] + 0.35 * fine[h // 4]
        return r + roughness * irregular

    def over(bg, fg, a):
        return bg * (1 - a[..., None]) + fg * a[..., None]

    # Clear daylight sky, with subtle wispy atmospheric variation.
    t = np.clip(Y / 0.75, 0, 1)[..., None]
    sky = np.array([77, 139, 196], np.float32) * (1 - t)
    sky = sky + np.array([195, 215, 228], np.float32) * t
    sky += (1.6 * broad + 0.45 * medium)[..., None]
    cloudfield = noise(14, 5)
    cloud = np.clip((cloudfield - 0.75) * 0.13, 0, 0.24)
    cloud *= np.exp(-((Y - 0.19) / 0.16) ** 2)
    bg = over(sky, np.full_like(sky, [238, 242, 243]), cloud)

    # A muted, more distant mountain layer.
    distant = ridge([(0, .44), (.09, .37), (.16, .40), (.26, .31),
                     (.36, .40), (.48, .36), (.59, .43), (.70, .34),
                     (.82, .25), (.89, .34), (1, .41)], .003)
    da = np.clip((Y - distant[None, :]) * h + 0.5, 0, 1)
    dtex = 6 * broad + 3 * medium + fine
    dcol = np.empty_like(src)
    dcol[:] = [137, 158, 176]
    dcol += dtex[..., None]
    dshade = np.clip(1 - 0.18 * (X - .25), .83, 1.06)
    dcol *= dshade[..., None]
    dsnow = np.clip((.335 + .012 * medium - Y) / .025, 0, 1)
    dsnow *= np.clip((Y - distant[None, :]) / .02, 0, 1)
    dcol = over(dcol, np.full_like(src, [208, 218, 226]), dsnow * .72)
    bg = over(bg, dcol, da)

    # Main range: a high left summit and a second summit on the right.
    mainridge = ridge([(0, .60), (.055, .55), (.12, .49), (.18, .40),
                       (.235, .315), (.278, .273), (.325, .177),
                       (.352, .238), (.40, .309), (.44, .354),
                       (.49, .402), (.55, .493), (.61, .559),
                       (.67, .534), (.725, .471), (.785, .366),
                       (.829, .291), (.862, .341), (.91, .439),
                       (1, .535)], .0037)
    distance = np.maximum(Y - mainridge[None, :], 0)
    ma = np.clip((Y - mainridge[None, :]) * h + .5, 0, 1)
    # Fan-shaped erosion channels radiate downward from each summit.
    leftfan = (X - .325) / np.maximum(Y - .177 + .105, .07)
    rightfan = (X - .829) / np.maximum(Y - .291 + .105, .07)
    mix = np.clip((X - .55) / .17, 0, 1)
    mix = mix * mix * (3 - 2 * mix)
    fan = leftfan * (1 - mix) + rightfan * mix
    folds = np.sin(35 * fan + .85 * broad + .32 * medium)
    gullies = np.abs(np.sin(19 * fan + .7 * broad))
    relief = .021 * broad + .010 * medium + .003 * fine
    relief += .032 * folds * np.clip(distance / .07, 0, 1)
    smoothrelief = cv2.GaussianBlur(relief, (0, 0), max(.45, w * .0012))
    dx = cv2.Sobel(smoothrelief, cv2.CV_32F, 1, 0, ksize=3) * w / 8
    dy = cv2.Sobel(smoothrelief, cv2.CV_32F, 0, 1, ksize=3) * h / 8
    dx = np.clip(dx, -2.6, 2.6)
    dy = np.clip(dy, -2.6, 2.6)
    illumination = (.88 - .20 * dx - .13 * dy) / np.sqrt(1 + .12 * dx * dx + .10 * dy * dy)
    illumination = np.clip(illumination, .48, 1.18)
    illumination += .055 * folds
    strata = np.sin(145 * Y + 18 * X + 3.2 * broad + .6 * medium)
    stone = np.empty_like(src)
    stone[:] = [135, 135, 129]
    stone += (8 * broad + 5 * medium + 3.5 * fine + 1.8 * micro + 2.5 * strata)[..., None]
    stone[..., 0] += 4 * broad
    stone[..., 2] -= 3 * broad
    stone *= illumination[..., None]
    # Broken snow line and narrow snow-filled channels, not a flat white cap.
    snowline = .445 - .042 * mix + .015 * broad + .008 * medium
    snowline += .020 * (gullies - .5)
    snowmask = np.clip((snowline - Y) / .025 + .5, 0, 1)
    snowmask *= np.clip(1.18 - .33 * gullies + .14 * medium, 0, 1)
    snowmask = np.clip(snowmask, 0, 1)
    snow = np.empty_like(src)
    snow[:] = [236, 241, 244]
    snowlight = np.clip(.85 + .25 * (illumination - .7), .64, 1.06)
    snow *= snowlight[..., None]
    snow += (2.0 * fine + .8 * micro)[..., None]
    snow[..., 2] += np.clip(1 - illumination, 0, 1) * 12
    mountain = over(stone, snow, snowmask)
    haze = np.clip(.035 + .13 * distance + .035 * (1 - illumination), 0, .22)
    mountain = over(mountain, np.full_like(src, [169, 190, 205]), haze)
    bg = over(bg, mountain, ma)

    # Low, textured foothills provide depth below the rocky range.
    foothillridge = ridge([(0, .765), (.08, .715), (.18, .748),
                           (.29, .792), (.42, .745), (.55, .817),
                           (.67, .755), (.78, .723), (.9, .772),
                           (1, .724)], .006)
    fa = np.clip((Y - foothillridge[None, :]) * h + .5, 0, 1)
    hillshade = np.clip(.92 + .12 * broad + .05 * medium, .64, 1.12)
    hills = np.empty_like(src)
    hills[:] = [81, 99, 83]
    texture = 5 * broad + 5 * medium + 3.4 * fine + 1.5 * micro
    hills += texture[..., None]
    hills[..., 0] += 3 * np.sin(18 * X + 7 * Y)
    hills *= hillshade[..., None]
    hillhaze = np.clip(.19 - .14 * (Y - foothillridge[None, :]), .07, .20)
    hills = over(hills, np.full_like(src, [163, 184, 197]), hillhaze)
    bg = over(bg, hills, fa)
    bg += rng.normal(0, .8, (h, w, 1)).astype(np.float32)
    bg = np.clip(bg, 0, 255)

    # Supersampled contours retain the player's original pixels.
    scale = 3
    def polygon(points):
        canvas = np.zeros((h * scale, w * scale), np.uint8)
        p = np.asarray([(round(x * (w - 1) * scale), round(y * (h - 1) * scale))
                        for x, y in points], np.int32)
        cv2.fillPoly(canvas, [p], 255)
        return cv2.resize(canvas, (w, h), interpolation=cv2.INTER_AREA).astype(np.float32) / 255

    person = polygon([
        (.462,.377),(.502,.375),(.536,.365),(.568,.354),
        (.568,.319),(.570,.281),(.581,.250),(.596,.228),
        (.620,.215),(.650,.214),(.676,.223),(.695,.240),
        (.706,.263),(.708,.302),(.718,.310),(.720,.332),
        (.706,.352),(.695,.374),(.686,.392),(.724,.408),
        (.755,.426),(.775,.450),(.786,.480),(.794,.526),
        (.807,.566),(.817,.604),(.821,.645),(.814,.681),
        (.795,.702),(.768,.711),(.742,.703),(.709,.683),
        (.684,.663),(.667,.697),(.656,.739),(.657,.779),
        (.675,.816),(.684,.849),(.708,.869),(.729,.897),
        (.740,.929),(.753,.958),(.766,1.0),(.457,1.0),
        (.449,.966),(.429,.926),(.414,.889),(.395,.878),
        (.378,.855),(.370,.822),(.371,.776),(.371,.728),
        (.373,.679),(.372,.625),(.366,.579),(.365,.548),
        (.335,.548),(.306,.549),(.280,.541),(.260,.532),
        (.246,.537),(.235,.556),(.223,.582),(.204,.614),
        (.182,.655),(.164,.685),(.158,.711),(.149,.731),
        (.134,.740),(.119,.726),(.110,.707),(.113,.694),
        (.126,.682),(.140,.674),(.151,.659),(.166,.632),
        (.182,.602),(.197,.571),(.210,.539),(.221,.522),
        (.214,.506),(.208,.484),(.207,.470),(.239,.458),
        (.277,.449),(.320,.436),(.364,.416),(.400,.398),
        (.429,.387)
    ])

    # Thin oval racket frame, with its open interior treated separately.
    racket_outer = polygon([
        (.203,.507),(.214,.508),(.222,.521),(.221,.550),
        (.214,.588),(.204,.633),(.195,.680),(.184,.722),
        (.175,.751),(.162,.765),(.153,.759),(.149,.743),
        (.152,.706),(.159,.666),(.167,.621),(.179,.573),
        (.191,.530)
    ])
    racket_inner = polygon([
        (.204,.530),(.211,.527),(.214,.540),(.211,.567),
        (.202,.607),(.192,.650),(.183,.695),(.171,.736),
        (.161,.750),(.159,.735),(.164,.697),(.171,.656),
        (.180,.612),(.191,.567)
    ])
    rim = np.clip(racket_outer - racket_inner, 0, 1)
    # Extract fine string detail while discarding the smooth old wall behind it.
    gray = cv2.cvtColor(src.astype(np.uint8), cv2.COLOR_RGB2GRAY).astype(np.float32)
    local = cv2.GaussianBlur(gray, (0, 0), max(.7, w * .003))
    detail = np.abs(gray - local)
    strings = np.clip((detail - 6) / 22, 0, .86) * racket_inner
    # The frame remains solid; only fine internal detail is partially retained.
    foreground = np.maximum(person, np.maximum(rim, strings))

    ball_canvas = np.zeros((h * scale, w * scale), np.uint8)
    cv2.ellipse(ball_canvas,
                (round(.3125 * (w - 1) * scale), round(.0615 * (h - 1) * scale)),
                (max(1, round(.0330 * w * scale)), max(1, round(.0345 * h * scale))),
                0, 0, 360, 255, -1, lineType=cv2.LINE_AA)
    ball = cv2.resize(ball_canvas, (w, h), interpolation=cv2.INTER_AREA).astype(np.float32) / 255
    foreground = np.maximum(foreground, ball)
    foreground = cv2.GaussianBlur(foreground, (0, 0), max(.25, w * .00065))

    # Keep the court visible below the replacement landscape.
    court = np.clip((Y - .954) * h / 1.2, 0, 1)
    foreground = np.maximum(foreground, court)
    result = over(bg, src, np.clip(foreground, 0, 1))
    return Image.fromarray(np.clip(np.rint(result), 0, 255).astype(np.uint8), 'RGB')
remove the bench with pillows
magicbrush_train_61184_1 · remove · execution=passed
PASSinstr 4preserve 4quality 3
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The bench with pillows in the foreground was mostly removed, and the rest of the scene is largely preserved. However, the edit leaves visible artifacts in the deck area, including a strange diagonal white remnant and some unnatural wood/edge patches where the bench was.

l1=0.0295 · gain=0.0027 · mask_l1=0.0040 · preserve_l1=0.0639

reasoning / plan
{
 "visual_evidence": [
  "A wooden bench with white seat cushions and pillows occupies the lower-left foreground.",
  "Its slatted wooden side extends to the bottom edge near the center-left.",
  "The bench obscures part of the pale pool wall and the wooden decking.",
  "Unobstructed decking is visible immediately to the right of the bench."
 ],
 "target_object": "The foreground wooden bench, including its white cushions and pillows",
 "target_region": "Lower-left foreground, extending from the pillows below the pool wall to the bottom edge",
 "editing_intent": "Remove the bench and pillows, revealing continuous wooden decking and the previously obscured pool wall.",
 "editing_plan": [
  "Mask the visible bench silhouette, cushions, pillows, and narrow edge shadows.",
  "Reconstruct the upper masked area using nearby pool-wall pixels.",
  "Rectify a clean strip of visible decking and quilt overlapping copies using minimum-error seams.",
  "Project the synthesized decking into the masked foreground, preserving plank perspective and photographic grain.",
  "Feather the replacement boundary while leaving surrounding objects unchanged."
 ],
 "preservation_constraints": [
  "Preserve the pool, water, sea, sky, cliffs, and umbrellas.",
  "Preserve the plants and white structure on the right.",
  "Preserve the separate furniture visible outside the foreground bench mask.",
  "Retain the original image dimensions and the existing deck lighting and texture."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    w, h = image.size
    src = np.asarray(image.convert('RGB')).copy()
    rng = np.random.default_rng(17)

    # Follow the foreground sofa rather than masking the whole corner.
    outline = np.array([
        [0.000, 0.859], [0.115, 0.843], [0.169, 0.838],
        [0.176, 0.818], [0.180, 0.800], [0.188, 0.786],
        [0.218, 0.787], [0.220, 0.742], [0.232, 0.735],
        [0.260, 0.745], [0.305, 0.766], [0.377, 0.806],
        [0.430, 0.829], [0.444, 0.842], [0.483, 0.832],
        [0.501, 0.839], [0.508, 0.910], [0.510, 1.000],
        [0.000, 1.000]
    ], dtype=np.float32)
    outline[:, 0] *= w - 1
    outline[:, 1] *= h - 1
    mask = np.zeros((h, w), np.uint8)
    cv2.fillPoly(mask, [np.rint(outline).astype(np.int32)], 255)
    r = max(1, int(round(min(w, h) * 0.003)))
    mask = cv2.dilate(mask, cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2*r+1, 2*r+1)))

    # Inpainting supplies small transitional regions next to the rear furniture.
    base = cv2.inpaint(src, mask, max(2, int(round(w * 0.007))), cv2.INPAINT_TELEA).astype(np.float32)

    yy, xx = np.indices((h, w), dtype=np.float32)
    # The nearby pool fascia supplies real texture, shading, and its lower edge.
    wall = cv2.remap(src, np.minimum(xx + 0.255*w, w-1), yy,
                     cv2.INTER_LINEAR, borderMode=cv2.BORDER_REFLECT_101).astype(np.float32)

    y0 = min(h-2, max(0, int(round(0.795*h))))
    rows = np.arange(y0, h, dtype=np.float32)
    n = len(rows)
    t = (rows-y0) / max(1, h-1-y0)
    # Both edges of this donor strip lie on unobstructed wooden decking.
    left = w * (0.516 + 0.044*t)
    span = w * (0.164 + 0.035*t)
    d = max(12, int(round(span[-1])))
    u = np.linspace(0, 1, d, dtype=np.float32)
    mx = left[:, None] + span[:, None]*u[None, :]
    my = np.broadcast_to(rows[:, None], (n, d)).copy()
    donor = cv2.remap(src, mx, my, cv2.INTER_LINEAR,
                      borderMode=cv2.BORDER_REFLECT_101).astype(np.float32)

    # Work in rectified coordinates so repeated strips retain the deck perspective.
    scale = span / max(1.0, float(d-1))
    coordinates = (np.arange(w, dtype=np.float32)[None, :] - left[:, None]) / scale[:, None]
    lo = int(np.floor(coordinates.min())) - 3
    hi = int(np.ceil(coordinates.max())) + 4
    total = hi-lo+1
    overlap = max(5, int(round(d*0.22)))
    overlap = min(overlap, d-3)
    stride = d-overlap
    texture = np.zeros((n, total+d, 3), np.float32)
    texture[:, :d] = donor
    end = d
    tile_number = 1

    # Overlapping texture quilting; seams follow the least visible grain path.
    while end < total:
        start = end-overlap
        patch = donor[:, ::-1].copy() if tile_number % 2 else donor.copy()
        patch += float(rng.uniform(-0.8, 0.8))
        old = texture[:, start:start+overlap]
        new = patch[:, :overlap]
        cost = np.mean((old-new)**2, axis=2)
        old_g = cv2.cvtColor(np.uint8(np.clip(old, 0, 255)), cv2.COLOR_RGB2GRAY).astype(np.float32)
        new_g = cv2.cvtColor(np.uint8(np.clip(new, 0, 255)), cv2.COLOR_RGB2GRAY).astype(np.float32)
        cost += 0.3*(old_g-new_g)**2
        dp = cost.copy()
        back = np.zeros((n, overlap), np.int32)
        columns = np.arange(overlap)
        for row in range(1, n):
            previous = dp[row-1]
            choices = np.vstack((
                np.concatenate(([1e12], previous[:-1])),
                previous,
                np.concatenate((previous[1:], [1e12]))
            ))
            best = np.argmin(choices, axis=0)
            dp[row] += choices[best, columns]
            back[row] = columns+best-1
        seam = np.zeros(n, np.int32)
        seam[-1] = int(np.argmin(dp[-1]))
        for row in range(n-1, 0, -1):
            seam[row-1] = back[row, seam[row]]
        blend = np.clip((columns[None, :]-seam[:, None]+1.0)/2.0, 0, 1)[..., None]
        texture[:, start:start+overlap] = old*(1-blend)+new*blend
        texture[:, start+overlap:start+d] = patch[:, overlap:]
        end = start+d
        tile_number += 1

    map_x = (coordinates-lo).astype(np.float32)
    map_y = np.broadcast_to(np.arange(n, dtype=np.float32)[:, None], (n, w)).copy()
    deck = cv2.remap(texture, map_x, map_y, cv2.INTER_LINEAR,
                     borderMode=cv2.BORDER_REFLECT_101)
    # Keep the sampled grain, with very subtle nonrepeating illumination and noise.
    coarse = rng.normal(0, 0.55, (max(2, n//22), max(2, w//45))).astype(np.float32)
    variation = cv2.resize(coarse, (w, n), interpolation=cv2.INTER_CUBIC)
    deck += variation[..., None]
    deck += rng.normal(0, 0.30, deck.shape).astype(np.float32)

    replacement = wall.copy()
    replacement[y0:] = deck
    # Softly join the pool fascia to the decking at the existing floor level.
    transition = max(1, int(round(h*0.003)))
    for k in range(min(transition+1, n)):
        a = (k+1)/float(transition+1)
        replacement[y0+k] = wall[y0+k]*(1-a)+deck[k]*a

    # Retain the narrow timber transition behind the leftmost small pillow.
    transition_region = ((xx < 0.219*w) & (xx > 0.172*w) &
                         (yy > 0.788*h) & (yy < 0.818*h)).astype(np.float32)
    transition_region = cv2.GaussianBlur(transition_region, (0, 0), max(0.6, w*0.002))
    replacement = replacement*(1-transition_region[..., None]) + base*transition_region[..., None]

    alpha = cv2.GaussianBlur(mask.astype(np.float32)/255.0, (0, 0), max(0.55, w*0.0014))
    alpha = np.clip(alpha, 0, 1)[..., None]
    result = src.astype(np.float32)*(1-alpha)+replacement*alpha
    return Image.fromarray(np.uint8(np.clip(result, 0, 255)), 'RGB')
add a bullet train
magicbrush_train_236951_1 · add / insert · execution=passed
FAILinstr 4preserve 3quality 2
source
GPT-6.1-Sol output
MagicBrush target (reference only)

A bullet train was added, but it largely covers/replaces the original train area and is poorly integrated. The scale, perspective, lighting, and edge blending look unrealistic, with a pasted-on/cartoon appearance, though much of the station and signage remain unchanged.

l1=0.0667 · gain=0.0063 · mask_l1=0.0102 · preserve_l1=0.0855

reasoning / plan
{
 "visual_evidence": [
  "A red locomotive occupies the left foreground on a railway track.",
  "The train and track recede toward the center of the image.",
  "People stand on the platform beside the train.",
  "A yellow station sign reading LACHHMANGARH SIKAR stands on the right.",
  "Trees, pale sky, gravel, and black top and bottom borders are visible."
 ],
 "target_object": "A streamlined bullet train in the left-hand railway corridor",
 "target_region": "The foreground track and existing locomotive silhouette on the left, stopping short of the platform pedestrians",
 "editing_intent": "Add a silver-white bullet train with a rounded aerodynamic nose, dark panoramic windshield, blue stripe, and perspective-aligned side windows, naturally occluding the existing locomotive.",
 "editing_plan": [
  "Mask the foreground locomotive and reconstruct the small areas that will be exposed around the new streamlined silhouette.",
  "Construct a curved bullet-train body aligned with the existing track perspective.",
  "Render metallic shading, reflective glazing, side windows, blue trim, headlights, panel seams, and a dark undercarriage.",
  "Add a soft contact shadow and subtle image-matched surface noise.",
  "Antialias and feather the edited boundaries while preserving the station sign, pedestrians, platform, trees, rails outside the train, and black borders."
 ],
 "preservation_constraints": [
  "Keep the station sign and its lettering unchanged.",
  "Preserve the people on the platform.",
  "Preserve the trees and background outside the train silhouette.",
  "Keep the platform, foreground gravel, and exposed rails intact except for the train's immediate shadow.",
  "Do not alter the black image borders."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image, ImageDraw

    image = image.convert('RGB')
    w, h = image.size
    scale = 2
    W, H = w * scale, h * scale
    rng = np.random.default_rng(19)
    original = np.asarray(image).copy()
    yy, xx = np.mgrid[0:H, 0:W].astype(np.float32)
    X, Y = xx / W, yy / H
    union = np.zeros((H, W), np.float32)

    def path_mask(commands, feather=0.00065):
        points = []
        current = None
        for command in commands:
            if command[0] == 'M':
                current = np.array(command[1:3], dtype=float)
                points.append(tuple(current))
            elif command[0] == 'L':
                current = np.array(command[1:3], dtype=float)
                points.append(tuple(current))
            elif command[0] == 'C':
                p0 = current.copy()
                p1 = np.array(command[1:3], dtype=float)
                p2 = np.array(command[3:5], dtype=float)
                p3 = np.array(command[5:7], dtype=float)
                length = np.linalg.norm(p1-p0) + np.linalg.norm(p2-p1) + np.linalg.norm(p3-p2)
                count = max(12, int(length * max(W, H) / 2))
                for t in np.linspace(0, 1, count)[1:]:
                    p = (1-t)**3*p0 + 3*(1-t)**2*t*p1 + 3*(1-t)*t*t*p2 + t**3*p3
                    points.append(tuple(p))
                current = p3
        canvas = Image.new('L', (W, H), 0)
        draw = ImageDraw.Draw(canvas)
        draw.polygon([(round(a*W), round(b*H)) for a,b in points], fill=255)
        mask = np.asarray(canvas).astype(np.float32) / 255.0
        if feather > 0:
            mask = cv2.GaussianBlur(mask, (0, 0), max(0.35, feather * min(W, H)))
        return mask

    def poly(points, feather=0.00065):
        return path_mask([('M', *points[0])] + [('L', *p) for p in points[1:]], feather)

    old = poly([(0,.257),(.071,.249),(.087,.234),(.119,.234),(.122,.248),(.213,.248),(.218,.276),(.244,.284),(.255,.304),(.311,.325),(.327,.382),(.357,.422),(.384,.471),(.390,.524),(.378,.613),(.351,.686),(.343,.731),(.286,.778),(0,.791)], 0)
    old_low = cv2.resize(old, (w,h), interpolation=cv2.INTER_AREA)
    removal = (old_low > .10).astype(np.uint8) * 255
    radius = max(1, round(min(w,h)*.003))
    removal = cv2.dilate(removal, cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2*radius+1,2*radius+1)))
    repaired = cv2.inpaint(original, removal, max(3, int(min(w,h)*.012)), cv2.INPAINT_TELEA)
    ly, lx = np.mgrid[0:h,0:w].astype(np.float32)
    nx, ny = lx/w, ly/h
    # Reuse the real pale sky for the area exposed above the lower, aerodynamic roof.
    source_y = np.clip((.159 + (.345-ny)*.34)*h, .145*h, .235*h).astype(np.float32)
    sky = cv2.remap(original, lx, source_y, cv2.INTER_LINEAR, borderMode=cv2.BORDER_REFLECT_101)
    sky_mask = (removal.astype(np.float32)/255) * (1-np.clip((ny-.326)/.022,0,1)) * (1-np.clip((nx-.239)/.024,0,1))
    sky_mask = cv2.GaussianBlur(sky_mask, (0,0), max(.45,min(w,h)*.001))
    repaired = np.clip(repaired*(1-sky_mask[...,None])+sky*sky_mask[...,None],0,255).astype(np.uint8)
    canvas = np.asarray(Image.fromarray(repaired).resize((W,H), Image.Resampling.BICUBIC)).astype(np.float32)
    union = np.maximum(union, cv2.resize(removal.astype(np.float32)/255,(W,H),interpolation=cv2.INTER_LINEAR))

    def paint(mask, color, opacity=1.0):
        nonlocal canvas, union
        alpha = np.clip(mask*opacity,0,1)
        c = np.asarray(color, dtype=np.float32)
        if c.ndim == 1:
            c = c[None,None,:]
        canvas = canvas*(1-alpha[...,None]) + c*alpha[...,None]
        union = np.maximum(union, alpha)

    def stroke(points, color, width=.0015, opacity=1.0, clip=None):
        im = Image.new('L',(W,H),0)
        d = ImageDraw.Draw(im)
        d.line([(round(a*W),round(b*H)) for a,b in points],fill=255,width=max(1,round(width*min(W,H))),joint='curve')
        m = np.asarray(im).astype(np.float32)/255
        m = cv2.GaussianBlur(m,(0,0),.45)
        if clip is not None:
            m *= clip
        paint(m,color,opacity)

    def ellipse(box, color, opacity=1.0, blur=.0006):
        im = Image.new('L',(W,H),0)
        d = ImageDraw.Draw(im)
        d.ellipse(tuple(round(v*(W if i%2==0 else H)) for i,v in enumerate(box)), fill=255)
        m = np.asarray(im).astype(np.float32)/255
        if blur:
            m = cv2.GaussianBlur(m,(0,0),max(.35,blur*min(W,H)))
        paint(m,color,opacity)
        return m

    shadow = path_mask([('M',-.03,.750),('C',.067,.763,.16,.768,.247,.723),('L',.358,.645),('L',.386,.656),('C',.328,.729,.23,.776,.13,.800),('C',.055,.815,-.014,.801,-.03,.787)], .010)
    paint(shadow, (30,34,31), .40)
    contact = path_mask([('M',-.01,.744),('C',.105,.768,.19,.747,.256,.707),('L',.36,.624),('L',.372,.636),('C',.28,.732,.15,.788,-.01,.775)], .002)
    paint(contact,(34,42,44),.88)
    ellipse((.246,.670,.279,.710),(30,37,40))
    ellipse((.250,.674,.274,.704),(71,77,77))
    ellipse((.317,.613,.344,.648),(28,35,36))
    ellipse((.321,.617,.341,.643),(66,73,72))

    body = path_mask([('M',-.03,.368),('C',.002,.326,.062,.301,.116,.315),('C',.207,.335,.294,.397,.366,.458),('C',.386,.475,.396,.513,.381,.565),('L',.370,.610),('C',.342,.642,.295,.676,.238,.711),('C',.183,.749,.127,.772,.059,.771),('C',.015,.772,-.031,.752,-.060,.722),('C',-.048,.620,-.030,.470,-.030,.368)], .00085)
    noise = rng.normal(0,1.12,(H,W)).astype(np.float32)
    low_noise = cv2.GaussianBlur(rng.normal(0,1,(H,W)).astype(np.float32),(0,0),max(1,W*.008))
    lower = np.clip((Y-.56)/.22,0,1)
    highlight = np.exp(-((Y-(.49+.19*X))/.095)**2)
    value = 227 - 66*lower + 16*highlight - 13*X + noise + 8*low_noise
    metal = np.stack([value+2,value+5,value+5],axis=-1)
    metal[:,:,0] -= 7*lower
    metal[:,:,2] += 5*lower
    paint(body,np.clip(metal,0,255))

    side = path_mask([('M',.185,.352),('C',.253,.389,.319,.431,.366,.458),('C',.388,.480,.395,.514,.381,.565),('L',.370,.610),('C',.334,.651,.284,.681,.238,.711),('C',.218,.648,.216,.570,.218,.489),('C',.225,.436,.213,.391,.185,.352)], .001)
    side *= body
    sv = 216 - 58*np.clip((Y-.48)/.24,0,1) + 9*np.exp(-((Y-(.44+.30*X))/.04)**2) + noise
    paint(side,np.stack([sv-9,sv,sv+5],axis=-1),.83)
    roofshine = path_mask([('M',.005,.345),('C',.035,.317,.080,.309,.116,.322),('C',.213,.348,.294,.410,.366,.465),('L',.365,.473),('C',.287,.416,.210,.360,.112,.337),('C',.071,.325,.036,.331,.005,.355)],.002)
    paint(roofshine*body,(249,248,232),.55)

    # Main panoramic windscreen: rounded outline and subtly reflected foliage.
    wind = path_mask([('M',-.014,.391),('C',.020,.359,.055,.343,.094,.349),('C',.151,.353,.194,.387,.212,.422),('C',.226,.448,.222,.473,.205,.488),('C',.151,.522,.069,.522,-.015,.481),('C',-.016,.449,-.016,.420,-.014,.391)],.00075)
    paint(wind*body,(49,57,57))
    glass = path_mask([('M',-.012,.395),('C',.025,.365,.058,.352,.096,.359),('C',.149,.365,.186,.392,.204,.424),('C',.216,.449,.214,.467,.198,.481),('C',.145,.509,.071,.510,-.011,.475),('L',-.012,.395)],.0007)
    foliage = original[int(.14*h):max(int(.34*h),int(.14*h)+1),int(.48*w):max(int(.85*w),int(.48*w)+1)]
    reflected = np.asarray(Image.fromarray(foliage).resize((W,H),Image.Resampling.BICUBIC)).astype(np.float32)
    reflected = cv2.GaussianBlur(reflected,(0,0),max(.5,W*.0012))
    reflection = .14*reflected + np.array([20,33,37],np.float32)
    reflection += (19*np.exp(-((Y-(.397+.12*X))/.025)**2))[...,None]*np.array([.8,1,1.1])
    paint(glass*body,reflection)
    stroke([(.078,.355),(.088,.414),(.095,.510)],(67,77,77),.003,1,glass)
    stroke([(.022,.383),(.073,.369),(.117,.376),(.158,.398)],(180,192,182),.0016,.33,glass)
    stroke([(.035,.478),(.079,.430)],(15,24,26),.0023,.9,glass)
    stroke([(.123,.492),(.165,.445)],(15,24,26),.0021,.9,glass)
    stroke([(.002,.486),(.065,.513),(.128,.516),(.193,.495)],(122,136,136),.0014,.62,body)

    # The blue belt wraps over the curved nose and narrows with distance.
    stripe = path_mask([('M',-.024,.610),('C',.037,.653,.120,.670,.205,.622),('C',.263,.590,.323,.565,.382,.544),('L',.377,.567),('C',.315,.590,.263,.616,.208,.649),('C',.133,.699,.042,.685,-.026,.644)],.0009)
    stripe *= body
    blue_brightness = 9*np.exp(-((Y-.632)/.025)**2) + noise*.65
    blue = np.stack([24+blue_brightness,73+blue_brightness,113+blue_brightness],axis=-1)
    paint(stripe,blue)
    stroke([(-.01,.611),(.025,.635),(.066,.651),(.113,.653),(.157,.643),(.204,.619),(.275,.583),(.376,.546)],(123,178,198),.0014,.5,body)

    # Receding side glazing, with curved corners and lighter reflected sky.
    for i in range(5):
        t0 = i/5
        t1 = (i+.76)/5
        xa = .238 + .132*t0
        xb = .238 + .132*t1
        ya = .435 + .065*t0
        yb = .435 + .065*t1
        hh = .051 - .024*t0
        wm = path_mask([('M',xa,ya+.004),('C',xa,ya,xa+.003,ya,xa+.006,ya+.003),('L',xb-.003,yb),('C',xb,yb+.002,xb+.002,yb+.005,xb+.001,yb+.009),('L',xb-.003,yb+hh-.002),('L',xa+.002,ya+hh),('C',xa-.001,ya+hh-.004,xa-.001,ya+.015,xa,ya+.004)],.0006)*side
        paint(wm,(34,53,59))
        tint = np.stack([42+11*(1-Y),66+12*(1-Y),73+14*(1-Y)],axis=-1) + reflected*.065
        paint(wm,tint,.76)
        stroke([(xa+.005,ya+.009),(xb-.004,yb+.007)],(177,192,186),.0011,.35,wm)

    # Quiet panel joints and a small side door, all restricted to the metal body.
    stroke([(.225,.492),(.226,.572),(.231,.650),(.242,.694)],(97,119,126),.0011,.62,side)
    stroke([(.345,.484),(.347,.543),(.339,.593),(.330,.626)],(90,111,116),.001,.47,side)
    stroke([(.365,.505),(.367,.548),(.359,.591)],(103,121,125),.0009,.5,side)
    stroke([(.343,.553),(.349,.551)],(40,57,61),.0017,.85,side)
    stroke([(.244,.685),(.284,.658),(.329,.624),(.366,.594)],(89,108,111),.002,.56,body)

    hood_glow = path_mask([('M',-.012,.525),('C',.056,.557,.129,.568,.196,.536),('L',.199,.543),('C',.127,.580,.054,.571,-.012,.539)],.003)
    paint(hood_glow*body,(252,250,237),.32)
    stroke([(.069,.528),(.090,.581),(.094,.622)],(178,191,191),.0009,.46,body)

    # Recessed headlights with small warm highlights rather than painted white spots.
    for box in [(.006,.650,.052,.672),(.143,.658,.191,.679)]:
        x0,y0,x1,y1 = box
        housing = ellipse(box,(61,78,83),1,.0008)
        inset = ellipse((x0+.004,y0+.004,x1-.004,y1-.004),(175,195,192),1,.00065)
        ellipse((x0+.007,y0+.005,x1-.008,y1-.007),(247,243,214),.93,.001)
        stroke([(x0+.008,(y0+y1)/2),(x1-.008,(y0+y1)/2)],(255,253,229),.0018,.9)

    under = path_mask([('M',-.016,.730),('C',.044,.753,.124,.755,.191,.730),('L',.211,.735),('C',.138,.778,.038,.782,-.018,.755)],.001)*body
    paint(under,(51,65,71),.86)
    coupler = path_mask([('M',.071,.741),('C',.079,.735,.106,.735,.115,.741),('L',.117,.754),('C',.105,.760,.081,.759,.071,.754)],.001)
    paint(coupler*body,(26,35,39))
    stroke([(.079,.744),(.106,.744)],(103,114,113),.0016,.68,body)
    ellipse((.035,.704,.045,.710),(78,96,101),.75)
    ellipse((.184,.700,.193,.706),(78,96,101),.65)

    # Preserve the exact source everywhere outside the edited train and shadow.
    result_hi = np.clip(canvas,0,255).astype(np.uint8)
    rendered = np.asarray(Image.fromarray(result_hi).resize((w,h),Image.Resampling.LANCZOS)).astype(np.float32)
    alpha = cv2.resize(union,(w,h),interpolation=cv2.INTER_AREA)
    alpha = np.clip(alpha,0,1)
    alpha[(ny < .125) | (ny >= .877)] = 0
    # No edits may cross onto the foreground platform pedestrians.
    protect = ((nx > .398) & (ny > .49))
    alpha[protect] = 0
    final = original.astype(np.float32)*(1-alpha[...,None]) + rendered*alpha[...,None]
    return Image.fromarray(np.clip(np.rint(final),0,255).astype(np.uint8), 'RGB')
add a bear
magicbrush_train_236951_3 · add / insert · execution=passed
PASSinstr 5preserve 5quality 3
source
GPT-6.1-Sol output
MagicBrush target (reference only)

A bear was added to the scene in the foreground while the original train station content remains essentially unchanged. The bear is recognizable and placed plausibly on the ground, though it looks somewhat pasted in due to lighting/shadow and integration quality.

l1=0.0138 · gain=-0.0075 · mask_l1=0.0214 · preserve_l1=0.0107

reasoning / plan
{
 "visual_evidence": [
  "A silver train occupies the left side beside railway tracks.",
  "People stand farther back on the platform.",
  "Open gravelly platform space is visible in the lower-right foreground.",
  "Trees shade the right side, while daylight comes from the brighter left side.",
  "Black bands border the photograph at the top and bottom."
 ],
 "target_object": "A new brown bear",
 "target_region": "The open lower-right platform foreground, in front of the distant pedestrians and above the bottom black band",
 "editing_intent": "Add a realistic, four-legged brown bear facing left, with textured fur, shaded anatomy, and a grounded contact shadow.",
 "editing_plan": [
  "Define the bear's silhouette using overlapping shaded volumes for its torso, shoulder hump, head, muzzle, ears, legs, and paws.",
  "Render brown fur with multiscale texture, directional individual hairs, soft silhouette edges, and small facial details.",
  "Add subdued contact and cast shadows on the platform beneath the bear.",
  "Antialias and composite the synthesized bear into the foreground while preserving the original scene outside the edit."
 ],
 "preservation_constraints": [
  "Do not alter the train or railway tracks.",
  "Keep the pedestrians and background structures unchanged.",
  "Preserve the trees and existing platform texture outside the bear and its shadow.",
  "Keep both black image borders unchanged."
 ]
}
pixel code
def edit(image):
    import math
    import numpy as np
    import cv2
    from PIL import Image, ImageDraw

    w, h = image.size
    source = np.asarray(image.convert('RGB'), dtype=np.float32)
    rng = np.random.default_rng(37)
    ss = 2
    x0, x1 = int(0.548*w), min(w, int(math.ceil(0.934*w)))
    y0, y1 = int(0.665*h), min(h, int(math.floor(0.878*h)))
    rw, rh = (x1-x0)*ss, (y1-y0)*ss
    yy, xx = np.mgrid[0:rh, 0:rw].astype(np.float32)
    X = (x0 + (xx+0.5)/ss)/w
    Y = (y0 + (yy+0.5)/ss)/h

    # Projected ellipsoids: center, radii, depth, depth radius,
    # in-plane rotation, and brown coat reflectance.
    parts = [
        (0.849,0.824,0.016,0.037,-0.024,0.019,-0.10,(67,46,30)),
        (0.841,0.858,0.025,0.009,-0.020,0.016,0.00,(62,43,28)),
        (0.682,0.822,0.016,0.035,-0.025,0.020,0.12,(68,47,31)),
        (0.671,0.858,0.025,0.009,-0.019,0.016,0.00,(62,43,28)),
        (0.796,0.757,0.096,0.057,0.003,0.051,0.02,(99,70,44)),
        (0.862,0.776,0.042,0.045,0.009,0.041,-0.13,(94,66,41)),
        (0.724,0.745,0.047,0.059,0.012,0.048,-0.10,(103,73,46)),
        (0.687,0.765,0.046,0.039,0.021,0.039,0.35,(98,68,42)),
        (0.853,0.806,0.024,0.039,0.037,0.028,-0.11,(88,60,37)),
        (0.854,0.839,0.017,0.026,0.037,0.020,0.01,(77,52,33)),
        (0.842,0.862,0.027,0.009,0.043,0.019,0.00,(73,50,32)),
        (0.728,0.801,0.024,0.038,0.041,0.030,0.12,(91,63,39)),
        (0.718,0.837,0.017,0.029,0.043,0.021,0.12,(80,55,34)),
        (0.704,0.862,0.028,0.010,0.047,0.019,0.00,(74,51,32)),
        (0.643,0.744,0.010,0.012,0.023,0.012,-0.10,(77,53,32)),
        (0.650,0.770,0.037,0.030,0.044,0.033,0.22,(99,69,44)),
        (0.666,0.744,0.012,0.014,0.063,0.012,0.18,(91,61,37)),
        (0.615,0.785,0.031,0.019,0.056,0.022,-0.12,(124,91,61)),
        (0.591,0.784,0.011,0.008,0.079,0.009,-0.10,(25,24,21))
    ]
    surfaces = []
    normals = []
    validities = []
    for cx,cy,rx,ry,depth,rz,angle,color in parts:
        ca, sa = math.cos(angle), math.sin(angle)
        dx, dy = X-cx, Y-cy
        u, v = ca*dx+sa*dy, -sa*dx+ca*dy
        q = (u/rx)**2 + (v/ry)**2
        valid = q < 1.0
        root = np.sqrt(np.maximum(1.0-q, 0.0004))
        z = np.where(valid, depth+rz*root, -100.0)
        gx = 2.0*u*ca/(rx*rx)-2.0*v*sa/(ry*ry)
        gy = 2.0*u*sa/(rx*rx)+2.0*v*ca/(ry*ry)
        nx = rz*gx/(2.0*root)
        ny = rz*gy/(2.0*root)*(w/float(h))
        nz = np.ones_like(nx)
        norm = np.sqrt(nx*nx+ny*ny+nz*nz)
        surfaces.append(z)
        normals.append(np.stack((nx/norm,ny/norm,nz/norm),axis=-1))
        validities.append(valid)
    zmax = np.max(np.stack(surfaces),axis=0)
    silhouette = np.any(np.stack(validities),axis=0)
    weight_sum = np.zeros((rh,rw),np.float32)
    normal_sum = np.zeros((rh,rw,3),np.float32)
    pigment = np.zeros_like(normal_sum)
    for part,z,n,valid in zip(parts,surfaces,normals,validities):
        weight = np.exp(np.clip((z-zmax)/0.0034,-50,0))*valid
        weight_sum += weight
        normal_sum += n*weight[...,None]
        pigment += np.array(part[-1],np.float32)*weight[...,None]
    denom = np.maximum(weight_sum,1e-8)
    pigment /= denom[...,None]
    normal_sum /= denom[...,None]
    normal_sum /= np.maximum(np.linalg.norm(normal_sum,axis=-1,keepdims=True),1e-8)
    light = np.array([-0.58,-0.76,1.10],np.float32)
    light /= np.linalg.norm(light)
    diffuse = np.maximum(np.sum(normal_sum*light,axis=-1),0)
    shade = 0.47+0.75*diffuse
    coat = pigment*shade[...,None]
    coat += (diffuse**7)[...,None]*np.array([12,10,7],np.float32)

    def noise_field(nx,ny):
        small = rng.normal(0,1,(max(2,ny),max(2,nx))).astype(np.float32)
        field = cv2.resize(small,(rw,rh),interpolation=cv2.INTER_CUBIC)
        return field/(float(field.std())+1e-6)

    broad = noise_field(14,9)
    medium = noise_field(57,32)
    fine = rng.normal(0,1,(rh,rw)).astype(np.float32)
    fur_variation = np.clip(0.99+0.082*broad+0.062*medium+0.037*fine,0.68,1.30)
    coat *= fur_variation[...,None]
    coat[~silhouette] = np.array([70,47,29],np.float32)
    coat = np.clip(coat,0,255)
    coat_image = Image.fromarray(coat.astype(np.uint8),'RGB')
    hair_layer = Image.new('RGBA',(rw,rh),(0,0,0,0))
    hair_draw = ImageDraw.Draw(hair_layer)
    sy,sx = np.nonzero(silhouette)
    count = max(1,int(len(sx)/4.5))
    selected = rng.integers(0,len(sx),size=count)
    stroke_width = max(1,int(round(0.00065*w*ss)))
    for index in selected:
        px,py = int(sx[index]),int(sy[index])
        fx,fy = float(X[py,px]),float(Y[py,px])
        if fx < 0.606:
            continue
        if fy > 0.804:
            angle = 1.48+rng.normal(0,0.23)
        elif fx < 0.688:
            angle = 2.32+rng.normal(0,0.27)
        else:
            angle = 0.42+rng.normal(0,0.25)
        length = rng.uniform(0.002,0.0065)*w*ss
        if fy > 0.847:
            length *= 0.55
        dx,dy = math.cos(angle)*length,math.sin(angle)*length
        brightness = rng.normal(4,14)
        c = np.clip(coat[py,px]+brightness*np.array([1.0,0.88,0.69]),0,255).astype(np.uint8)
        color = (int(c[0]),int(c[1]),int(c[2]),int(rng.integers(75,165)))
        hair_draw.line([(px,py),(px+dx*0.55,py+dy*0.43),(px+dx,py+dy)],fill=color,width=stroke_width)
    hairy = np.asarray(Image.alpha_composite(coat_image.convert('RGBA'),hair_layer).convert('RGB'),dtype=np.float32)
    coat = np.where(silhouette[...,None],hairy,coat)

    # Small, softly shaded facial features rather than graphic outlines.
    def detail(cx,cy,rx,ry,color,opacity=1.0):
        nonlocal coat
        q = ((X-cx)/rx)**2+((Y-cy)/ry)**2
        a = np.clip((1-q)*4.0,0,1)*opacity
        a *= silhouette
        relief = np.sqrt(np.maximum(1-q,0))
        target = np.array(color,np.float32)[None,None,:]*(0.78+0.22*relief[...,None])
        coat = coat*(1-a[...,None])+target*a[...,None]
    detail(0.666,0.744,0.0064,0.0085,(54,36,25),0.76)
    detail(0.664,0.741,0.0037,0.0040,(91,61,41),0.48)
    detail(0.636,0.764,0.0060,0.0042,(65,42,26),0.47)
    detail(0.635,0.764,0.0036,0.0025,(18,16,13),0.95)
    detail(0.6343,0.7633,0.0009,0.0007,(173,161,133),0.75)
    detail(0.588,0.786,0.0030,0.0020,(10,10,9),0.77)
    detail(0.590,0.781,0.0045,0.0016,(90,86,72),0.42)
    coat_image = Image.fromarray(np.clip(coat,0,255).astype(np.uint8),'RGB')
    features = Image.new('RGBA',(rw,rh),(0,0,0,0))
    fd = ImageDraw.Draw(features)
    def p(x,y):
        return ((x*w-x0)*ss,(y*h-y0)*ss)
    fd.line([p(0.598,0.794),p(0.609,0.797),p(0.623,0.796)],fill=(46,31,22,140),width=max(1,int(0.0009*w*ss)))
    for px in (0.687,0.697,0.707,0.827,0.837,0.847):
        fd.line([p(px+0.002,0.861),p(px,0.866)],fill=(55,48,37,115),width=max(1,int(0.0008*w*ss)))
    coat_image = Image.alpha_composite(coat_image.convert('RGBA'),features).convert('RGB')

    # Fine hairs extend slightly beyond the otherwise smooth volume boundary.
    distance = cv2.distanceTransform(silhouette.astype(np.uint8),cv2.DIST_L2,3)
    edge = silhouette & (distance < max(1.6,0.0019*w*ss)) & (X>0.607) & (Y<0.850)
    ey,ex = np.nonzero(edge)
    softmask = cv2.GaussianBlur(silhouette.astype(np.float32),(0,0),0.52)
    mask_image = Image.fromarray(np.clip(softmask*255,0,255).astype(np.uint8),'L')
    md = ImageDraw.Draw(mask_image)
    cd = ImageDraw.Draw(coat_image)
    smooth = cv2.GaussianBlur(silhouette.astype(np.float32),(0,0),1.4)
    gy,gx = np.gradient(smooth)
    if len(ex):
        chosen = rng.integers(0,len(ex),size=max(1,len(ex)//2))
        for index in chosen:
            px,py = int(ex[index]),int(ey[index])
            vx,vy = -float(gx[py,px]),-float(gy[py,px])
            norm = math.hypot(vx,vy)+1e-7
            length = rng.uniform(0.0008,0.0028)*w*ss
            end = (px+vx/norm*length,py+vy/norm*length)
            c = np.clip(coat[py,px]+rng.normal(0,8),0,255).astype(np.uint8)
            md.line([(px,py),end],fill=int(rng.integers(120,220)),width=stroke_width)
            cd.line([(px,py),end],fill=tuple(int(v) for v in c),width=stroke_width)
    alpha_hi = np.asarray(mask_image,dtype=np.float32)/255.0
    rgb_hi = np.asarray(coat_image,dtype=np.float32)
    # Premultiplied resampling keeps antialiased fur edges free of dark halos.
    alpha = cv2.resize(alpha_hi,(x1-x0,y1-y0),interpolation=cv2.INTER_AREA)
    premul = cv2.resize(rgb_hi*alpha_hi[...,None],(x1-x0,y1-y0),interpolation=cv2.INTER_AREA)

    # Preserve the original platform texture through translucent shadows.
    oy,ox = np.mgrid[0:h,0:w].astype(np.float32)
    fx,fy = (ox+0.5)/w,(oy+0.5)/h
    shadow = 0.15*np.exp(-0.5*(((fx-0.795)/0.106)**2+((fy-0.867)/0.008)**2))
    shadow += 0.12*np.exp(-0.5*(((fx-0.811)/0.092)**2+((fy-0.873)/0.0045)**2))
    for cx,cy,rx in [(0.704,0.867,0.024),(0.842,0.867,0.024),(0.671,0.862,0.021)]:
        shadow += 0.20*np.exp(-0.5*(((fx-cx)/rx)**2+((fy-cy)/0.0028)**2))
    permitted = (fy>0.839)&(fy<0.878)&(fx>0.55)&(fx<0.96)
    shadow *= permitted
    result = source*(1-np.clip(shadow,0,0.43)[...,None])
    region = result[y0:y1,x0:x1]
    result[y0:y1,x0:x1] = premul+region*(1-alpha[...,None])
    return Image.fromarray(np.clip(np.rint(result),0,255).astype(np.uint8),'RGB')
add a helicopter in the sky
magicbrush_train_507950_3 · add / insert · execution=passed
PASSinstr 5preserve 5quality 4
source
GPT-6.1-Sol output
MagicBrush target (reference only)

A helicopter was added clearly in the sky, and the rest of the scene appears unchanged. The helicopter is reasonably placed but looks somewhat flat/illustrative compared with the photo, so visual quality is good but not perfect.

l1=0.0069 · gain=-0.0043 · mask_l1=0.0002 · preserve_l1=0.0147

reasoning / plan
{
 "visual_evidence": [
  "Pale, cloudy sky is visible above the wooded hills.",
  "The upper-right sky has open space for an airborne helicopter.",
  "Cows occupy the foreground, and a white-and-blue train crosses the middle distance."
 ],
 "target_object": "A new helicopter",
 "target_region": "Open sky in the upper-right portion of the image, above the hills",
 "editing_intent": "Add a small, realistic helicopter with shaded metal surfaces, cockpit glazing, landing skids, and slightly blurred rotating blades.",
 "editing_plan": [
  "Select a sky-only placement above the right-hand hills.",
  "Construct an antialiased helicopter silhouette with a rounded cabin, tapered tail, engine housing, and landing skids.",
  "Add curved cockpit windows, subtle body highlights, panel details, and atmospheric color matching.",
  "Render main and tail rotors with faint motion blur and sharper blade traces.",
  "Blend the synthesized pixels into the sky while leaving the rest of the photograph unchanged."
 ],
 "preservation_constraints": [
  "Keep the cows, grass, and soil unchanged.",
  "Preserve the train and railway.",
  "Do not alter the wooded hills or trees.",
  "Preserve all sky pixels outside the helicopter and its rotor blur."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    original = np.array(image.convert('RGB'), dtype=np.float32)
    w, h = image.size
    x0, y0 = int(w * 0.64), int(h * 0.008)
    x1, y1 = int(w * 0.96), int(h * 0.19)
    rw, rh = x1 - x0, y1 - y0
    if rw < 2 or rh < 2:
        return image.copy()
    ss = 4
    W, H = rw * ss, rh * ss
    yy, xx = np.mgrid[0:H, 0:W].astype(np.float32)
    U, V = xx / max(W - 1, 1), yy / max(H - 1, 1)
    rng = np.random.default_rng(17)
    grain = rng.normal(0, 1.0, (H, W)).astype(np.float32)
    grain = cv2.GaussianBlur(grain, (0, 0), 0.45 * ss)
    sky = np.median(original[y0:y1, x0:x1].reshape(-1, 3), axis=0)
    foreground = np.zeros((H, W, 3), np.float32)
    coverage = np.zeros((H, W), np.float32)

    def paint(mask, color, opacity=1.0, shade=0.0, haze=0.18):
        nonlocal foreground, coverage
        a = np.clip(mask * opacity, 0.0, 1.0)
        base = np.array(color, np.float32) * (1.0 - haze) + sky * haze
        lighting = shade * (0.55 - V) + 1.7 * np.sin(U * 15.0 + V * 7.0) + grain * 1.6
        col = np.clip(base[None, None, :] + lighting[:, :, None], 0, 255)
        foreground = col * a[:, :, None] + foreground * (1.0 - a[:, :, None])
        coverage = a + coverage * (1.0 - a)

    def polygon(points, color, opacity=1.0, shade=0.0, feather=0.32, haze=0.18):
        pts = np.round(np.array(points) * np.array([W - 1, H - 1])).astype(np.int32)
        mask = np.zeros((H, W), np.uint8)
        cv2.fillPoly(mask, [pts], 255, lineType=cv2.LINE_AA)
        m = mask.astype(np.float32) / 255.0
        if feather > 0:
            m = cv2.GaussianBlur(m, (0, 0), max(0.3, feather * ss))
        paint(m, color, opacity, shade, haze)

    def path(start, segments):
        points = [start]
        current = np.array(start, float)
        for segment in segments:
            if len(segment) == 2:
                current = np.array(segment, float)
                points.append(tuple(current))
            else:
                c1 = np.array(segment[0:2], float)
                c2 = np.array(segment[2:4], float)
                end = np.array(segment[4:6], float)
                for t in np.linspace(0, 1, 18)[1:]:
                    p = (1-t)**3 * current + 3*(1-t)**2*t*c1 + 3*(1-t)*t*t*c2 + t**3*end
                    points.append(tuple(p))
                current = end
        return points

    def line(points, color, width=0.004, opacity=1.0, feather=0.22):
        mask = np.zeros((H, W), np.uint8)
        pts = np.round(np.array(points) * np.array([W - 1, H - 1])).astype(np.int32)
        cv2.polylines(mask, [pts], False, 255, max(1, int(width * W)), cv2.LINE_AA)
        m = mask.astype(np.float32) / 255.0
        if feather > 0:
            m = cv2.GaussianBlur(m, (0, 0), max(0.3, feather * ss))
        paint(m, color, opacity, 0.0)

    def ellipse(center, radii, color, opacity=1.0, feather=0.3):
        mask = np.zeros((H, W), np.uint8)
        c = (int(center[0] * W), int(center[1] * H))
        axes = (max(1, int(radii[0] * W)), max(1, int(radii[1] * H)))
        cv2.ellipse(mask, c, axes, 0, 0, 360, 255, -1, cv2.LINE_AA)
        m = mask.astype(np.float32) / 255.0
        if feather > 0:
            m = cv2.GaussianBlur(m, (0, 0), max(0.3, feather * ss))
        paint(m, color, opacity)

    # Faint rotor sweep, behind the aircraft.
    ellipse((0.445, 0.205), (0.402, 0.023), (107, 117, 121), 0.105, 0.85)
    line([(0.055, 0.226), (0.435, 0.203), (0.852, 0.181)], (74, 84, 87), 0.006, 0.61, 0.42)
    line([(0.096, 0.188), (0.437, 0.204), (0.817, 0.231)], (101, 112, 115), 0.005, 0.23, 0.62)

    # Far landing skid and supports.
    line([(0.29, 0.639), (0.279, 0.729), (0.461, 0.735), (0.479, 0.624)], (65, 73, 74), 0.007, 0.80)
    line([(0.226, 0.722), (0.249, 0.742), (0.509, 0.742)], (81, 90, 88), 0.008, 0.87)

    # Tail boom with a curved taper and vertical stabilizer.
    polygon(path((0.484, 0.465), [(0.614, 0.459, 0.734, 0.435, 0.871, 0.414), (0.896, 0.468), (0.702, 0.516, 0.623, 0.548, 0.489, 0.574)]), (92, 104, 101), shade=30)
    polygon(path((0.837, 0.437), [(0.858, 0.307), (0.884, 0.285), (0.911, 0.315), (0.895, 0.481), (0.858, 0.507)]), (79, 91, 89), shade=22)
    line([(0.571, 0.477), (0.842, 0.430)], (149, 157, 150), 0.004, 0.52)
    polygon([(0.776, 0.487), (0.821, 0.470), (0.889, 0.497), (0.889, 0.518), (0.823, 0.505)], (76, 88, 86), 0.94, 14)

    # Main cabin: rounded nose, fuller lower cabin, tapered rear.
    body = path((0.175, 0.543), [(0.178, 0.466, 0.242, 0.390, 0.320, 0.385), (0.394, 0.377, 0.472, 0.396, 0.522, 0.440), (0.552, 0.470, 0.569, 0.536, 0.542, 0.582), (0.520, 0.646, 0.463, 0.674, 0.377, 0.678), (0.276, 0.680, 0.197, 0.635, 0.180, 0.582), (0.175, 0.543)])
    polygon(body, (91, 105, 102), shade=61, feather=0.40)
    polygon(path((0.190, 0.586), [(0.266, 0.625, 0.395, 0.640, 0.538, 0.584), (0.512, 0.651, 0.458, 0.675, 0.377, 0.678), (0.269, 0.679, 0.199, 0.635, 0.190, 0.586)]), (59, 72, 71), 0.48, 9)

    # Engine cowling and rotor mast.
    polygon(path((0.349, 0.406), [(0.356, 0.350, 0.380, 0.323, 0.433, 0.329), (0.490, 0.326, 0.529, 0.355, 0.530, 0.431), (0.448, 0.445, 0.400, 0.429, 0.349, 0.406)]), (104, 114, 107), shade=45)
    line([(0.430, 0.333), (0.435, 0.228)], (68, 77, 76), 0.009, 0.96)
    line([(0.438, 0.321), (0.440, 0.240)], (142, 149, 140), 0.003, 0.65)
    ellipse((0.436, 0.219), (0.021, 0.020), (62, 73, 73), 0.94)
    ellipse((0.509, 0.398), (0.020, 0.026), (39, 50, 48), 0.90)
    line([(0.474, 0.358), (0.500, 0.367)], (159, 164, 151), 0.003, 0.46)

    # Cockpit glass with curved contours and muted cloudy reflections.
    polygon(path((0.190, 0.531), [(0.205, 0.470, 0.247, 0.420, 0.295, 0.410), (0.323, 0.409), (0.304, 0.544), (0.253, 0.565, 0.212, 0.555, 0.190, 0.531)]), (37, 56, 64), shade=23, feather=0.29, haze=0.22)
    polygon(path((0.338, 0.412), [(0.365, 0.411, 0.398, 0.424, 0.419, 0.445), (0.430, 0.532), (0.326, 0.545), (0.338, 0.412)]), (42, 61, 69), shade=22, feather=0.25, haze=0.22)
    polygon(path((0.207, 0.500), [(0.227, 0.453, 0.267, 0.427, 0.301, 0.423), (0.294, 0.448), (0.255, 0.459, 0.230, 0.480, 0.207, 0.500)]), (158, 178, 184), 0.27, feather=0.52)
    polygon([(0.343, 0.425), (0.394, 0.442), (0.408, 0.459), (0.339, 0.447)], (161, 180, 181), 0.23, feather=0.48)
    line([(0.323, 0.414), (0.311, 0.546), (0.318, 0.594)], (128, 140, 131), 0.004, 0.78)
    line([(0.441, 0.455), (0.454, 0.608), (0.363, 0.635), (0.329, 0.601)], (47, 63, 60), 0.003, 0.53)
    line([(0.369, 0.558), (0.390, 0.556)], (153, 161, 150), 0.003, 0.70)
    line([(0.204, 0.588), (0.285, 0.621), (0.391, 0.630)], (155, 160, 143), 0.003, 0.42)

    # Near skid: narrow tubular metal, not a filled polygon.
    line([(0.289, 0.648), (0.301, 0.767)], (65, 74, 71), 0.008, 0.95)
    line([(0.465, 0.633), (0.478, 0.762)], (66, 76, 73), 0.008, 0.95)
    skid = path((0.204, 0.731), [(0.216, 0.757, 0.238, 0.782, 0.265, 0.782), (0.522, 0.776)])
    line(skid, (65, 77, 74), 0.010, 0.98, 0.26)
    line([(0.261, 0.775), (0.518, 0.770)], (160, 166, 155), 0.0028, 0.64)
    line([(0.497, 0.626), (0.522, 0.694)], (68, 78, 74), 0.0025, 0.65)

    # Tail rotor, with a low-opacity swept disk and visible blade traces.
    ellipse((0.886, 0.447), (0.040, 0.070), (113, 125, 126), 0.13, 0.64)
    line([(0.857, 0.395), (0.914, 0.496)], (57, 70, 72), 0.005, 0.69, 0.34)
    line([(0.858, 0.499), (0.914, 0.394)], (77, 89, 90), 0.004, 0.49, 0.42)
    ellipse((0.886, 0.447), (0.010, 0.015), (159, 167, 156), 0.95, 0.20)

    # Downsample premultiplied layers, preserving untouched source pixels exactly.
    small_fg = cv2.resize(foreground, (rw, rh), interpolation=cv2.INTER_AREA)
    small_a = cv2.resize(coverage, (rw, rh), interpolation=cv2.INTER_AREA)
    roi = original[y0:y1, x0:x1]
    result_roi = roi * (1.0 - small_a[:, :, None]) + small_fg
    output = original.copy()
    output[y0:y1, x0:x1] = np.clip(result_roi, 0, 255)
    return Image.fromarray(np.rint(output).astype(np.uint8), 'RGB')
The hand could be holding a cup.
magicbrush_train_357633_3 · other · execution=passed
PASSinstr 4preserve 4quality 3
source
GPT-6.1-Sol output
MagicBrush target (reference only)

A cup was added near the hand so it plausibly appears the hand could be holding it. The rest of the scene is largely unchanged, though the cup partially covers the mouse/hand area and looks somewhat pasted in with imperfect lighting and integration.

l1=0.0249 · gain=-0.0014 · mask_l1=0.0005 · preserve_l1=0.0410

reasoning / plan
{
 "visual_evidence": [
  "A hand enters from the right beside the laptop keyboard.",
  "The fingers are bent near the upper-left side of the hand.",
  "There is room above the hand and along the right image edge for a partly cropped cup.",
  "The scene has bright daylight, with cooler reflections on the laptop."
 ],
 "target_object": "The hand and the space immediately above and beside it",
 "target_region": "Lower-right corner, to the right of the laptop",
 "editing_intent": "Add a realistically shaded ceramic cup behind the existing fingers so the hand appears to hold its handle.",
 "editing_plan": [
  "Identify the visible skin pixels and protect the laptop boundary.",
  "Construct an antialiased cup silhouette and curved handle in the available space.",
  "Render ceramic shading, an elliptical rim, a coffee surface, reflections, and subtle surface texture.",
  "Add a soft background shadow and contact shading beneath the fingers.",
  "Restore the original hand over the cup and preserve all unrelated pixels."
 ],
 "preservation_constraints": [
  "Keep the laptop, keyboard, screen, and displayed car unchanged.",
  "Preserve the visible hand, its skin texture, and finger positions.",
  "Keep the outdoor background unchanged outside the cup and its small shadow.",
  "Allow the cup to be naturally cropped by the right image edge."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    w, h = image.size
    src = np.asarray(image.convert('RGB')).astype(np.float32)
    yy, xx = np.mgrid[0:h, 0:w].astype(np.float32)
    X = (xx + 0.5) / w
    Y = (yy + 0.5) / h
    scale = 3
    W, H = w * scale, h * scale
    unit = min(w, h)
    rng = np.random.default_rng(17)

    def down(mask):
        return cv2.resize(mask.astype(np.float32) / 255.0, (w, h), interpolation=cv2.INTER_AREA)

    def ellipse(cx, cy, rx, ry):
        m = np.zeros((H, W), np.uint8)
        cv2.ellipse(m, (round(cx * W), round(cy * H)),
                    (max(1, round(rx * W)), max(1, round(ry * H))),
                    0, 0, 360, 255, -1, cv2.LINE_AA)
        return down(m)

    def polygon(points):
        m = np.zeros((H, W), np.uint8)
        p = np.array([[round(x * W), round(y * H)] for x, y in points], np.int32)
        cv2.fillPoly(m, [p], 255, cv2.LINE_AA)
        return down(m)

    def arc(cx, cy, rx, ry, start, end, thickness):
        m = np.zeros((H, W), np.uint8)
        cv2.ellipse(m, (round(cx * W), round(cy * H)),
                    (round(rx * W), round(ry * H)), 0, start, end,
                    255, max(1, round(thickness * min(W, H))), cv2.LINE_AA)
        return down(m)

    def blend(canvas, color, mask):
        a = np.clip(mask, 0, 1)[..., None]
        return canvas * (1 - a) + np.asarray(color, np.float32) * a

    # Separate the actual hand from the cool objects around it.
    rgb = src.astype(np.uint8)
    hsv = cv2.cvtColor(rgb, cv2.COLOR_RGB2HSV)
    roi = polygon([(0.839, 0.704), (0.889, 0.674), (1.0, 0.674),
                   (1.0, 0.875), (0.912, 0.805), (0.853, 0.750)])
    skin = ((hsv[..., 0] < 29) & (hsv[..., 1] > 65) &
            (src[..., 0] > 60) & (src[..., 0] > src[..., 1] * 1.07) &
            (src[..., 0] > src[..., 2] * 1.28) & (roi > 0.4)).astype(np.uint8)
    k = max(1, round(unit * 0.004))
    kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2 * k + 1, 2 * k + 1))
    skin = cv2.morphologyEx(skin, cv2.MORPH_CLOSE, kernel)
    n, labels, stats, centers = cv2.connectedComponentsWithStats(skin, 8)
    if n > 1:
        largest = 1 + int(np.argmax(stats[1:, cv2.CC_STAT_AREA]))
        skin = (labels == largest).astype(np.uint8)
    hand = cv2.GaussianBlur(skin.astype(np.float32), (0, 0), max(0.45, unit * 0.001))
    hand = np.maximum(hand, skin.astype(np.float32) * 0.98)

    # Keep all painting on the background side of the laptop's sloping edge.
    laptop_edge = 0.795 + 0.55 * (Y - 0.590)
    safe = np.clip((X - laptop_edge - 0.0015) * w / 1.1, 0, 1)
    safe = np.where(Y < 0.590, 1.0, safe).astype(np.float32)

    # Tapered cup body with a rounded bottom rather than a polygonal base.
    points = [(0.877, 0.610), (1.041, 0.610), (1.023, 0.758)]
    for a in np.linspace(0, np.pi, 70):
        points.append((0.961 + 0.062 * np.cos(a), 0.758 + 0.018 * np.sin(a)))
    body = polygon(points) * safe
    outer_handle = ellipse(0.882, 0.699, 0.040, 0.054)
    inner_handle = ellipse(0.882, 0.699, 0.023, 0.035)
    handle = np.clip(outer_handle - inner_handle, 0, 1) * safe
    rim = ellipse(0.959, 0.610, 0.082, 0.024) * safe
    opening = ellipse(0.959, 0.6085, 0.073, 0.0165) * safe
    silhouette = np.maximum(np.maximum(body, handle), rim)

    # A small, soft shadow on the original background, never on the laptop.
    transform = np.float32([[1, 0, w * 0.006], [0, 1, h * 0.011]])
    shadow = cv2.warpAffine(silhouette, transform, (w, h), flags=cv2.INTER_LINEAR)
    shadow = cv2.GaussianBlur(shadow, (0, 0), max(1.0, unit * 0.009))
    shadow *= safe * (1 - hand) * 0.18
    out = src * (1 - shadow[..., None])

    sample = src[int(h * 0.85):int(h * 0.92), int(w * 0.48):int(w * 0.62)]
    reference = np.median(sample.reshape(-1, 3), axis=0)
    ceramic = 0.38 * reference + 0.62 * np.array([230, 230, 220], np.float32)
    grain = rng.normal(0, 0.62, (h, w)).astype(np.float32)
    broad_noise = cv2.GaussianBlur(rng.normal(0, 1, (h, w)).astype(np.float32),
                                 (0, 0), max(1.0, unit * 0.005)) * 2.5

    # Curved handle shading, including its rounded tubular cross-section.
    hx = (X - 0.882) / 0.040
    hy = (Y - 0.699) / 0.054
    radius = np.sqrt(hx * hx + hy * hy)
    tube_light = np.exp(-((radius - 0.78) / 0.15) ** 2)
    handle_shade = -27 + 33 * tube_light - 8 * hx - 8 * hy
    handle_rgb = ceramic[None, None, :] + handle_shade[..., None]
    handle_rgb += (grain + broad_noise)[..., None]
    handle_rgb += np.stack((3 * np.maximum(hy, 0), np.zeros_like(X), -3 * np.maximum(hy, 0)), axis=-1)
    out = blend(out, np.clip(handle_rgb, 0, 255), handle)

    # Convex ceramic: a broad daylight highlight and cooler side falloff.
    t = np.clip((Y - 0.610) / 0.166, 0, 1)
    half_width = 0.082 - 0.020 * t
    u = (X - 0.960) / half_width
    light = 17 * np.exp(-((u + 0.38) / 0.55) ** 2)
    light -= 24 * np.abs(np.clip(u, -1, 1)) ** 2.8
    light -= 10 * t + 8 * np.exp(-((t - 0.94) / 0.055) ** 2)
    light += 5 * np.exp(-((u + 0.66) / 0.11) ** 2) * (1 - 0.5 * t)
    body_rgb = ceramic[None, None, :] + light[..., None]
    warm = np.exp(-((X - 0.923) / 0.053) ** 2 - ((Y - 0.741) / 0.062) ** 2)
    body_rgb += warm[..., None] * np.array([7, 1, -5], np.float32)
    body_rgb += (grain + broad_noise)[..., None]
    out = blend(out, np.clip(body_rgb, 0, 255), body)

    # Raised elliptical lip, a dark inner wall, and coffee inside.
    rim_light = 12 - 10 * ((X - 0.959) / 0.082) + 5 * ((Y - 0.610) / 0.024)
    rim_rgb = ceramic[None, None, :] + rim_light[..., None] + grain[..., None] * 0.6
    out = blend(out, np.clip(rim_rgb, 0, 255), rim)
    qx = (X - 0.959) / 0.073
    qy = (Y - 0.6085) / 0.0165
    radial = np.sqrt(qx * qx + qy * qy)
    coffee_light = 10 * np.exp(-((qx + 0.30) / 0.75) ** 2) - 13 * np.clip(radial, 0, 1) ** 3
    coffee_rgb = np.zeros_like(src) + np.array([57, 37, 25], np.float32)
    coffee_rgb += coffee_light[..., None] * np.array([1.0, 0.72, 0.46], np.float32)
    coffee_rgb += grain[..., None] * 0.5
    reflection = np.exp(-((X - 0.930) / 0.020) ** 2 - ((Y - 0.604) / 0.0038) ** 2)
    coffee_rgb += reflection[..., None] * np.array([68, 63, 47], np.float32)
    out = blend(out, np.clip(coffee_rgb, 0, 255), opening)
    front_lip = arc(0.959, 0.610, 0.0775, 0.021, 8, 172, 0.0027) * safe
    out = blend(out, np.clip(ceramic + 24, 0, 255), front_lip * 0.78)
    back_lip = arc(0.959, 0.608, 0.073, 0.016, 192, 347, 0.0015) * safe
    out = blend(out, np.array([105, 105, 94], np.float32), back_lip * 0.48)

    # Fingertips cast narrow shadows onto the cup and remain in front of it.
    distance = cv2.distanceTransform((skin == 0).astype(np.uint8), cv2.DIST_L2, 5)
    contact = np.exp(-distance / max(0.8, unit * 0.003)) * (1 - hand)
    contact *= silhouette * 0.21
    out *= 1 - contact[..., None]
    out = blend(out, src, hand)
    return Image.fromarray(np.clip(np.rint(out), 0, 255).astype(np.uint8), 'RGB')
make one of the dogs pant
magicbrush_train_115859_1 · replace / change · execution=passed
FAILinstr 4preserve 5quality 2
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The edit makes the right dog appear to be panting by adding an open mouth and tongue, while leaving the rest of the scene essentially unchanged. However, the added mouth/tongue looks cartoonish and poorly blended with the dog's face, reducing visual quality.

l1=0.0203 · gain=-0.0029 · mask_l1=0.0056 · preserve_l1=0.0277

reasoning / plan
{
 "visual_evidence": [
  "Two dogs are lying beside each other on patterned bedding.",
  "The dog on the right has golden-brown fur and a dark nose.",
  "The right dog's mouth is closed beneath its muzzle."
 ],
 "target_object": "The golden-brown dog on the right",
 "target_region": "The mouth beneath and to the right of its nose, including a small area immediately below the muzzle",
 "editing_intent": "Make the right dog pant by opening its mouth and adding a naturally shaded pink tongue hanging over its lower lip.",
 "editing_plan": [
  "Trace a curved mouth opening beneath the existing muzzle without covering the nose.",
  "Construct a softly feathered lower jaw rim using texture sampled from the dog's own fur.",
  "Add a shaded dark mouth cavity and small, partially visible teeth.",
  "Synthesize a curved pink tongue with darker roots, rounded edges, subtle texture, and a central groove.",
  "Blend the new mouth into the surrounding fur while preserving the rest of the image."
 ],
 "preservation_constraints": [
  "Do not change the left dog.",
  "Preserve the right dog's eyes, nose, ears, and upper muzzle.",
  "Preserve the bedding, background, and framing.",
  "Keep the edit localized to the right dog's mouth and the space immediately beneath it."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    w, h = image.size
    source = np.asarray(image.convert('RGB'), dtype=np.float32)
    result = source.copy()
    scale = float(min(w, h))
    yy, xx = np.mgrid[0:h, 0:w].astype(np.float32)
    xx /= float(w)
    yy /= float(h)
    rng = np.random.default_rng(24)

    def curved_mask(start, segments, feather=0.0012):
        points = [np.array(start, dtype=np.float64)]
        p0 = points[0]
        for segment in segments:
            p1 = np.array(segment[0:2], dtype=np.float64)
            p2 = np.array(segment[2:4], dtype=np.float64)
            p3 = np.array(segment[4:6], dtype=np.float64)
            for t in np.linspace(0.0, 1.0, 45)[1:]:
                p = (1-t)**3*p0 + 3*(1-t)**2*t*p1 + 3*(1-t)*t*t*p2 + t**3*p3
                points.append(p)
            p0 = p3
        supersampling = 3
        polygon = np.round(np.asarray(points) * np.array([w, h]) * supersampling).astype(np.int32)
        mask = np.zeros((h*supersampling, w*supersampling), dtype=np.uint8)
        cv2.fillPoly(mask, [polygon], 255)
        mask = cv2.resize(mask, (w, h), interpolation=cv2.INTER_AREA).astype(np.float32)/255.0
        if feather > 0:
            mask = cv2.GaussianBlur(mask, (0, 0), max(0.3, feather*scale))
        return np.clip(mask, 0, 1)

    def blend(color, mask, opacity=1.0):
        nonlocal result
        alpha = np.clip(mask*opacity, 0, 1)[..., None]
        color = np.asarray(color, dtype=np.float32)
        result = result*(1-alpha) + color*alpha

    grain = rng.normal(0, 1, (h, w)).astype(np.float32)
    broad_noise = cv2.GaussianBlur(grain, (0, 0), max(0.5, scale*0.004))
    broad_noise /= max(float(broad_noise.std()), 0.001)

    mouth_segments = [
        (0.724, 0.394, 0.780, 0.368, 0.820, 0.347),
        (0.831, 0.370, 0.816, 0.412, 0.793, 0.440),
        (0.774, 0.466, 0.745, 0.468, 0.723, 0.443),
        (0.704, 0.427, 0.691, 0.403, 0.684, 0.386)
    ]
    aperture = curved_mask((0.684, 0.386), mouth_segments, 0.0011)

    # A narrow lower jaw carries real fur texture rather than a painted outline.
    radius = max(1, int(round(scale*0.006)))
    kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2*radius+1, 2*radius+1))
    jaw = cv2.dilate(aperture, kernel)
    jaw = cv2.GaussianBlur(jaw, (0, 0), max(0.4, scale*0.0016))
    shadow = cv2.GaussianBlur(jaw, (0, 0), max(0.6, scale*0.005))
    shadow *= np.clip((yy-0.386)/0.04, 0, 1)
    blend(source*np.array([0.76, 0.72, 0.70], dtype=np.float32), shadow, 0.38)

    map_x = ((xx-0.684)*0.50+0.722)*w
    map_y = ((yy-0.347)*0.45+0.292)*h
    fur = cv2.remap(source, map_x.astype(np.float32), map_y.astype(np.float32), cv2.INTER_LINEAR, borderMode=cv2.BORDER_REFLECT_101)
    jaw_shade = 0.79 - 0.13*np.clip((yy-0.39)/0.09, 0, 1)
    fur = fur*jaw_shade[..., None]
    fur += grain[..., None]*1.3
    blend(np.clip(fur, 0, 255), jaw)

    # The cavity is warm near its lower surfaces and nearly black at the rear.
    depth = np.clip((xx-0.714)/0.112, 0, 1)
    lower = np.clip((yy-0.389)/0.068, 0, 1)
    cavity = np.empty_like(source)
    cavity[..., 0] = 35 + 13*lower - 12*depth
    cavity[..., 1] = 19 + 5*lower - 7*depth
    cavity[..., 2] = 18 + 7*lower - 5*depth
    reflected = np.exp(-((xx-0.752)/0.039)**2-((yy-0.438)/0.024)**2)
    cavity += reflected[..., None]*np.array([17, 7, 7], dtype=np.float32)
    cavity += grain[..., None]*1.0 + broad_noise[..., None]*1.1
    blend(np.clip(cavity, 0, 255), aperture)

    # A subdued lower gum surface remains behind the hanging tongue.
    gum = curved_mask((0.713, 0.423), [
        (0.736, 0.439, 0.773, 0.452, 0.801, 0.425),
        (0.790, 0.450, 0.762, 0.466, 0.737, 0.452),
        (0.725, 0.446, 0.717, 0.433, 0.713, 0.423)
    ], 0.0018)*aperture
    gum_color = np.empty_like(source)
    gum_color[:] = [74, 37, 34]
    gum_color += broad_noise[..., None]*2.0 + grain[..., None]*0.8
    blend(gum_color, gum, 0.78)

    # Small upper teeth are tucked into the opening, not drawn as bright triangles.
    rear_tooth = curved_mask((0.801, 0.362), [
        (0.805, 0.359, 0.812, 0.354, 0.815, 0.355),
        (0.815, 0.371, 0.809, 0.389, 0.804, 0.396),
        (0.799, 0.392, 0.800, 0.372, 0.801, 0.362)
    ], 0.00075)*aperture
    tooth_color = np.empty_like(source)
    tooth_light = np.clip((0.396-yy)/0.041, 0, 1)
    tooth_color[..., 0] = 163 + 47*tooth_light
    tooth_color[..., 1] = 145 + 43*tooth_light
    tooth_color[..., 2] = 111 + 39*tooth_light
    tooth_color += grain[..., None]*0.8
    blend(tooth_color, rear_tooth, 0.94)

    small_tooth = curved_mask((0.701, 0.399), [
        (0.705, 0.397, 0.710, 0.399, 0.713, 0.402),
        (0.714, 0.409, 0.713, 0.417, 0.708, 0.421),
        (0.704, 0.418, 0.701, 0.407, 0.701, 0.399)
    ], 0.0008)*aperture
    blend(tooth_color*0.83, small_tooth, 0.86)

    tongue = curved_mask((0.724, 0.406), [
        (0.737, 0.394, 0.764, 0.394, 0.776, 0.407),
        (0.775, 0.429, 0.781, 0.467, 0.768, 0.487),
        (0.759, 0.501, 0.739, 0.502, 0.727, 0.488),
        (0.714, 0.473, 0.719, 0.439, 0.724, 0.406)
    ], 0.0010)

    # The tongue casts a small shadow onto the lower jaw.
    shift_x = max(1, int(round(w*0.002)))
    shift_y = max(1, int(round(h*0.003)))
    transform = np.float32([[1, 0, shift_x], [0, 1, shift_y]])
    tongue_shadow = cv2.warpAffine(tongue, transform, (w, h))
    tongue_shadow = cv2.GaussianBlur(tongue_shadow, (0, 0), max(0.5, scale*0.002))
    blend(result*0.72, tongue_shadow*(1-tongue), 0.43)

    length = np.clip((yy-0.407)/0.083, 0, 1)
    center = 0.749-0.004*length
    across = (xx-center)/0.025
    edge = np.clip(np.abs(across), 0, 1)**1.7
    root = np.exp(-np.maximum(yy-0.405, 0)/0.015)
    tongue_color = np.empty_like(source)
    tongue_color[..., 0] = 184 + 24*length - 31*edge - 49*root
    tongue_color[..., 1] = 89 + 30*length - 19*edge - 32*root
    tongue_color[..., 2] = 94 + 30*length - 17*edge - 32*root
    highlight = np.exp(-((xx-(center-0.009))/0.009)**2) * np.clip((yy-0.423)/0.027, 0, 1)
    tongue_color += highlight[..., None]*np.array([15, 15, 13], dtype=np.float32)
    tongue_color += broad_noise[..., None]*1.7 + grain[..., None]*1.25
    blend(np.clip(tongue_color, 0, 255), tongue)

    groove = curved_mask((0.746, 0.422), [
        (0.748, 0.438, 0.750, 0.463, 0.746, 0.484),
        (0.747, 0.466, 0.746, 0.440, 0.745, 0.423),
        (0.745, 0.422, 0.746, 0.422, 0.746, 0.422)
    ], 0.0009)*tongue
    blend([116, 54, 61], groove, 0.45)
    groove_highlight = np.exp(-((xx-(center+0.0025))/0.0017)**2)
    groove_highlight *= np.exp(-((yy-0.465)/0.018)**2)*tongue
    blend([224, 153, 153], groove_highlight, 0.18)

    # Keep the upper lip lightly irregular using the original fur's fine texture.
    erosion = cv2.erode(aperture, cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3)))
    upper_edge = np.clip(aperture-erosion, 0, 1)
    upper_edge *= np.clip((0.415-yy)/0.026, 0, 1)*(1-tongue)
    blend(source*0.65, upper_edge, 0.27)

    return Image.fromarray(np.clip(np.rint(result), 0, 255).astype(np.uint8), 'RGB')
add a bouquet of red flowers
magicbrush_train_23781_1 · add / insert · execution=passed
PASSinstr 5preserve 4quality 3
source
GPT-6.1-Sol output
MagicBrush target (reference only)

A bouquet of red flowers was clearly added to the scene. The rest of the vegetable arrangement is largely unchanged, though the bouquet occludes some potatoes/carrots in the lower right. The added flowers are recognizable but look like a flat graphic overlay with lighting/style mismatch, reducing realism.

l1=0.0690 · gain=-0.0281 · mask_l1=0.0541 · preserve_l1=0.0765

reasoning / plan
{
 "visual_evidence": [
  "Red radishes fill the central area.",
  "Potatoes occupy much of the right side.",
  "Orange carrots cross the lower foreground.",
  "Green stalks and leafy vegetables surround the produce.",
  "The scene has soft natural lighting and textured surfaces."
 ],
 "target_object": "A new bouquet of red flowers",
 "target_region": "Right-side foreground, with flower heads above the potatoes and gathered stems extending toward the lower-right corner",
 "editing_intent": "Add a natural-looking bouquet of red roses resting among the vegetables.",
 "editing_plan": [
  "Construct curved green stems and shaded, veined leaves.",
  "Build seven red roses from overlapping, individually shaded petals with irregular edges and textured highlights.",
  "Gather the stems with a small natural-colored cord.",
  "Add a soft contact shadow beneath the bouquet.",
  "Antialias and composite the bouquet while preserving the surrounding vegetables."
 ],
 "preservation_constraints": [
  "Preserve the original framing and image dimensions.",
  "Keep all pixels outside the bouquet and its soft shadow unchanged.",
  "Retain the visible radishes, peas, broccoli, carrots, and surrounding greenery.",
  "Do not introduce a vase, container, text, or background replacement."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    w, h = image.size
    scale = 2
    W, H = w * scale, h * scale
    unit = float(min(W, H))
    rng = np.random.default_rng(27)
    original = np.asarray(image.convert('RGB'), dtype=np.float32)
    background = cv2.resize(original, (W, H), interpolation=cv2.INTER_CUBIC)
    premul = np.zeros((H, W, 3), np.float32)
    alpha = np.zeros((H, W), np.float32)

    def apply(mask, x0, y0, color):
        mh, mw = mask.shape
        xa, ya = max(0, x0), max(0, y0)
        xb, yb = min(W, x0 + mw), min(H, y0 + mh)
        if xb <= xa or yb <= ya:
            return
        sx, sy = xa - x0, ya - y0
        a = np.clip(mask[sy:sy + yb - ya, sx:sx + xb - xa], 0, 1)
        c = np.asarray(color, dtype=np.float32)
        if c.ndim == 3:
            c = c[sy:sy + yb - ya, sx:sx + xb - xa]
        aa = a[..., None]
        premul[ya:yb, xa:xb] = premul[ya:yb, xa:xb] * (1 - aa) + c * aa
        alpha[ya:yb, xa:xb] = alpha[ya:yb, xa:xb] * (1 - a) + a

    def stroke(points, width, color, opacity=1.0):
        pts = np.asarray(points, np.float32)
        pad = int(width + 4)
        x0 = int(np.floor(pts[:, 0].min())) - pad
        y0 = int(np.floor(pts[:, 1].min())) - pad
        x1 = int(np.ceil(pts[:, 0].max())) + pad
        y1 = int(np.ceil(pts[:, 1].max())) + pad
        mask = np.zeros((max(1, y1 - y0), max(1, x1 - x0)), np.uint8)
        q = np.round(pts - [x0, y0]).astype(np.int32)
        cv2.polylines(mask, [q], False, 255, max(1, int(round(width))), cv2.LINE_AA)
        apply(mask.astype(np.float32) / 255 * opacity, x0, y0, color)

    def cubic(p0, p1, p2, p3, n=24):
        t = np.linspace(0, 1, n, dtype=np.float32)[:, None]
        p0, p1, p2, p3 = map(lambda p: np.asarray(p, np.float32), (p0, p1, p2, p3))
        return (1-t)**3*p0 + 3*(1-t)**2*t*p1 + 3*(1-t)*t*t*p2 + t**3*p3

    def texture(shape, amplitude=1.0):
        hh, ww = shape
        small = rng.normal(0, 1, (max(3, hh // 12), max(3, ww // 12))).astype(np.float32)
        broad = cv2.resize(small, (ww, hh), interpolation=cv2.INTER_CUBIC)
        fine = rng.normal(0, 0.36, (hh, ww)).astype(np.float32)
        return amplitude * (broad + fine)

    def leaf(base, tip, breadth, tint):
        base, tip = np.asarray(base, np.float32), np.asarray(tip, np.float32)
        axis = tip - base
        length = float(np.linalg.norm(axis))
        e = axis / max(length, 1e-6)
        side = np.array([-e[1], e[0]], np.float32)
        left = cubic(base, base + axis * .30 + side * breadth, base + axis * .74 + side * breadth * .78, tip)
        right = cubic(tip, base + axis * .76 - side * breadth * .65, base + axis * .22 - side * breadth * .87, base)
        pts = np.vstack([left, right])
        x0, y0 = np.floor(pts.min(axis=0) - 3).astype(int)
        x1, y1 = np.ceil(pts.max(axis=0) + 4).astype(int)
        mask = np.zeros((y1-y0, x1-x0), np.uint8)
        cv2.fillPoly(mask, [np.round(pts-[x0,y0]).astype(np.int32)], 255, cv2.LINE_AA)
        yy, xx = np.mgrid[y0:y1, x0:x1].astype(np.float32)
        dx, dy = xx-base[0], yy-base[1]
        v = (dx*e[0]+dy*e[1]) / length
        u = (dx*side[0]+dy*side[1]) / max(breadth, 1)
        sheen = .72 + .25*np.exp(-((u+.25)/.49)**2) + .08*(1-v)
        col = np.asarray(tint)[None,None,:] * sheen[...,None]
        col += texture(mask.shape, 3.2)[...,None]
        mid = np.exp(-(u/.035)**2) * (v>.04) * (v<.97)
        col += mid[...,None] * np.array([14,23,7], np.float32)
        for fraction in (.22,.37,.52,.67,.80):
            for direction in (-1,1):
                vein = np.exp(-((v-fraction-.16*np.abs(u))/.012)**2)
                vein *= (u*direction>0) * (np.abs(u)<.82) * .55
                col += vein[...,None]*np.array([5,13,3], np.float32)
        apply(mask.astype(np.float32)/255, x0, y0, np.clip(col,0,255))

    flowers = [(.760,.480,.070), (.870,.500,.070), (.670,.520,.060), (.930,.600,.066), (.720,.600,.075), (.820,.615,.080), (.860,.720,.068)]
    stem_paths = []
    for i, (fx,fy,fr) in enumerate(flowers):
        top = np.array([fx*W, fy*H], np.float32)
        end = np.array([(0.964 + (i-3)*.003)*W, (0.980 + (i%3-1)*.009)*H], np.float32)
        p1 = top + np.array([.045*W,.16*H],np.float32)
        p2 = np.array([(.895+(i-3)*.006)*W,.855*H],np.float32)
        path = cubic(end,p2,p1,top,65)
        stem_paths.append(path)
        stroke(path, unit*.0074, (28,58,24))
        stroke(path + np.array([-unit*.0010,-unit*.0008]), unit*.0044, (71+int(i*2),112,48))
        stroke(path + np.array([-unit*.0016,-unit*.0009]), unit*.0012, (137,160,78), .65)

    leaves = [((.866,.823),(.776,.797),.031), ((.903,.854),(.849,.911),.024), ((.923,.812),(.994,.780),.032), ((.864,.735),(.948,.725),.034), ((.797,.719),(.726,.766),.037), ((.747,.598),(.633,.661),.030), ((.852,.518),(.835,.409),.030), ((.925,.611),(.987,.651),.028), ((.735,.520),(.633,.469),.026), ((.891,.891),(.849,.950),.024)]
    for j,(base,tip,breadth) in enumerate(leaves):
        b = (base[0]*W,base[1]*H)
        t = (tip[0]*W,tip[1]*H)
        stroke([b,t],unit*.0025,(48,79,30))
        leaf(b,t,breadth*unit,(54+j%3*5,96+j%4*6,39))

    def petal(cx, cy, R, angle, rho, halfwidth, depth, ring, variant):
        radial = np.array([np.cos(angle),np.sin(angle)],np.float32)
        tangent = np.array([-radial[1],radial[0]],np.float32)
        center = np.array([cx,cy],np.float32) + radial*rho*R
        pw, pd = halfwidth*R, depth*R
        skew = rng.uniform(-.13,.13)
        top = .94 + rng.uniform(-.07,.07)
        segments = [((0,-.72),(-.50,-.68),(-1.04,.00),(-.91,.48)), ((-.91,.48),(-.82,.90),(-.42,top+.09),(skew,top)), ((skew,top),(.38,top+.08),(.90,.84),(.95,.42)), ((.95,.42),(.98,.03),(.50,-.70),(0,-.72))]
        local = np.vstack([cubic(*segment,n=18) for segment in segments])
        points = center + local[:,0,None]*pw*tangent + local[:,1,None]*pd*radial
        points[:,1] = cy + (points[:,1]-cy)*.88
        x0,y0 = np.floor(points.min(axis=0)-4).astype(int)
        x1,y1 = np.ceil(points.max(axis=0)+5).astype(int)
        mask = np.zeros((y1-y0,x1-x0),np.uint8)
        cv2.fillPoly(mask,[np.round(points-[x0,y0]).astype(np.int32)],255,cv2.LINE_AA)
        yy,xx = np.mgrid[y0:y1,x0:x1].astype(np.float32)
        corrected_y = cy + (yy-cy)/.88
        dx,dy = xx-center[0],corrected_y-center[1]
        u = (dx*tangent[0]+dy*tangent[1])/max(pw,1)
        v = (dx*radial[0]+dy*radial[1])/max(pd,1)
        outer = np.clip((v+.65)/1.60,0,1)
        fold = np.exp(-((u+.33+.12*v)/.21)**2)
        illumination = .84 + .13*(-radial[0]-radial[1]) + .10*(-u*tangent[0]-u*tangent[1])
        brightness = (.46 + .54*outer**.65)*illumination
        base = np.array([192+variant,20+variant*.12,36+variant*.20],np.float32)
        col = brightness[...,None]*base
        col += fold[...,None]*np.array([17,5,7],np.float32)*outer[...,None]
        distance = cv2.distanceTransform((mask>127).astype(np.uint8),cv2.DIST_L2,5)
        rim = np.exp(-((distance-1.1)/max(.95,unit*.0010))**2)
        rim *= np.clip((v-.28)/.55,0,1)
        col += rim[...,None]*np.array([39,17,16],np.float32)
        lip = np.exp(-((v-.73+.10*u*u)/.080)**2)*np.clip(outer,0,1)
        col += lip[...,None]*np.array([15,5,5],np.float32)
        folds = np.sin(u*14+v*3)*np.sin(u*7-v*2)
        col += (folds*2.2+texture(mask.shape,2.8))[...,None]*np.array([1,.40,.44],np.float32)
        rootshade = np.exp(-((v+.48)/.22)**2)
        col *= (1-.22*rootshade)[...,None]
        a = cv2.GaussianBlur(mask.astype(np.float32)/255,(3,3),.48)
        apply(a,x0,y0,np.clip(col,0,255))

    def rose(fx,fy,fr,index):
        cx,cy,R = fx*W,fy*H,fr*unit
        rotation = rng.uniform(0,2*np.pi)
        for k in range(5):
            a = rotation+k*2*np.pi/5
            b = np.array([cx,cy]) + .31*R*np.array([np.cos(a),np.sin(a)])
            t = np.array([cx,cy]) + 1.08*R*np.array([np.cos(a+.09),np.sin(a+.09)*.88])
            leaf(b,t,.15*R,(44,79,30))
        rings = [(9,.53,.43,.47), (8,.39,.35,.38), (6,.245,.265,.285), (5,.12,.175,.19), (3,.045,.100,.125)]
        variant = rng.uniform(-12,14)
        for ring,(count,rho,pw,pd) in enumerate(rings):
            start = rotation + ring*.62
            order = list(range(count))
            for k in order:
                angle = start + k*2*np.pi/count + rng.uniform(-.095,.095)
                petal(cx,cy,R,angle,rho+rng.uniform(-.014,.014),pw*rng.uniform(.92,1.06),pd*rng.uniform(.94,1.06),ring,variant+ring*2)
        # A tiny dark, curled center gives the layered flower depth.
        t = np.linspace(0,2.7*np.pi,65)
        radius = R*(.006+.0045*t)
        spiral = np.column_stack([cx+radius*np.cos(t+rotation),cy+.88*radius*np.sin(t+rotation)])
        stroke(spiral,max(1,unit*.0013),(89,7,19),.73)
        stroke(spiral[:-12]+[-unit*.0006,-unit*.0007],max(1,unit*.0007),(222,47,57),.52)

    for index, flower in enumerate(flowers):
        rose(*flower,index)

    # Two narrow strands of raffia around the gathered stems.
    tie1 = cubic((.899*W,.867*H),(.908*W,.876*H),(.927*W,.880*H),(.941*W,.878*H),35)
    tie2 = tie1 + np.array([-unit*.001,unit*.005])
    for cord in (tie1,tie2):
        stroke(cord + [unit*.001,unit*.0018],unit*.0044,(51,45,22),.75)
        stroke(cord,unit*.0032,(171,144,88))
        stroke(cord + [-unit*.0005,-unit*.0007],unit*.0010,(218,193,131),.8)
    tail = cubic((.931*W,.880*H),(.929*W,.899*H),(.953*W,.908*H),(.945*W,.922*H),30)
    stroke(tail,unit*.0022,(178,149,91))

    # The bouquet rests on the produce: a small close shadow plus a soft falloff.
    shift = np.float32([[1,0,.009*W],[0,1,.012*H]])
    shifted = cv2.warpAffine(alpha,shift,(W,H),flags=cv2.INTER_LINEAR,borderMode=cv2.BORDER_CONSTANT)
    soft = cv2.GaussianBlur(shifted,(0,0),unit*.008)
    close = cv2.GaussianBlur(shifted,(0,0),unit*.0022)
    shadow = np.clip(.19*soft+.15*close,0,.34)
    shaded = background*(1-shadow[...,None])
    shaded += shadow[...,None]*np.array([23,17,12],np.float32)
    result = premul + shaded*(1-alpha[...,None])
    # Fine surface grain keeps the new flowers consistent with the photograph.
    grain = rng.normal(0,.65,(H,W,1)).astype(np.float32)
    result += grain*alpha[...,None]
    result = cv2.resize(result,(w,h),interpolation=cv2.INTER_AREA)
    affected = cv2.resize(np.maximum(alpha,np.clip(soft+close,0,1)),(w,h),interpolation=cv2.INTER_AREA)
    result[affected<.0005] = original[affected<.0005]
    return Image.fromarray(np.clip(result,0,255).astype(np.uint8),'RGB')
Replace the mirror with a window.
magicbrush_train_192047_1 · replace / change · execution=passed
PASSinstr 5preserve 5quality 4
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The mirror was correctly replaced with a window in the same location, while the sink, wall, tiles, outlet, and towel ring remain unchanged. The edit is visually coherent overall, though the window and outdoor view look slightly pasted-on and flatter than the surrounding lighting.

l1=0.0364 · gain=0.0037 · mask_l1=0.0020 · preserve_l1=0.0827

reasoning / plan
{
 "visual_evidence": [
  "A tall, narrow mirror hangs above the sink on the left wall.",
  "Its outline is a perspective quadrilateral with a thin light-colored edge.",
  "The wall is muted gray-green, with white tile below.",
  "An electrical outlet is left of the mirror; the faucet and towel ring are below and to its right."
 ],
 "target_object": "The wall-mounted mirror",
 "target_region": "The tall quadrilateral in the upper-left portion of the image, above the sink",
 "editing_intent": "Replace the mirror with a recessed, realistically shaded window showing subdued daylight and distant foliage.",
 "editing_plan": [
  "Mask the mirror, including its thin edge, and inpaint the small areas that will remain exposed around the replacement.",
  "Synthesize a softly textured outdoor view with overcast sky and layered distant foliage.",
  "Construct a pale window frame, recessed glazing, horizontal sash rail, beveled edges, and a shallow sill.",
  "Perspective-warp the window to match the mirror's position on the wall.",
  "Add a restrained cast shadow, feather the perimeter, and preserve all surrounding bathroom fixtures."
 ],
 "preservation_constraints": [
  "Keep the sink, faucet, towel ring, electrical outlet, and soap dish unchanged.",
  "Preserve the wall corner and tile layout.",
  "Do not change the image dimensions or camera perspective.",
  "Limit changes to the mirror footprint and its immediate mounting boundary."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    image = image.convert('RGB')
    w, h = image.size
    src = np.asarray(image).copy()
    rng = np.random.default_rng(27)
    scale = min(w, h) / 512.0

    def points(coords):
        return np.array([(x*w, y*h) for x, y in coords], np.float32)

    old_outline = points([(0.189,0.006),(0.173,0.034),(0.205,0.495),
                          (0.217,0.525),(0.465,0.479),(0.430,0.046)])
    removal = np.zeros((h,w), np.uint8)
    cv2.fillPoly(removal, [np.round(old_outline).astype(np.int32)], 255)
    radius = max(1, int(round(2*scale)))
    removal = cv2.dilate(removal, cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2*radius+1,2*radius+1)))
    repaired = cv2.inpaint(src, removal, max(2, int(round(4*scale))), cv2.INPAINT_TELEA).astype(np.float32)
    repair_noise = rng.normal(0, 0.65, (h,w,1)).astype(np.float32)
    repaired += repair_noise * (removal[...,None]/255.0)

    cw = max(64, int(round(w*0.40)))
    ch = max(96, int(round(h*0.68)))
    yy, xx = np.mgrid[0:ch,0:cw].astype(np.float32)
    u = xx / max(1,cw-1)
    v = yy / max(1,ch-1)

    def noise(nx, ny, blur=0.0):
        a = rng.normal(0,1,(max(2,ny),max(2,nx))).astype(np.float32)
        a = cv2.resize(a, (cw,ch), interpolation=cv2.INTER_CUBIC)
        if blur > 0:
            a = cv2.GaussianBlur(a,(0,0),blur)
        return a

    wall_patch = src[int(h*0.10):max(int(h*0.10)+1,int(h*0.34)), int(w*0.50):max(int(w*0.50)+1,int(w*0.61))]
    wall = np.median(wall_patch.reshape(-1,3),axis=0).astype(np.float32)
    grain = rng.normal(0,0.62,(ch,cw)).astype(np.float32)
    fine = noise(45,65)*0.65 + grain
    broad = noise(6,9)*0.75
    frame_color = np.clip(wall + np.array([39,39,37],np.float32),0,255)
    panel = np.zeros((ch,cw,3),np.float32)

    def rect(x0,y0,x1,y1,color,shade=0):
        mask = (u>=x0)&(u<=x1)&(v>=y0)&(v<=y1)
        col = np.asarray(color,np.float32)
        tex = fine + broad + shade + 2.5*(1-u) - 1.7*v
        panel[mask] = (col[None,None,:] + tex[...,None])[mask]

    # Outer mounting edge, bevel, and the substantial painted frame.
    rect(0,0,1,1,wall+np.array([-27,-23,-24]))
    rect(0.012,0.008,0.989,0.994,frame_color-12)
    rect(0.026,0.017,0.970,0.981,frame_color)
    rect(0.026,0.017,0.055,0.981,frame_color+14)
    rect(0.055,0.017,0.968,0.031,frame_color+10)
    rect(0.957,0.028,0.973,0.980,frame_color-20)
    rect(0.043,0.967,0.957,0.984,frame_color-17)
    # The dark reveal remains visible between the frame and glazing.
    rect(0.081,0.052,0.919,0.947,wall-51)
    rect(0.096,0.062,0.904,0.937,frame_color-45)
    rect(0.104,0.068,0.896,0.929,frame_color-23)

    gx0,gy0,gx1,gy1 = 0.124,0.079,0.881,0.918
    gu = (u-gx0)/(gx1-gx0)
    gv = (v-gy0)/(gy1-gy0)
    cloud = noise(5,7,1.1)*2.2 + noise(11,13,0.8)*0.8
    sky_top = np.clip(wall+np.array([34,45,50]),0,240)
    sky_bottom = np.clip(wall+np.array([48,54,51]),0,245)
    blend = np.clip(gv,0,1)
    outdoors = sky_top[None,None,:]*(1-blend[...,None]) + sky_bottom[None,None,:]*blend[...,None]
    outdoors += cloud[...,None]

    # Organic, overlapping tree lines built from correlated multi-scale noise.
    silhouette = noise(13,3,1.0)
    midtexture = noise(25,38,0.45)
    leaftexture = noise(80,115,0.35)
    leafgrain = noise(130,170,0.20)
    for layer in range(3):
        ridge = cv2.resize(rng.normal(0,1,(1,15+layer*8)).astype(np.float32),(cw,1),interpolation=cv2.INTER_CUBIC)[0]
        ridge = cv2.GaussianBlur(ridge[None,:],(0,0),max(0.5,cw*0.008))[0]
        top = (0.58 + layer*0.105) + 0.044*ridge[None,:] + 0.012*silhouette
        broken_edge = gv-top + 0.009*leaftexture
        foliage_alpha = np.clip(broken_edge*(85+layer*10),0,1)
        foliage_alpha = cv2.GaussianBlur(foliage_alpha.astype(np.float32),(0,0),0.45)
        bases = [np.array([101,119,102]),np.array([79,101,78]),np.array([61,83,59])]
        texture = 5.5*midtexture + 4.0*leaftexture + 1.6*leafgrain
        green = np.empty((ch,cw,3),np.float32)
        green[:] = bases[layer]
        green += texture[...,None]*np.array([0.85,1.0,0.65],np.float32)
        green += (3.5*(1-gu))[...,None]
        outdoors = outdoors*(1-foliage_alpha[...,None]) + green*foliage_alpha[...,None]

    # Subtle glass tint, daylight haze, and a soft reflected highlight.
    outdoors = outdoors*0.93 + np.array([157,177,172],np.float32)[None,None,:]*0.07
    reflection = np.exp(-((gu-0.13)/0.12)**2)*(0.018+0.035*np.clip(1-gv,0,1))
    outdoors = outdoors*(1-reflection[...,None]) + frame_color[None,None,:]*reflection[...,None]
    outdoors += rng.normal(0,0.55,(ch,cw,1)).astype(np.float32)
    glazing = (u>=gx0)&(u<=gx1)&(v>=gy0)&(v<=gy1)
    panel[glazing] = outdoors[glazing]

    # Glazing seals and the upper/lower sash meeting rail.
    rect(0.112,0.074,0.124,0.922,frame_color-49)
    rect(0.881,0.074,0.893,0.922,frame_color-55)
    rect(0.112,0.073,0.893,0.080,frame_color-36)
    rect(0.112,0.919,0.893,0.930,frame_color-35)
    rect(0.098,0.491,0.906,0.525,frame_color-28)
    rect(0.096,0.489,0.906,0.514,frame_color)
    rect(0.100,0.489,0.902,0.495,frame_color+13)
    rect(0.103,0.512,0.900,0.520,frame_color-20)
    # A shallow lower sill with a shaded underside.
    rect(0.035,0.945,0.974,0.979,frame_color+2)
    rect(0.035,0.945,0.974,0.953,frame_color+13)
    rect(0.044,0.975,0.976,0.992,frame_color-22)
    panel = np.clip(panel,0,255).astype(np.uint8)

    destination = points([(0.188,0.012),(0.427,0.052),(0.461,0.477),(0.218,0.520)])
    canonical = np.array([[0,0],[cw-1,0],[cw-1,ch-1],[0,ch-1]],np.float32)
    transform = cv2.getPerspectiveTransform(canonical,destination)
    warped = cv2.warpPerspective(panel,transform,(w,h),flags=cv2.INTER_LINEAR,borderMode=cv2.BORDER_REPLICATE).astype(np.float32)
    canonical_alpha = np.ones((ch,cw),np.float32)
    canonical_alpha[[0,-1],:] = 0
    canonical_alpha[:,[0,-1]] = 0
    alpha = cv2.warpPerspective(canonical_alpha,transform,(w,h),flags=cv2.INTER_LINEAR,borderMode=cv2.BORDER_CONSTANT,borderValue=0)
    alpha = cv2.GaussianBlur(alpha,(0,0),max(0.35,0.52*scale))
    alpha = np.clip(alpha,0,1)

    # Cast a small, soft mounting shadow primarily to the right and below.
    shift = np.float32([[1,0,2.6*scale],[0,1,2.1*scale]])
    shadow = cv2.warpAffine(alpha,shift,(w,h),flags=cv2.INTER_LINEAR,borderMode=cv2.BORDER_CONSTANT)
    shadow = cv2.GaussianBlur(shadow,(0,0),max(0.55,2.1*scale))
    shadow *= (1-alpha)
    shadow[shadow<0.003] = 0
    base = repaired*(1-0.16*shadow[...,None])
    result = base*(1-alpha[...,None]) + warped*alpha[...,None]

    # Keep every pixel outside the edited footprint and narrow shadow unchanged.
    changed = (removal>0)|(alpha>0.001)|(shadow>0)
    result[~changed] = src[~changed]
    return Image.fromarray(np.clip(result,0,255).astype(np.uint8), 'RGB')
add a shark in the water
magicbrush_train_251888_2 · add / insert · execution=passed
PASSinstr 5preserve 5quality 4
source
GPT-6.1-Sol output
MagicBrush target (reference only)

A shark fin has been added in the water, clearly satisfying the requested edit. The city skyline, boat, and other unrelated content are preserved. The shark fin is reasonably blended into the water, though it looks slightly oversized and a bit artificial.

l1=0.0029 · gain=-0.0009 · mask_l1=0.0001 · preserve_l1=0.0058

reasoning / plan
{
 "visual_evidence": [
  "Blue-gray harbor water occupies the lower part of the image.",
  "A sailing vessel sits on the left side of the water.",
  "Dense high-rise buildings and hazy hills fill the background.",
  "Open water in the lower-right foreground provides space for the addition."
 ],
 "target_object": "A partly submerged shark with a visible dorsal fin and back",
 "target_region": "Open foreground water to the right of the sailing vessel",
 "editing_intent": "Add a realistically shaded shark breaking the water surface, with a subdued submerged body, reflection, and small surrounding ripples.",
 "editing_plan": [
  "Create antialiased curved masks for the submerged body, exposed back, and dorsal fin.",
  "Blend the submerged silhouette with the existing water texture.",
  "Render the dorsal fin with curved shading, fine grain, and softly feathered edges.",
  "Add a faint water reflection and localized shadow beneath the shark.",
  "Add broken waterline ripples around the back and fin while preserving the rest of the image."
 ],
 "preservation_constraints": [
  "Do not change the sailing vessel, its rigging, or flags.",
  "Preserve the buildings, signs, shoreline, hills, and sky.",
  "Keep the existing water texture outside the localized shark and ripple area.",
  "Match the scene's muted colors and diffuse lighting."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    w, h = image.size
    original = np.asarray(image.convert('RGB'), dtype=np.float32)
    out = original.copy()
    rng = np.random.default_rng(17)
    yy, xx = np.mgrid[0:h, 0:w].astype(np.float32)
    X, Y = xx / float(w), yy / float(h)
    ss = 3

    def bezier(p0, p1, p2, p3, count=60):
        t = np.linspace(0.0, 1.0, count)[:, None]
        a, b, c, d = [np.asarray(p, dtype=np.float32)[None, :] for p in (p0, p1, p2, p3)]
        return (1-t)**3*a + 3*(1-t)**2*t*b + 3*(1-t)*t**2*c + t**3*d

    def curved_mask(segments, feather=0.45):
        points = np.concatenate([bezier(*s) for s in segments], axis=0)
        points = np.rint(points * np.array([w*ss, h*ss])).astype(np.int32)
        canvas = np.zeros((h*ss, w*ss), dtype=np.uint8)
        cv2.fillPoly(canvas, [points], 255)
        m = cv2.resize(canvas, (w, h), interpolation=cv2.INTER_AREA).astype(np.float32)/255.0
        if feather > 0:
            m = cv2.GaussianBlur(m, (0, 0), feather * w / 512.0)
        return m

    def stroke_mask(segments, thickness):
        canvas = np.zeros((h*ss, w*ss), dtype=np.uint8)
        for s in segments:
            p = bezier(*s, count=90)
            p = np.rint(p*np.array([w*ss, h*ss])).astype(np.int32)
            cv2.polylines(canvas, [p], False, 255, max(1, int(round(thickness*w*ss))), cv2.LINE_AA)
        return cv2.resize(canvas, (w, h), interpolation=cv2.INTER_AREA).astype(np.float32)/255.0

    def blend(color, alpha):
        nonlocal out
        a = np.clip(alpha, 0, 1)[..., None]
        out = out*(1-a) + np.asarray(color, dtype=np.float32)*a

    water = np.median(original[int(.81*h):int(.98*h), int(.43*w):int(.95*w)], axis=(0,1))
    noise = rng.normal(0, 1, (h, w)).astype(np.float32)
    grain = cv2.GaussianBlur(noise, (0,0), max(.4, .0012*w))

    body = curved_mask([
        ((.546,.930),(.570,.916),(.611,.909),(.655,.914)),
        ((.655,.914),(.709,.913),(.774,.919),(.819,.930)),
        ((.819,.930),(.832,.930),(.842,.924),(.851,.925)),
        ((.851,.925),(.839,.937),(.826,.940),(.813,.941)),
        ((.813,.941),(.737,.953),(.616,.952),(.563,.941)),
        ((.563,.941),(.551,.938),(.544,.935),(.546,.930))
    ], feather=1.7)
    tail = curved_mask([
        ((.818,.934),(.839,.925),(.851,.911),(.871,.900)),
        ((.871,.900),(.864,.920),(.854,.931),(.847,.936)),
        ((.847,.936),(.857,.943),(.866,.951),(.872,.960)),
        ((.872,.960),(.853,.953),(.838,.945),(.818,.934))
    ], feather=2.1)
    underwater_color = original*.63 + (water*np.array([.59,.64,.65]))[None,None,:]*.37
    blend(underwater_color, body*.48)
    blend(underwater_color, tail*.19)

    shadow = np.exp(-(((X-.686)/.083)**2 + ((Y-.937)/.012)**2)*1.5)
    blend(water*np.array([.64,.69,.70]), shadow*.18)

    fin = curved_mask([
        ((.619,.925),(.638,.907),(.648,.866),(.663,.847)),
        ((.663,.847),(.666,.843),(.670,.844),(.672,.849)),
        ((.672,.849),(.676,.870),(.676,.892),(.689,.906)),
        ((.689,.906),(.699,.916),(.713,.919),(.727,.926)),
        ((.727,.926),(.697,.931),(.646,.930),(.619,.925))
    ], feather=.40)

    map_x = (xx + np.sin(Y*410.0)*(.003*w)).astype(np.float32)
    map_y = ((.926-(Y-.926)/.47)*h).astype(np.float32)
    reflected = cv2.remap(fin, map_x, map_y, cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT, borderValue=0)
    reflected *= (Y>.928).astype(np.float32)*np.exp(-np.maximum(Y-.928,0)/.022)
    reflected = cv2.GaussianBlur(reflected, (0,0), max(.5,.0015*w))
    blend(water*np.array([.62,.68,.70]), reflected*.23)

    back = curved_mask([
        ((.567,.932),(.590,.920),(.626,.914),(.655,.919)),
        ((.655,.919),(.701,.919),(.752,.920),(.790,.932)),
        ((.790,.932),(.740,.936),(.677,.937),(.622,.936)),
        ((.622,.936),(.597,.938),(.576,.936),(.567,.932))
    ], feather=.65)
    back_light = np.exp(-((Y-.923)/.009)**2)
    back_color = np.empty_like(original)
    for c in range(3):
        back_color[:,:,c] = [61,78,81][c] + back_light*[25,27,24][c] + grain*1.9
    blend(back_color, back*.66)

    left = np.zeros(h, dtype=np.float32)
    right = np.ones(h, dtype=np.float32)*w
    for row in range(h):
        indices = np.flatnonzero(fin[row]>.35)
        if indices.size:
            left[row] = indices[0]
            right[row] = indices[-1]
    cross = np.clip((xx-left[:,None])/np.maximum(right-left,1)[:,None],0,1)
    height = np.clip((.927-Y)/.082,0,1)
    light = .14 + .73*(1-cross)**1.35 + .12*height
    light -= .07*np.exp(-((cross-.87)/.09)**2)
    fin_color = np.empty_like(original)
    for c in range(3):
        fin_color[:,:,c] = [48,62,67][c] + light*[48,48,42][c] + grain*2.0 + noise*.65
    # Subtle tonal streaks follow the fin's sloping surface, not its boundary.
    streak = np.sin((cross*8.5 + height*.8)*np.pi)*1.0
    fin_color += streak[:,:,None]
    blend(fin_color, fin*.98)

    leading = stroke_mask([
        ((.621,.923),(.638,.905),(.649,.866),(.664,.848))
    ], .00115)
    blend(np.array([119,133,132],dtype=np.float32), leading*fin*.27)

    # Soft water coverage at the base keeps the fin rooted in the surface.
    waterline = np.exp(-((Y-.929)/.0028)**2)*np.exp(-((X-.674)/.064)**4)
    blend(original, waterline*.34)

    outer_ripples = stroke_mask([
        ((.535,.935),(.542,.943),(.565,.947),(.590,.947)),
        ((.603,.948),(.626,.951),(.648,.952),(.670,.951)),
        ((.688,.951),(.724,.951),(.765,.949),(.787,.944)),
        ((.801,.943),(.820,.940),(.833,.936),(.842,.932)),
        ((.559,.920),(.574,.915),(.590,.913),(.606,.914)),
        ((.734,.922),(.764,.924),(.789,.927),(.805,.931))
    ], .00125)
    ripple_color = water + np.array([31,33,29],dtype=np.float32)
    ripple_texture = np.clip(.71+grain*.15, .32,1)
    blend(ripple_color, outer_ripples*ripple_texture*.41)

    contact_ripples = stroke_mask([
        ((.574,.933),(.590,.938),(.607,.938),(.622,.936)),
        ((.620,.928),(.639,.932),(.657,.933),(.673,.932)),
        ((.678,.932),(.696,.933),(.716,.931),(.732,.932)),
        ((.744,.935),(.756,.937),(.774,.936),(.789,.934))
    ], .0017)
    blend(water+np.array([43,43,36],dtype=np.float32), contact_ripples*np.clip(.65+noise*.12,.25,.95)*.60)

    dark_ripples = stroke_mask([
        ((.551,.940),(.565,.944),(.582,.944),(.598,.943)),
        ((.689,.944),(.722,.946),(.758,.943),(.778,.941))
    ], .0011)
    blend(water*np.array([.76,.81,.83]), dark_ripples*.35)
    return Image.fromarray(np.clip(out,0,255).astype(np.uint8), 'RGB')
Put a pizza next to the hotdog.
magicbrush_train_570259_3 · add / insert · execution=passed
FAILinstr 3preserve 5quality 3
source
GPT-6.1-Sol output
MagicBrush target (reference only)

A pizza was added, but it is placed on the lower-left area of the plate rather than clearly next to the hotdog. Unrelated food items and the rest of the scene are preserved well, but the pizza looks flat and cartoon-like compared with the photographic image.

l1=0.1198 · gain=-0.0069 · mask_l1=0.0168 · preserve_l1=0.1469

reasoning / plan
{
 "visual_evidence": [
  "A hotdog with mustard sits in a bun at the upper right of the plate.",
  "A white bowl of red soup occupies the upper left.",
  "Lettuce, tomato slices, and white onion rings occupy the lower part of the plate.",
  "A strip of exposed plate lies below the bowl and to the lower left of the hotdog."
 ],
 "target_object": "A new small pizza beside the hotdog",
 "target_region": "The plate below the soup bowl and immediately lower-left of the hotdog, extending slightly over the upper edge of the lettuce.",
 "editing_intent": "Add a realistically textured, perspective-shaped pepperoni pizza without changing the hotdog or soup.",
 "editing_plan": [
  "Identify a compact elliptical footprint on the plate beside the hotdog.",
  "Create a soft cast shadow and a shaded, irregular baked-crust edge.",
  "Build tomato sauce and melted cheese using multiscale texture, uneven boundaries, and browned patches.",
  "Add perspective-matched pepperoni with curled edges, fat flecks, and small shadows.",
  "Feather the pizza boundary and retain foreground tomato and lower lettuce where they naturally overlap.",
  "Preserve the original pixels outside the pizza and its local shadow."
 ],
 "preservation_constraints": [
  "Keep the hotdog, mustard, and bun unchanged.",
  "Keep the soup and white bowl unchanged.",
  "Keep the onion rings and tomato slices unchanged.",
  "Preserve lettuce outside the small area naturally covered by the pizza.",
  "Do not alter the framing or plate outside the local addition."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    w, h = image.size
    original = np.asarray(image.convert('RGB'), dtype=np.float32)
    canvas = original.copy()
    rng = np.random.default_rng(2718)
    yy, xx = np.mgrid[0:h, 0:w].astype(np.float32)
    x = (xx + 0.5) / w
    y = (yy + 0.5) / h
    cx, cy, rx, ry = 0.220, 0.613, 0.208, 0.095
    u = (x - cx) / rx
    v = (y - cy) / ry
    theta = np.arctan2(v, u)
    radius = np.sqrt(u*u + v*v)
    aa = 0.85 / max(1.0, min(rx*w, ry*h))

    def texture(scale):
        nw = max(3, int(w * scale))
        nh = max(3, int(h * scale))
        small = rng.normal(0, 1, (nh, nw)).astype(np.float32)
        field = cv2.resize(small, (w, h), interpolation=cv2.INTER_CUBIC)
        return field / max(float(field.std()), 0.01)

    def edge(distance, limit, softness=aa):
        z = np.clip((limit - distance) / max(softness, 1e-6) + 0.5, 0, 1)
        return z*z*(3-2*z)

    def layer(color, alpha):
        a = np.clip(alpha, 0, 1)[..., None]
        canvas[:] = canvas*(1-a) + np.asarray(color, dtype=np.float32)*a

    def blur(mask, sx, sy=None):
        return cv2.GaussianBlur(mask.astype(np.float32), (0, 0), max(sx, 0.35), sigmaY=max(sy if sy is not None else sx, 0.35))

    coarse = texture(0.035)
    medium = texture(0.12)
    fine = texture(0.48)
    grain = rng.normal(0, 1, (h, w)).astype(np.float32)
    plate_sample = original[int(0.52*h):max(int(0.56*h), int(0.52*h)+1), int(0.025*w):max(int(0.14*w), int(0.025*w)+1)]
    illumination = float(np.clip(plate_sample.mean()/182.0, 0.80, 1.06)) if plate_sample.size else 0.92
    irregular = 1 + 0.012*np.sin(7*theta+0.8) + 0.007*np.sin(13*theta-0.4) + 0.004*medium
    rho = radius / irregular
    top_mask = edge(rho, 1.0)
    safe = edge(0.515-y, 0, 0.006)

    shadow_r = np.sqrt(((x-cx-0.007)/(rx*1.025))**2 + ((y-cy-0.016)/(ry*1.045))**2)
    shadow = blur(edge(shadow_r, 1), 0.008*w, 0.006*h) * 0.30 * safe
    layer(original * np.array([0.64, 0.61, 0.58], dtype=np.float32), shadow)
    contact_r = np.sqrt(((x-cx-0.002)/(rx*1.003))**2 + ((y-cy-0.011)/(ry*1.02))**2)
    contact = blur(edge(contact_r, 1), 0.0025*w, 0.0025*h) * 0.35 * safe
    layer(original * 0.43, contact)

    side_v = (y-cy-0.010)/ry
    side_theta = np.arctan2(side_v, u)
    side_r = np.sqrt(u*u + side_v*side_v) / (1+0.012*np.sin(7*side_theta+0.8)+0.007*np.sin(13*side_theta-0.4))
    side_mask = edge(side_r, 1.0)*safe
    side_light = 8*coarse + 3*medium + 2*grain - 8*u - 11*side_v
    side_color = np.stack([137+side_light, 88+0.82*side_light, 40+0.55*side_light], axis=-1)*illumination
    layer(np.clip(side_color, 0, 255), side_mask)

    lighting = -10*u - 14*v
    ridge = 17*np.exp(-((rho-0.90)/0.065)**2)
    baked_edge = 30*np.clip((rho-0.94)/0.06, 0, 1)
    crust_variation = 10*coarse + 5*medium + 2.5*fine + 1.5*grain + lighting + ridge - baked_edge
    char = np.zeros((h, w), np.float32)
    for i in range(35):
        ang = rng.uniform(0, 2*np.pi)
        rr = rng.uniform(0.855, 0.978)
        pu, pv = rr*np.cos(ang), rr*np.sin(ang)
        su, sv = rng.uniform(0.014, 0.055), rng.uniform(0.016, 0.046)
        char += rng.uniform(8, 34)*np.exp(-0.5*(((u-pu)/su)**2+((v-pv)/sv)**2))
    crust_color = np.stack([202+crust_variation-char*0.65, 146+crust_variation*0.85-char, 77+crust_variation*0.55-char*0.62], axis=-1)*illumination
    layer(np.clip(crust_color, 0, 255), top_mask*safe)

    sauce_limit = 0.846 + 0.009*coarse + 0.008*np.sin(11*theta)
    sauce_mask = edge(rho, sauce_limit)*top_mask*safe
    sauce_variation = 9*coarse + 6*medium + 2*fine + lighting*0.45
    sauce_color = np.stack([161+sauce_variation, 61+sauce_variation*0.60, 27+sauce_variation*0.30], axis=-1)*illumination
    layer(np.clip(sauce_color, 0, 255), sauce_mask)

    cheese_limit = 0.803 + 0.020*coarse + 0.008*np.sin(9*theta+0.4)
    cheese_mask = edge(rho, cheese_limit, aa*1.2)*sauce_mask
    cheese_variation = 9*coarse + 4*medium + 1.8*fine + 1.2*grain + lighting*0.60
    golden = np.clip(0.6*coarse+0.45*medium, -1.5, 2.0)
    cheese_color = np.stack([232+cheese_variation-3*golden, 189+cheese_variation*0.88-10*golden, 105+cheese_variation*0.65-15*golden], axis=-1)*illumination
    layer(np.clip(cheese_color, 0, 255), cheese_mask)

    browning = np.zeros((h, w), np.float32)
    for i in range(36):
        ang = rng.uniform(0, 2*np.pi)
        rr = np.sqrt(rng.uniform(0, 1))*0.74
        pu, pv = rr*np.cos(ang), rr*np.sin(ang)
        su, sv = rng.uniform(0.015, 0.07), rng.uniform(0.014, 0.06)
        patch = np.exp(-0.5*(((u-pu)/su)**2+((v-pv)/sv)**2))
        browning += rng.uniform(0.12, 0.55)*patch
    browning = np.clip(browning, 0, 0.72)*cheese_mask
    baked_color = np.stack([166+5*medium, 104+4*medium, 43+2*medium], axis=-1)*illumination
    layer(baked_color, browning)
    small_blisters = np.clip((fine-1.5)*0.075, 0, 0.13)*cheese_mask
    layer(np.array([150, 93, 36])*illumination, small_blisters)
    sheen = np.clip((coarse+0.35*medium-0.8)*0.07, 0, 0.10)*cheese_mask
    layer(np.array([254, 222, 161])*illumination, sheen)

    toppings = [(-0.43, -0.30, 0.195), (0.22, -0.38, 0.192), (0.48, 0.19, 0.180), (-0.08, 0.22, 0.207), (-0.48, 0.38, 0.174)]
    for pu, pv, pr in toppings:
        a = (u-pu)/pr
        b = (v-pv)/pr
        angle = np.arctan2(b, a)
        rad = np.sqrt(a*a+b*b)/(1+0.023*np.sin(5*angle+pu*9)+0.014*np.sin(9*angle))
        pmask = edge(rad, 1, aa/pr)*cheese_mask
        oil = np.exp(-((rad-1.08)/0.18)**2)*0.12*cheese_mask
        layer(np.array([222, 143, 53])*illumination, oil)
        sr = np.sqrt(((u-pu-0.010)/pr)**2+((v-pv-0.025)/pr)**2)
        pshadow = blur(edge(sr, 1, aa/pr), 0.0018*w, 0.0015*h)*0.30*cheese_mask
        layer(np.array([112, 66, 25])*illumination, pshadow)
        rim_dark = 27*np.exp(-((rad-0.94)/0.095)**2)
        inner = 10*np.exp(-(rad/0.68)**2)
        pvar = 7*medium + 3.5*fine + 1.9*grain - 5*a - 7*b + inner-rim_dark
        pepper_color = np.stack([164+pvar, 61+pvar*0.68, 32+pvar*0.43], axis=-1)*illumination
        layer(np.clip(pepper_color, 0, 255), pmask)
        fat = np.zeros((h, w), np.float32)
        specks = np.zeros((h, w), np.float32)
        for j in range(19):
            ang = rng.uniform(0, 2*np.pi)
            rr = np.sqrt(rng.uniform(0, 1))*0.83
            qa, qb = rr*np.cos(ang), rr*np.sin(ang)
            scale = rng.uniform(0.034, 0.075)
            spot = np.exp(-0.5*(((a-qa)/scale)**2+((b-qb)/(scale*0.75))**2))
            fat += spot*rng.uniform(0.35, 0.70)
        for j in range(8):
            ang = rng.uniform(0, 2*np.pi)
            rr = np.sqrt(rng.uniform(0, 1))*0.86
            qa, qb = rr*np.cos(ang), rr*np.sin(ang)
            scale = rng.uniform(0.025, 0.050)
            specks += np.exp(-0.5*(((a-qa)/scale)**2+((b-qb)/scale)**2))*0.45
        layer(np.array([226, 159, 100])*illumination, np.clip(fat, 0, 0.8)*pmask)
        layer(np.array([83, 37, 22])*illumination, np.clip(specks, 0, 0.5)*pmask)
        highlight = np.exp(-0.5*(((a+0.35)/0.48)**2+((b+0.43)/0.20)**2))*0.13
        layer(np.array([237, 136, 83])*illumination, highlight*pmask)

    # Keep the existing foreground tomato and the lowest lettuce leaves in front.
    r, g, b = original[..., 0], original[..., 1], original[..., 2]
    tomato = ((x > 0.355) & (y > 0.59) & (r > 75) & (r > g*1.22) & (r > b*1.35)).astype(np.uint8)
    tomato = cv2.morphologyEx(tomato, cv2.MORPH_CLOSE, np.ones((3, 3), np.uint8))
    tomato = cv2.dilate(tomato, np.ones((3, 3), np.uint8), iterations=1).astype(np.float32)
    tomato = blur(tomato, max(0.001*w, 0.4))
    lettuce = ((y > 0.702) & (g > r*1.12) & (g > b*1.08)).astype(np.float32)
    lettuce = blur(lettuce, max(0.001*w, 0.4))
    foreground = np.maximum(tomato, lettuce)[..., None]
    canvas = canvas*(1-foreground)+original*foreground
    # The bowl and hotdog are protected from even faint shadow spill.
    protect = ((y < 0.515) | (x > 0.485))
    canvas[protect] = original[protect]
    return Image.fromarray(np.clip(np.rint(canvas), 0, 255).astype(np.uint8), 'RGB')
add a bottle of olive oil
magicbrush_train_328270_3 · add / insert · execution=passed
PASSinstr 5preserve 5quality 4
source
GPT-6.1-Sol output
MagicBrush target (reference only)

A clearly identifiable bottle labeled olive oil was added to the scene, placed on the counter near the back right. The rest of the image is essentially unchanged. The bottle is reasonably integrated, though its lighting and sharpness are slightly artificial compared with the photo.

l1=0.0202 · gain=-0.0019 · mask_l1=0.0001 · preserve_l1=0.0432

reasoning / plan
{
 "visual_evidence": [
  "A person is working with dough on a baking tray.",
  "The work surface is dark and holds a pizza in the foreground.",
  "A tall white ceramic crock stands at the right edge.",
  "There is a narrow dark surface area immediately left of the crock, behind the person's hands."
 ],
 "target_object": "A new bottle of olive oil",
 "target_region": "The rear-right work surface, immediately left of the white crock and behind the hands",
 "editing_intent": "Add a small upright olive oil bottle with dark green glass, a gold cap, and a cream label.",
 "editing_plan": [
  "Position the bottle in the narrow space left of the crock without covering the hands.",
  "Construct an antialiased glass silhouette with a narrow neck, rounded shoulders, and a thick base.",
  "Render olive-colored contents, curved shading, reflections, a ridged cap, and an olive oil label.",
  "Add a restrained contact shadow on the surface beneath the bottle.",
  "Match texture and blend the rendered pixels while preserving the surrounding scene."
 ],
 "preservation_constraints": [
  "Keep the person, arms, and hands unchanged.",
  "Preserve the pizza, toppings, flour, dough, and baking tray.",
  "Do not alter the white crock or rolling pin.",
  "Preserve the refrigerator, chair, and background.",
  "Leave pixels outside the bottle and its small shadow unchanged."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    source = np.asarray(image.convert('RGB'), dtype=np.float32)
    w, h = image.size
    scale = 4
    x0 = max(0, int(np.floor(0.803 * w)))
    y0 = max(0, int(np.floor(0.244 * h)))
    x1 = min(w, int(np.ceil(0.947 * w)))
    y1 = min(h, int(np.ceil(0.558 * h)))
    rw, rh = x1 - x0, y1 - y0
    W, H = rw * scale, rh * scale
    original = source[y0:y1, x0:x1]
    background = cv2.resize(original, (W, H), interpolation=cv2.INTER_CUBIC)
    canvas = background.copy()
    cx, top = 0.876 * w, 0.255 * h
    bw, bh = 0.070 * w, 0.267 * h
    yy, xx = np.mgrid[0:H, 0:W].astype(np.float32)
    gx = x0 + (xx + 0.5) / scale
    gy = y0 + (yy + 0.5) / scale
    u = (gx - cx) / bw
    v = (gy - top) / bh
    rng = np.random.default_rng(71)
    grain = cv2.resize(rng.normal(0, 1, (rh, rw)).astype(np.float32), (W, H), interpolation=cv2.INTER_LINEAR)

    def point(a, b):
        return (int(round((cx + a * bw - x0) * scale)), int(round((top + b * bh - y0) * scale)))

    def polygon(points):
        m = np.zeros((H, W), np.float32)
        p = np.array([point(a, b) for a, b in points], np.int32)
        cv2.fillPoly(m, [p], 1.0, lineType=cv2.LINE_AA)
        return m

    def ellipse(a, b, ra, rb):
        m = np.zeros((H, W), np.float32)
        cv2.ellipse(m, point(a, b), (max(1, int(ra * bw * scale)), max(1, int(rb * bh * scale))), 0, 0, 360, 1.0, -1, cv2.LINE_AA)
        return m

    def stroke(points, thickness):
        m = np.zeros((H, W), np.float32)
        p = np.array([point(a, b) for a, b in points], np.int32)
        cv2.polylines(m, [p], False, 1.0, max(1, int(thickness * bw * scale)), cv2.LINE_AA)
        return m

    def soften(mask, amount):
        return cv2.GaussianBlur(mask, (0, 0), max(0.35, amount * scale))

    def lay(color, mask, opacity=1.0):
        nonlocal canvas
        alpha = np.clip(mask * opacity, 0, 1)[..., None]
        c = np.asarray(color, np.float32)
        canvas = canvas * (1 - alpha) + c * alpha

    # Soft, compact surface shadow; keep it off the white crock.
    shadow = ellipse(0.04, 1.018, 0.61, 0.027)
    shadow = soften(shadow, 0.007 * h)
    crock_guard = np.clip((0.912 * w - gx) / max(0.003 * w, 0.1), 0, 1)
    lay(np.array([9, 11, 8], np.float32), shadow * crock_guard, 0.24)
    contact = soften(ellipse(0.0, 1.001, 0.49, 0.011), 0.0017 * h)
    lay([7, 10, 6], contact * crock_guard, 0.43)

    # Curved silhouette, sampled finely so shoulders have no polygon corners.
    outline = [(-0.185, 0.055), (-0.185, 0.255), (-0.195, 0.279),
               (-0.235, 0.307), (-0.300, 0.330), (-0.372, 0.351),
               (-0.426, 0.373), (-0.461, 0.397), (-0.479, 0.426),
               (-0.486, 0.466), (-0.484, 0.944), (-0.478, 0.964),
               (-0.462, 0.980), (-0.427, 0.992), (-0.370, 0.998),
               (0.359, 0.998), (0.421, 0.992), (0.461, 0.980),
               (0.480, 0.958), (0.486, 0.933), (0.486, 0.450),
               (0.479, 0.419), (0.463, 0.395), (0.429, 0.371),
               (0.374, 0.349), (0.302, 0.327), (0.238, 0.304),
               (0.201, 0.280), (0.188, 0.257), (0.188, 0.055)]
    glass = soften(polygon(outline), 0.00055 * h)
    left_light = np.exp(-((u + 0.24) / 0.22) ** 2)
    center_light = np.exp(-((u - 0.04) / 0.35) ** 2)
    side_dark = np.clip(np.abs(u) / 0.5, 0, 1) ** 2
    oil = 1.0 / (1.0 + np.exp(np.clip(-(v - 0.43) * 85, -50, 50)))
    body = np.empty((H, W, 3), np.float32)
    body[..., 0] = 24 + 25 * left_light + 12 * center_light + 13 * oil - 9 * side_dark
    body[..., 1] = 35 + 34 * left_light + 14 * center_light + 8 * oil - 13 * side_dark
    body[..., 2] = 13 + 12 * left_light + 6 * center_light - 3 * oil - 4 * side_dark
    # Weak transmitted scene variation and correlated photographic grain.
    transmitted = cv2.GaussianBlur(background, (0, 0), max(1.0, 0.0025 * h * scale))
    body += (transmitted - np.mean(transmitted, axis=(0, 1), keepdims=True)) * 0.065
    body += grain[..., None] * 1.15
    lay(np.clip(body, 0, 255), glass)

    # Amber oil meniscus and heavy, slightly luminous green glass base.
    meniscus = stroke([(-0.41, 0.433), (-0.25, 0.438), (0.0, 0.441), (0.27, 0.438), (0.43, 0.431)], 0.018)
    lay([111, 111, 38], soften(meniscus, 0.0006 * h) * glass, 0.29)
    bottom_band = np.exp(-((v - 0.976) / 0.012) ** 2) * np.exp(-(u / 0.46) ** 6) * glass
    lay([87, 95, 37], bottom_band, 0.47)
    dark_base = stroke([(-0.43, 0.988), (-0.23, 0.997), (0.22, 0.997), (0.43, 0.986)], 0.019)
    lay([13, 22, 9], soften(dark_base, 0.0005 * h) * glass, 0.65)

    # Uneven glass reflections that follow neck and shoulder curvature.
    reflection = stroke([(-0.135, 0.092), (-0.145, 0.248), (-0.171, 0.284),
                         (-0.278, 0.331), (-0.367, 0.379), (-0.400, 0.445),
                         (-0.401, 0.551), (-0.405, 0.716), (-0.396, 0.946)], 0.027)
    reflect_mod = 0.50 + 0.23 * np.sin(v * 19.0) + 0.15 * np.cos(v * 47.0)
    lay([177, 188, 121], soften(reflection, 0.0011 * h) * glass * reflect_mod, 0.63)
    thin_edge = stroke([(-0.456, 0.432), (-0.455, 0.940), (-0.431, 0.973)], 0.013)
    lay([109, 132, 58], soften(thin_edge, 0.00055 * h) * glass, 0.42)
    right_edge = stroke([(0.442, 0.405), (0.456, 0.455), (0.453, 0.937), (0.430, 0.975)], 0.018)
    lay([82, 100, 39], soften(right_edge, 0.0008 * h) * glass, 0.37)
    neck_glint = stroke([(0.117, 0.104), (0.123, 0.235), (0.147, 0.279)], 0.018)
    lay([137, 150, 89], soften(neck_glint, 0.0006 * h) * glass, 0.29)
    shoulder_glint = stroke([(-0.285, 0.335), (-0.155, 0.318), (0.060, 0.313), (0.249, 0.332)], 0.015)
    lay([129, 139, 72], soften(shoulder_glint, 0.0007 * h) * glass, 0.27)

    # Paper label conforms to the front face with shaded sides.
    label = polygon([(-0.384, 0.550), (-0.190, 0.543), (0.180, 0.543),
                     (0.375, 0.552), (0.375, 0.820), (0.183, 0.829),
                     (-0.192, 0.829), (-0.384, 0.820)])
    label = soften(label, 0.00045 * h) * glass
    paper_shade = 1.0 - 0.18 * (np.clip(np.abs(u) / 0.40, 0, 1) ** 2)
    paper = np.stack([207 * paper_shade, 200 * paper_shade, 158 * paper_shade], axis=-1)
    paper += grain[..., None] * 0.8
    lay(paper, label)
    border = stroke([(-0.348, 0.569), (-0.185, 0.563), (0.175, 0.563),
                     (0.340, 0.571), (0.340, 0.801), (0.175, 0.809),
                     (-0.185, 0.809), (-0.348, 0.801), (-0.348, 0.569)], 0.012)
    lay([135, 127, 75], soften(border, 0.00035 * h) * label, 0.70)

    def label_text(text, baseline, width_fraction, color):
        font = cv2.FONT_HERSHEY_SIMPLEX
        thickness = max(1, int(round(0.0011 * w * scale)))
        nominal = cv2.getTextSize(text, font, 1.0, thickness)[0][0]
        font_scale = width_fraction * bw * scale / max(1, nominal)
        text_width = cv2.getTextSize(text, font, font_scale, thickness)[0][0]
        tx, ty = point(0, baseline)
        m = np.zeros((H, W), np.uint8)
        cv2.putText(m, text, (int(tx - text_width / 2), ty), font, font_scale, 255, thickness, cv2.LINE_AA)
        lay(color, (m.astype(np.float32) / 255.0) * label, 0.94)

    label_text('OLIVE', 0.643, 0.59, [51, 62, 30])
    label_text('OIL', 0.716, 0.36, [51, 62, 30])
    divider = stroke([(-0.25, 0.741), (0.25, 0.741)], 0.011)
    lay([141, 129, 73], divider * label, 0.72)
    # Small botanical mark on the lower label, with no invented brand.
    twig = stroke([(-0.12, 0.797), (0.0, 0.773), (0.12, 0.768)], 0.013)
    lay([81, 91, 45], twig * label, 0.8)
    for a, b, ra, rb in [(-0.072, 0.773, 0.047, 0.007), (0.025, 0.790, 0.050, 0.007), (0.093, 0.760, 0.042, 0.006)]:
        lay([91, 105, 48], ellipse(a, b, ra, rb) * label, 0.85)

    # Gold screw cap with ridges, a rounded top, and a darker lower rim.
    cap = polygon([(-0.209, 0.011), (0.209, 0.011), (0.216, 0.026),
                   (0.216, 0.083), (0.193, 0.094), (-0.193, 0.094),
                   (-0.216, 0.083), (-0.216, 0.026)])
    cap = np.maximum(cap, ellipse(0, 0.013, 0.210, 0.013))
    cap = soften(cap, 0.00045 * h)
    cap_light = np.exp(-((u + 0.080) / 0.145) ** 2)
    ridges = 6 * np.sin(u * 166.0) + 2 * np.sin(u * 333.0)
    cap_rgb = np.empty((H, W, 3), np.float32)
    cap_rgb[..., 0] = 111 + 61 * cap_light + ridges
    cap_rgb[..., 1] = 97 + 57 * cap_light + ridges * 0.9
    cap_rgb[..., 2] = 41 + 39 * cap_light + ridges * 0.5
    cap_rgb += grain[..., None] * 0.7
    lay(cap_rgb, cap)
    cap_top = soften(ellipse(0, 0.012, 0.201, 0.012), 0.0004 * h)
    lay([174, 157, 87], cap_top, 0.74)
    cap_rim = stroke([(-0.204, 0.083), (-0.105, 0.088), (0.110, 0.088), (0.203, 0.082)], 0.021)
    lay([76, 67, 28], soften(cap_rim, 0.0004 * h) * cap, 0.77)
    cap_highlight = stroke([(-0.141, 0.029), (-0.141, 0.073)], 0.025)
    lay([215, 201, 129], soften(cap_highlight, 0.00045 * h) * cap, 0.51)

    # Downsample only the actual pixel changes, preserving all untouched pixels.
    delta = cv2.resize(canvas - background, (rw, rh), interpolation=cv2.INTER_AREA)
    result = source.copy()
    result[y0:y1, x0:x1] = np.clip(original + delta, 0, 255)
    return Image.fromarray(np.clip(np.rint(result), 0, 255).astype(np.uint8), 'RGB')
give the man bermuda shorts
magicbrush_train_62756_3 · add / insert · execution=passed
PASSinstr 4preserve 5quality 3
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The central man has been edited to appear to wear knee-length shorts, satisfying the requested local change. The rest of the scene is essentially unchanged. The edit is somewhat crude, with awkward leg proportions and blending around the shorts/skin, but it is recognizable as bermuda shorts.

l1=0.0034 · gain=-0.0001 · mask_l1=0.0000 · preserve_l1=0.0053

reasoning / plan
{
 "visual_evidence": [
  "The foreground man wears a dark suit jacket and long dark trousers.",
  "His trouser legs are visible between the jacket and black shoes.",
  "He is walking on wet pavement in front of motorcycles and vehicles."
 ],
 "target_object": "The foreground man's trousers",
 "target_region": "The trousers and lower legs beneath the suit jacket, leaving the shoes intact",
 "editing_intent": "Turn the long trousers into dark knee-length Bermuda shorts and reveal naturally shaded bare lower legs.",
 "editing_plan": [
  "Locate the dark trouser silhouette using a constrained geometric mask and pixel brightness.",
  "Retain the upper trousers as the shorts and establish two staggered knee-length hems.",
  "Synthesize bare calves using skin colors sampled from the man's face, cylindrical shading, and fine texture.",
  "Inpaint the narrow remnants of trouser fabric outside the new calves.",
  "Add subtle hem shadows and feather the edited boundaries while preserving the shoes and surrounding scene."
 ],
 "preservation_constraints": [
  "Preserve the man's face, hair, jacket, shirt, tie, hands, and shoes.",
  "Preserve the other person, motorcycles, vehicles, signs, and buildings.",
  "Keep the original framing, wet pavement, lighting, and image texture."
 ]
}
pixel code
def edit(image):
    import cv2
    import numpy as np
    from PIL import Image

    original = np.asarray(image.convert('RGB')).copy()
    h, w = original.shape[:2]
    scale = min(w, h) / 512.0
    rng = np.random.default_rng(47)
    yy, xx = np.mgrid[0:h, 0:w].astype(np.float32)
    X, Y = xx / w, yy / h

    def polygon(points):
        mask = np.zeros((h, w), np.uint8)
        coords = np.round(np.asarray(points) * [w, h]).astype(np.int32)
        cv2.fillPoly(mask, [coords], 255)
        return mask

    def feather(mask, amount=0.45):
        return np.clip(cv2.GaussianBlur(mask.astype(np.float32) / 255.0, (0, 0), max(0.25, amount * scale)), 0, 1)

    # A tight guide isolates the foreground man's trousers, not the pavement.
    guide = polygon([
        (0.289, 0.554), (0.346, 0.554), (0.346, 0.589),
        (0.342, 0.620), (0.336, 0.654), (0.331, 0.685),
        (0.337, 0.706), (0.313, 0.707), (0.306, 0.675),
        (0.299, 0.643), (0.293, 0.608)
    ])
    rgb = original.astype(np.float32)
    lum = rgb @ np.array([0.299, 0.587, 0.114], np.float32)
    dark = ((lum < 73) & (np.max(rgb, axis=2) < 109)).astype(np.uint8) * 255
    trousers = cv2.bitwise_and(guide, dark)
    kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (max(3, int(round(3 * scale)) | 1),) * 2)
    trousers = cv2.morphologyEx(trousers, cv2.MORPH_CLOSE, kernel)
    trousers = cv2.bitwise_and(trousers, guide)

    # Skin sample: the visible face, excluding the dark suit and background.
    face = rgb[int(0.413*h):int(0.450*h), int(0.302*w):int(0.344*w)]
    candidates = face.reshape(-1, 3)
    select = ((candidates[:, 0] > candidates[:, 1] * 1.04) &
              (candidates[:, 1] > candidates[:, 2] * 0.96) &
              (candidates.mean(axis=1) > 88) &
              (candidates.mean(axis=1) < 221))
    if np.count_nonzero(select) >= 5:
        skin = np.median(candidates[select], axis=0)
    else:
        skin = np.median(candidates, axis=0)
    skin = np.clip(skin * np.array([0.94, 0.92, 0.90]), [105, 83, 73], [190, 164, 151])

    # The rear leg is partly occluded by the forward leg.
    rear = polygon([
        (0.322, 0.617), (0.339, 0.620), (0.336, 0.639),
        (0.333, 0.657), (0.328, 0.678), (0.323, 0.687),
        (0.314, 0.683), (0.318, 0.663), (0.321, 0.643)
    ])
    front = polygon([
        (0.303, 0.628), (0.322, 0.633), (0.325, 0.649),
        (0.325, 0.667), (0.328, 0.684), (0.332, 0.700),
        (0.329, 0.704), (0.318, 0.704), (0.315, 0.690),
        (0.312, 0.673), (0.308, 0.651)
    ])
    # Constrain new anatomy to the existing silhouette to avoid enlarging it.
    support = cv2.dilate(trousers, np.ones((max(1, int(round(scale))), max(1, int(round(scale)))), np.uint8))
    rear = cv2.bitwise_and(rear, support)
    front = cv2.bitwise_and(front, support)
    rear[Y >= 0.691] = 0
    front[Y >= 0.704] = 0
    combined = cv2.bitwise_or(rear, front)

    # Remove only the thin fabric remnants outside the narrower bare calves.
    lower = trousers.copy()
    lower[(Y < 0.620) | (Y >= 0.704)] = 0
    # The left shorts leg has a slightly lower hem.
    lower[(X < 0.320) & (Y < 0.633)] = 0
    erase = cv2.bitwise_and(lower, cv2.bitwise_not(combined))
    if np.any(erase):
        cleaned = cv2.inpaint(original, erase, max(2, int(round(3 * scale))), cv2.INPAINT_TELEA).astype(np.float32)
        # Restore restrained photographic grain to the narrow pavement fill.
        fill_noise = rng.normal(0, 0.8, (h, w, 1)).astype(np.float32)
        ea = feather(erase, 0.35)[..., None]
        result = rgb * (1 - ea) + np.clip(cleaned + fill_noise, 0, 255) * ea
    else:
        result = rgb.copy()

    grain = rng.normal(0, 0.95, (h, w)).astype(np.float32)
    broad_noise = cv2.GaussianBlur(rng.normal(0, 1, (h, w)).astype(np.float32), (0, 0), max(0.5, 1.0 * scale))

    def paint_leg(canvas, mask, rear_leg=False):
        if rear_leg:
            center = 0.329 - 0.09 * (Y - 0.627)
            radius = 0.0082 - 0.020 * np.clip(Y - 0.628, 0, 0.06)
            top = 0.621
            base = skin * 0.85
        else:
            center = 0.314 + 0.135 * np.clip(Y - 0.633, 0, 0.071)
            radius = 0.0100 - 0.052 * np.clip(Y - 0.638, 0, 0.066)
            top = 0.632
            base = skin
        across = np.clip((X - center) / np.maximum(radius, 0.004), -1.5, 1.5)
        curved = np.sqrt(np.maximum(0, 1 - np.minimum(across * across, 1)))
        lighting = 0.76 + 0.24 * curved - 0.055 * across
        cuff_shadow = 0.14 * np.exp(-np.maximum(Y - top, 0) / 0.007)
        knee = 0.045 * np.exp(-((Y - (top + 0.012)) / 0.014)**2) * curved
        lighting = lighting - cuff_shadow + knee
        layer = base[None, None, :] * lighting[..., None]
        # Low-amplitude skin mottling and grain, rather than flat color.
        layer += (grain + 1.6 * broad_noise)[..., None]
        layer[..., 0] += 1.1 * broad_noise
        layer[..., 2] -= 0.6 * broad_noise
        a = feather(mask, 0.42)[..., None]
        return canvas * (1 - a) + np.clip(layer, 0, 255) * a

    result = paint_leg(result, rear, True)
    result = paint_leg(result, front, False)

    # Subtle fabric hems retain the original trouser texture and black color.
    hems = np.zeros((h, w), np.uint8)
    cv2.line(hems, (int(0.322*w), int(0.617*h)), (int(0.339*w), int(0.620*h)), 255, max(1, int(round(scale))))
    cv2.line(hems, (int(0.303*w), int(0.628*h)), (int(0.322*w), int(0.633*h)), 255, max(1, int(round(scale))))
    hems = cv2.bitwise_and(hems, trousers)
    hems = cv2.bitwise_and(hems, cv2.bitwise_not(combined))
    ha = feather(hems, 0.35)[..., None] * 0.65
    hem_color = np.clip(rgb * 0.85 + np.array([2.0, 2.5, 3.0]), 0, 255)
    result = result * (1 - ha) + hem_color * ha

    # Explicitly preserve the black footwear and everything outside the edit.
    affected = cv2.bitwise_or(erase, cv2.bitwise_or(combined, hems))
    boundary = cv2.GaussianBlur(affected.astype(np.float32) / 255, (0, 0), max(0.25, 0.6 * scale))
    changed = boundary > 0.001
    changed[Y >= 0.707] = False
    result[~changed] = rgb[~changed]
    return Image.fromarray(np.clip(np.rint(result), 0, 255).astype(np.uint8), 'RGB')
let the bag contain soda bottles
magicbrush_train_171472_1 · replace / change · execution=passed
PASSinstr 4preserve 5quality 3
source
GPT-6.1-Sol output
MagicBrush target (reference only)

Soda bottles were added inside one of the bags as requested, and the rest of the scene is essentially unchanged. The edit is localized and understandable, though the bottles look somewhat artificial/cartoon-like and do not fully match the image lighting and texture.

l1=0.0431 · gain=-0.0126 · mask_l1=0.0455 · preserve_l1=0.0423

reasoning / plan
{
 "visual_evidence": [
  "An open dark bag occupies the middle-right of the image.",
  "Its opening currently contains assorted packaged groceries.",
  "The bag has a dark front rim, fabric sides, and visible handles."
 ],
 "target_object": "The contents of the open dark bag at middle-right",
 "target_region": "The opening above the bag's front rim, approximately 58–90% across and 37–53% down the image",
 "editing_intent": "Replace the visible groceries inside this bag with several realistically shaded soda bottles.",
 "editing_plan": [
  "Mask the bag opening while retaining its front rim and surrounding fabric.",
  "Remove the existing contents and reconstruct a shadowed, textured interior using pixels sampled from the same bag.",
  "Construct three soda bottles with rounded shoulders, screw caps, liquid shading, labels, reflections, and fine texture.",
  "Arrange the bottles inside the opening, add contact shadows, and hide their lower ends behind the original front rim.",
  "Restore the visible dark handle and feather the edited boundaries."
 ],
 "preservation_constraints": [
  "Preserve all other bags, groceries, furniture, and the background.",
  "Preserve the target bag's outer fabric, front rim, and visible handle.",
  "Match the photograph's muted lighting, softness, and grain."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image, ImageDraw, ImageFont

    original = image.convert('RGB')
    w, h = image.size
    src = np.asarray(original).astype(np.float32)
    rng = np.random.default_rng(27)
    scale = min(w, h) / 512.0
    yy, xx = np.mgrid[0:h, 0:w]
    xn, yn = xx / float(w), yy / float(h)

    # The mask follows the opening rather than the exterior of the bag.
    points = [(0.575,0.454),(0.599,0.405),(0.674,0.377),
              (0.750,0.382),(0.820,0.397),(0.870,0.431),
              (0.898,0.478),(0.855,0.505),(0.780,0.527),
              (0.703,0.527),(0.641,0.505),(0.603,0.481)]
    mask = np.zeros((h,w), np.uint8)
    poly = np.array([(int(x*w),int(y*h)) for x,y in points], np.int32)
    cv2.fillPoly(mask, [poly], 255)
    front = np.interp(xn, [0.57,0.62,0.69,0.75,0.81,0.87,0.91],
                     [0.463,0.492,0.521,0.525,0.515,0.494,0.477])
    front_gate = np.clip((front-yn)*h / max(1.0,scale) + 0.5, 0, 1)
    mask = (mask.astype(np.float32)*front_gate).astype(np.uint8)
    repaired = cv2.inpaint(src.astype(np.uint8), mask, max(2,int(4*scale)), cv2.INPAINT_TELEA).astype(np.float32)

    # Sample actual dark fabric, retaining irregular weave and color variation.
    patch = src[int(.545*h):max(int(.545*h)+2,int(.578*h)),
                int(.882*w):max(int(.882*w)+2,int(.938*w))]
    texture = cv2.resize(patch, (w,h), interpolation=cv2.INTER_LINEAR)
    texmean = texture.mean(axis=(0,1), keepdims=True)
    variation = np.clip(texture-texmean, -22, 22)
    depth = np.clip((yn-.38)/.15, 0, 1)
    interior = np.zeros_like(src)
    interior[:] = [42,45,37]
    interior += variation*.38
    interior -= depth[...,None]*10
    fold = 3*np.sin(xn*93+yn*27) + 2*np.sin(xn*177-yn*47)
    interior += fold[...,None]
    interior += rng.normal(0,1.6,(h,w,1))
    feather = cv2.GaussianBlur(mask.astype(np.float32)/255, (0,0), max(.55,.85*scale))
    feather *= front_gate
    fill = .93*interior + .07*repaired
    canvas = np.clip(src*(1-feather[...,None])+fill*feather[...,None],0,255)

    def make_bottle(bw, bh, angle, liquid, label_color, cap_color, title):
        ss = 3
        W, H = max(24,int(bw*ss)), max(60,int(bh*ss))
        v, u = np.mgrid[0:H,0:W].astype(np.float32)
        u = (u+.5)/W-.5
        v = (v+.5)/H
        radius = np.interp(v, [0,.012,.065,.077,.155,.195,.265,.325,.42,.79,.87,.93,.975,1],
                           [.18,.215,.215,.165,.165,.20,.35,.465,.475,.475,.465,.475,.425,.27])
        dist = radius-np.abs(u)
        alpha = np.clip(dist*W+.5,0,1)
        alpha *= np.clip((1-v)*H,0,1)
        radial = np.sqrt(np.clip(1-(u/np.maximum(radius,.01))**2,0,1))
        light = .43+.64*radial-.11*u
        color = np.array(liquid, np.float32)
        rgb = color[None,None,:]*light[...,None]
        # Empty shoulder and neck are translucent PET with warm reflected light.
        neck = v < .275
        clear = np.array([103,112,91],np.float32)[None,None,:]*(.51+.54*radial[...,None])
        clear += np.exp(-((u+.09)/.026)**2)[...,None]*22
        rgb = np.where(neck[...,None], .68*clear+.32*rgb, rgb)
        meniscus = np.exp(-((v-.277)/.008)**2)
        rgb -= meniscus[...,None]*12
        # Bottle label follows cylindrical shading rather than being a flat rectangle.
        band = (v>.455)&(v<.698)
        label = np.array(label_color,np.float32)[None,None,:]*(.65+.38*radial[...,None])
        label = np.broadcast_to(label,(H,W,3)).copy()
        label += (2*np.sin(v*145)+1.5*np.cos(u*35))[...,None]
        rgb = np.where(band[...,None],label,rgb)
        for level in [.457,.694]:
            line = np.exp(-((v-level)/.0035)**2)
            rgb += line[...,None]*np.array([19,17,13],np.float32)
        # Fine molded rings and irregular vertical reflections.
        for level in [.322,.373,.785,.835,.891,.948]:
            curve = level+.012*(u/.48)**2
            ring = np.exp(-((v-curve)/.004)**2)*(v>.28)
            rgb += ring[...,None]*(8+10*radial[...,None])
            rgb -= np.exp(-((v-curve-.007)/.004)**2)[...,None]*5
        reflection = np.exp(-((u+.235+.015*np.sin(v*24))/.025)**2)
        reflection *= (.5+.5*np.sin(v*6+1)**2)
        rgb += reflection[...,None]*np.array([47,49,43])*np.where(band,.25,1)[...,None]
        rgb += np.exp(-((u-.31)/.013)**2)[...,None]*np.array([13,17,13])
        # Screw-cap ribs, top glint, and the tamper ring.
        cap = v < .077
        ribs = 5*np.cos(u*W*1.1)+2*np.sin(u*W*2.1)
        cap_rgb = np.array(cap_color,np.float32)[None,None,:]*(.65+.35*radial[...,None])
        cap_rgb = np.broadcast_to(cap_rgb,(H,W,3)).copy()+ribs[...,None]
        cap_rgb += np.exp(-((v-.013)/.008)**2)[...,None]*20
        cap_rgb -= np.exp(-((v-.066)/.006)**2)[...,None]*18
        rgb = np.where(cap[...,None],cap_rgb,rgb)
        rgb += np.exp(-((v-.093)/.004)**2)[...,None]*9
        # Subtle petaloid foot and grain.
        feet = (v>.915)*np.cos(u*29)**2
        rgb -= feet[...,None]*8
        rgb += rng.normal(0,1.15,(H,W,1))
        rgba = np.dstack([np.clip(rgb,0,255).astype(np.uint8), (alpha*255).astype(np.uint8)])
        bottle = Image.fromarray(rgba,'RGBA')
        # Render lettering separately so the built-in font works at any input size.
        font = ImageFont.load_default()
        text_layer = Image.new('L',(140,35),0)
        td = ImageDraw.Draw(text_layer)
        box = td.textbbox((0,0),title,font=font)
        td.text((2-box[0],2-box[1]),title,fill=230,font=font)
        text_layer = text_layer.crop((0,0,max(3,box[2]-box[0]+4),max(3,box[3]-box[1]+4)))
        tw, th = max(5,int(W*.66)), max(5,int(H*.062))
        text_layer = text_layer.resize((tw,th),Image.Resampling.LANCZOS)
        text_rgb = Image.new('RGBA',(tw,th),(228,223,194,0))
        text_rgb.putalpha(text_layer)
        bottle.alpha_composite(text_rgb,((W-tw)//2,int(H*.535)))
        draw = ImageDraw.Draw(bottle)
        draw.line([(int(W*.29),int(H*.641)),(int(W*.70),int(H*.641))],fill=(204,203,171,155),width=max(1,int(ss*scale)))
        bottle = bottle.resize((max(8,int(bw)),max(20,int(bh))),Image.Resampling.LANCZOS)
        return bottle.rotate(angle,Image.Resampling.BICUBIC,expand=True)

    # Rear bottles first; their feet will be occluded by the unmodified bag rim.
    specs = [(.645,.343,.075,.197,-8,(58,37,21),(151,42,33),(164,47,37),'COLA'),
             (.834,.361,.067,.170,-11,(47,92,32),(157,155,57),(69,114,39),'LIME'),
             (.742,.302,.079,.239,5,(65,40,23),(155,44,35),(175,50,39),'COLA')]
    for cx, top, width, height, angle, liquid, label, cap, title in specs:
        bottle = make_bottle(width*w,height*h,angle,liquid,label,cap,title)
        layer = Image.new('RGBA',(w,h),(0,0,0,0))
        px = int(cx*w-bottle.width/2)
        py = int((top+height/2)*h-bottle.height/2)
        layer.paste(bottle,(px,py))
        arr = np.asarray(layer).astype(np.float32)
        a = arr[:,:,3]/255.0
        a *= front_gate
        shifted = cv2.warpAffine(a,np.float32([[1,0,2.5*scale],[0,1,2*scale]]),(w,h))
        shadow = cv2.GaussianBlur(shifted,(0,0),max(.7,2.0*scale))*feather*.35
        canvas *= (1-shadow[...,None])
        canvas = canvas*(1-a[...,None])+arr[:,:,:3]*a[...,None]

    # Recover the original dark handle where it passes in front of the contents.
    handle_mask = np.zeros((h,w),np.uint8)
    hp = np.array([(int(x*w),int(y*h)) for x,y in
                   [(.715,.350),(.723,.334),(.751,.337),(.802,.359),
                    (.846,.395),(.838,.410),(.811,.381),(.772,.365),(.733,.357)]],np.int32)
    cv2.fillPoly(handle_mask,[hp],255)
    dark = np.clip((79-src.mean(axis=2))/17,0,1)
    handle_alpha = cv2.GaussianBlur(handle_mask.astype(np.float32)/255*dark,(0,0),max(.35,.5*scale))
    canvas = canvas*(1-handle_alpha[...,None])+src*handle_alpha[...,None]
    return Image.fromarray(np.clip(canvas,0,255).astype(np.uint8),'RGB')
let a dog coil up and sleep
magicbrush_train_171472_3 · replace / change · execution=passed
PASSinstr 4preserve 5quality 3
source
GPT-6.1-Sol output
MagicBrush target (reference only)

A curled-up sleeping dog was added in the scene, matching the requested action. The rest of the cluttered room is largely unchanged. However, the dog is stylized/cartoon-like and does not blend realistically with the photo lighting and texture.

l1=0.0080 · gain=-0.0037 · mask_l1=0.0004 · preserve_l1=0.0121

reasoning / plan
{
 "visual_evidence": [
  "An exposed concrete floor occupies the upper middle of the image.",
  "Bags, containers, and loose items crowd the foreground.",
  "No dog is currently visible.",
  "The clear floor above the bags provides room for a small curled-up dog."
 ],
 "target_object": "A sleeping dog added to the exposed floor",
 "target_region": "Upper-middle floor, above the white bags and left of the green hose",
 "editing_intent": "Add a natural-looking tan dog curled tightly around its tucked paws, with its head resting down and its visible eye closed.",
 "editing_plan": [
  "Select a clear floor footprint without covering existing objects.",
  "Construct a rounded canine body, wrapping tail, tucked paws, lowered head, floppy ear, and muzzle.",
  "Render directional shading, fine fur texture, and small facial details.",
  "Add a soft contact shadow consistent with the room lighting.",
  "Antialias and composite the dog while preserving pixels outside its footprint and shadow."
 ],
 "preservation_constraints": [
  "Keep all bags and their contents unchanged.",
  "Preserve the doorway, walls, furniture, and green hose.",
  "Do not alter the image dimensions or overall color balance.",
  "Leave the surrounding floor texture visible and unchanged outside the new dog and its shadow."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    source = np.asarray(image.convert('RGB'), dtype=np.float32)
    w, h = image.size
    rng = np.random.default_rng(2817)
    x0, y0 = int(w * 0.465), int(h * 0.035)
    x1, y1 = int(w * 0.873), int(h * 0.243)
    pw, ph = x1 - x0, y1 - y0
    scale = 3
    W, H = max(12, pw * scale), max(12, ph * scale)
    yy, xx = np.mgrid[0:H, 0:W].astype(np.float32)
    X, Y = (xx + 0.5) / W, (yy + 0.5) / H
    premult = np.zeros((H, W, 3), np.float32)
    coverage = np.zeros((H, W), np.float32)
    floor = source[y0:y1, x0:x1]
    exposure = float(np.clip(np.median(floor) / 100.0, 0.86, 1.06))

    def over(color, alpha):
        nonlocal premult, coverage
        a = np.clip(alpha, 0, 1).astype(np.float32)
        c = np.asarray(color, dtype=np.float32)
        if c.ndim == 1:
            c = np.broadcast_to(c, (H, W, 3))
        premult = c * a[..., None] + premult * (1 - a[..., None])
        coverage = a + coverage * (1 - a)

    def noise_field(sigma):
        n = rng.normal(0, 1, (H, W)).astype(np.float32)
        n = cv2.GaussianBlur(n, (0, 0), max(0.4, sigma))
        return n / max(float(n.std()), 0.001)

    broad = noise_field(W * 0.016)
    fine = noise_field(0.65)
    medium = noise_field(W * 0.004)

    def fur(mask, base, illumination, angle, amount=1.0):
        base = np.asarray(base, np.float32) * exposure
        variation = 2.2 * broad + 2.0 * medium + 1.3 * fine
        color = base[None, None, :] * illumination[..., None]
        color = color + variation[..., None] * np.array([1.0, 0.88, 0.65], np.float32)
        color = np.clip(color, 0, 255).astype(np.float32)
        strokes = color.copy()
        count = int(min(23000, max(900, mask.sum() / (scale * scale) * 1.4)))
        sx = rng.integers(0, W, count)
        sy = rng.integers(0, H, count)
        good = mask[sy, sx] > 0.96
        sx, sy = sx[good], sy[good]
        for px, py in zip(sx, sy):
            theta = float(angle[py, px]) + float(rng.normal(0, 0.22))
            length = float(rng.uniform(0.003, 0.009) * W)
            dx, dy = np.cos(theta) * length, np.sin(theta) * length
            value = float(rng.normal(0, 10.0))
            c = np.clip(color[py, px] + value * np.array([1.0, 0.87, 0.65]), 0, 255)
            p1 = (int(px - dx * 0.35), int(py - dy * 0.35))
            p2 = (int(px + dx * 0.65), int(py + dy * 0.65))
            cv2.line(strokes, p1, p2, tuple(float(v) for v in c), max(1, scale // 2), cv2.LINE_AA)
        color = color * (1 - 0.58 * amount) + strokes * (0.58 * amount)
        over(color, mask)

    def ellipse(cx, cy, rx, ry, base, rotation=0.0, flow='body', strength=1.0):
        co, si = np.cos(rotation), np.sin(rotation)
        ux = (X - cx) * co + (Y - cy) * si
        vy = -(X - cx) * si + (Y - cy) * co
        u, v = ux / rx, vy / ry
        q = u * u + v * v
        edge = q + 0.006 * medium
        mask = np.clip((1 - edge) / 0.026, 0, 1)
        z = np.sqrt(np.maximum(0, 1 - q))
        lighting = 0.70 + 0.34 * np.clip(0.29 * u - 0.34 * v + 0.83 * z, -0.6, 1.1)
        if flow == 'body':
            angle = np.arctan2(v * ry * H, u * rx * W) + np.pi / 2
            lighting -= 0.07 * np.exp(-((X - 0.43) / 0.15) ** 2 - ((Y - 0.65) / 0.19) ** 2)
        elif flow == 'face':
            angle = np.full((H, W), 0.40, np.float32) + 0.25 * v
        elif flow == 'paw':
            angle = np.full((H, W), 0.13, np.float32) + 0.15 * v
        else:
            angle = np.full((H, W), 1.22, np.float32) + 0.18 * u
        fur(mask, base, lighting, angle, strength)
        return mask

    def bezier(points, n=100):
        p = np.asarray(points, np.float32)
        t = np.linspace(0, 1, n, dtype=np.float32)[:, None]
        return (1-t)**3*p[0] + 3*(1-t)**2*t*p[1] + 3*(1-t)*t**2*p[2] + t**3*p[3]

    def stroke(points, color, width, opacity=1.0, softness=0.0):
        mask = np.zeros((H, W), np.uint8)
        p = np.asarray(points, np.float32) * np.array([W, H], np.float32)
        cv2.polylines(mask, [np.rint(p).astype(np.int32)], False, 255, max(1, int(width * W)), cv2.LINE_AA)
        a = mask.astype(np.float32) / 255.0
        if softness > 0:
            a = cv2.GaussianBlur(a, (0, 0), max(0.4, softness * W))
        over(np.asarray(color, np.float32) * exposure, a * opacity)

    # The dog's continuous rounded back and haunch form the main curled silhouette.
    body_mask = ellipse(0.532, 0.419, 0.356, 0.346, (158, 116, 73), rotation=-0.045)
    hollow = np.exp(-((X - 0.443) / 0.149)**2 - ((Y - 0.649) / 0.116)**2)
    over((69 * exposure, 46 * exposure, 29 * exposure), hollow * body_mask * 0.25)

    # A thick tapered tail follows the outside of the curl and ends beside the paws.
    tail_points = bezier([(0.800, 0.423), (0.944, 0.735), (0.743, 0.881), (0.466, 0.808)], 170)
    tm = np.zeros((H, W), np.uint8)
    tangent_x = np.zeros((H, W), np.float32)
    tangent_y = np.zeros((H, W), np.float32)
    for i, p in enumerate(tail_points):
        t = i / max(1, len(tail_points)-1)
        radius = max(1, int(H * (0.079 * (1-t) + 0.027 * t)))
        center = (int(p[0] * W), int(p[1] * H))
        cv2.circle(tm, center, radius, 255, -1, cv2.LINE_AA)
        j0, j1 = max(0, i-1), min(len(tail_points)-1, i+1)
        d = (tail_points[j1] - tail_points[j0]) * np.array([W, H], np.float32)
        a = float(np.arctan2(d[1], d[0]))
        cv2.circle(tangent_x, center, radius + 2, float(np.cos(a)), -1)
        cv2.circle(tangent_y, center, radius + 2, float(np.sin(a)), -1)
    tail_mask = cv2.GaussianBlur(tm.astype(np.float32) / 255, (0, 0), 0.65)
    dist = cv2.distanceTransform((tm > 100).astype(np.uint8), cv2.DIST_L2, 5)
    ridge = np.clip(dist / max(1.0, H * 0.065), 0, 1)
    tail_light = 0.68 + 0.29 * np.sqrt(ridge) + 0.08 * (1-Y)
    tail_angle = np.arctan2(tangent_y, tangent_x)
    fur(tail_mask, (163, 119, 75), tail_light, tail_angle)

    # Tucked forepaws sit in the hollow underneath the lowered head.
    ellipse(0.496, 0.735, 0.087, 0.083, (169, 130, 86), rotation=-0.09, flow='paw')
    ellipse(0.456, 0.794, 0.089, 0.078, (179, 141, 96), rotation=0.035, flow='paw')
    for px in (0.488, 0.511):
        curve = bezier([(px, 0.785), (px+0.003, 0.801), (px-0.001, 0.815), (px-0.012, 0.819)], 20)
        stroke(curve, (96, 69, 43), 0.0035, 0.44, 0.0009)

    # The head rests sideways, its muzzle pointing into the curled paws.
    ellipse(0.281, 0.629, 0.129, 0.183, (161, 115, 72), rotation=-0.11, flow='face')
    ellipse(0.355, 0.709, 0.083, 0.091, (190, 153, 109), rotation=0.12, flow='face', strength=0.75)

    # Smoothly interpolated floppy ear, rather than a hard polygon.
    ear_nodes = np.array([(0.198, 0.469), (0.151, 0.486), (0.137, 0.581), (0.166, 0.697), (0.225, 0.774), (0.270, 0.741), (0.255, 0.610), (0.232, 0.506)], np.float32)
    curve = []
    for i in range(len(ear_nodes)):
        p0 = ear_nodes[(i-1) % len(ear_nodes)]
        p1 = ear_nodes[i]
        p2 = ear_nodes[(i+1) % len(ear_nodes)]
        p3 = ear_nodes[(i+2) % len(ear_nodes)]
        for t in np.linspace(0, 1, 16, endpoint=False):
            curve.append(0.5*((2*p1)+(-p0+p2)*t+(2*p0-5*p1+4*p2-p3)*t*t+(-p0+3*p1-3*p2+p3)*t*t*t))
    em = np.zeros((H, W), np.uint8)
    ep = np.rint(np.asarray(curve) * np.array([W, H])).astype(np.int32)
    cv2.fillPoly(em, [ep], 255, cv2.LINE_AA)
    ea = cv2.GaussianBlur(em.astype(np.float32)/255, (0, 0), 0.7)
    ed = cv2.distanceTransform((em > 100).astype(np.uint8), cv2.DIST_L2, 5)
    elight = 0.68 + 0.30 * np.clip(ed / max(1, W * 0.035), 0, 1) + 0.05 * (1-Y)
    fur(ea, (116, 77, 45), elight, np.full((H, W), 1.28, np.float32), 0.8)
    fold = bezier([(0.197, 0.504), (0.211, 0.579), (0.206, 0.676), (0.239, 0.730)], 40)
    stroke(fold, (77, 48, 29), 0.005, 0.26, 0.002)

    # Closed visible eye and a quiet, relaxed mouth.
    eye = bezier([(0.309, 0.606), (0.320, 0.624), (0.341, 0.627), (0.355, 0.614)], 40)
    stroke(eye, (88, 57, 34), 0.012, 0.19, 0.003)
    stroke(eye, (43, 31, 24), 0.005, 0.91, 0.0008)
    mouth = bezier([(0.416, 0.730), (0.397, 0.744), (0.373, 0.757), (0.350, 0.745)], 35)
    stroke(mouth, (92, 64, 43), 0.0033, 0.61, 0.0008)

    # Small, shaded charcoal nose, with a restrained reflected highlight.
    co, si = np.cos(-0.12), np.sin(-0.12)
    nu = ((X-0.421)*co + (Y-0.707)*si) / 0.020
    nv = (-(X-0.421)*si + (Y-0.707)*co) / 0.028
    nq = nu*nu + nv*nv
    na = np.clip((1-nq)/0.075, 0, 1)
    nz = np.sqrt(np.maximum(0, 1-nq))
    nc = np.empty((H, W, 3), np.float32)
    nlight = 7*nz - 4*nv + 1.1*fine
    for k, b in enumerate((36, 31, 27)):
        nc[..., k] = b + nlight
    over(np.clip(nc, 0, 255), na)
    glint = np.exp(-((X-0.424)/0.006)**2 - ((Y-0.696)/0.005)**2) * na
    over((101, 94, 83), glint * 0.34)
    nostril = np.exp(-((X-0.430)/0.004)**2 - ((Y-0.711)/0.006)**2) * na
    over((15, 14, 13), nostril * 0.65)

    # Downsample premultiplied layers, retaining clean, feathered fur edges.
    A = cv2.resize(coverage, (pw, ph), interpolation=cv2.INTER_AREA)
    P = cv2.resize(premult, (pw, ph), interpolation=cv2.INTER_AREA)
    shadow_shift = np.float32([[1, 0, -0.005*w], [0, 1, 0.006*h]])
    shifted = cv2.warpAffine(A, shadow_shift, (pw, ph), flags=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT)
    soft_shadow = cv2.GaussianBlur(shifted, (0, 0), max(0.8, 0.006*w))
    contact = cv2.GaussianBlur(shifted, (0, 0), max(0.5, 0.0018*w))
    shadow = np.clip(0.21*soft_shadow + 0.13*contact, 0, 0.34)
    shadowed_floor = floor * (1-shadow[..., None]*np.array([0.94, 0.97, 1.0], np.float32))
    result = source.copy()
    result[y0:y1, x0:x1] = shadowed_floor*(1-A[..., None]) + P
    return Image.fromarray(np.clip(np.rint(result), 0, 255).astype(np.uint8), 'RGB')
Make the cat a dog.
magicbrush_train_533536_1 · replace / change · execution=passed
FAILinstr 4preserve 4quality 2
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The cat has been replaced with a dog-like animal in the correct region, while the TV and surrounding scene are mostly unchanged. However, the dog is crudely rendered, lacks realism and detail, and does not blend well with the original image lighting and texture.

l1=0.0313 · gain=0.0036 · mask_l1=0.0081 · preserve_l1=0.0413

reasoning / plan
{
 "visual_evidence": [
  "A brown tabby cat occupies the lower-left foreground and faces the television.",
  "The cat has pointed ears, striped fur, and a small bright pink collar detail.",
  "A black JVC television sits on a dark reddish wooden surface."
 ],
 "target_object": "The foreground cat",
 "target_region": "The animal in the lower-left corner, especially its head, ears, muzzle, and visible coat",
 "editing_intent": "Replace the cat with a brown, floppy-eared dog looking toward the television, retaining the foreground placement and low-light appearance.",
 "editing_plan": [
  "Mask the original animal and construct a rounded canine head, longer muzzle, hanging ear, and connected neck.",
  "Inpaint only the portions of the original feline silhouette that will remain exposed outside the dog.",
  "Retain the existing body shading while converting the striped coat into textured brown canine fur.",
  "Render the new head and ear with layered shading, sampled fur detail, fine hair strokes, and feathered contours.",
  "Add a dark nose, subtle eye, mouth crease, and contact shadow appropriate to the viewing direction.",
  "Restore the visible pink collar detail and preserve the television and surrounding wood outside the localized edit."
 ],
 "preservation_constraints": [
  "Keep the television screen, JVC lettering, controls, and red indicator unchanged.",
  "Keep the wooden surface unchanged except where the animal is replaced or casts a localized shadow.",
  "Maintain the original image dimensions, viewpoint, and dim warm lighting.",
  "Keep the animal facing toward the television.",
  "Retain the small visible pink collar detail."
 ]
}
pixel code
def edit(image):
    import cv2
    import numpy as np
    from PIL import Image

    w, h = image.size
    d = float(min(w, h))
    src = np.asarray(image.convert('RGB')).copy()
    original = src.astype(np.float32)
    rng = np.random.default_rng(27)
    yy, xx = np.mgrid[0:h, 0:w].astype(np.float32)
    x, y = xx / w, yy / h

    def blur(a, sigma):
        return cv2.GaussianBlur(a.astype(np.float32), (0, 0), max(0.25, float(sigma)))

    def shape(points, feather=0.0018, smooth=True):
        p = np.asarray([(a*w, b*h) for a, b in points], np.float32)
        if smooth:
            curve = []
            for i in range(len(p)):
                p0, p1 = p[(i-1) % len(p)], p[i]
                p2, p3 = p[(i+1) % len(p)], p[(i+2) % len(p)]
                for t in np.linspace(0, 1, 14, endpoint=False):
                    curve.append(0.5*((2*p1) + (-p0+p2)*t +
                        (2*p0-5*p1+4*p2-p3)*t*t +
                        (-p0+3*p1-3*p2+p3)*t*t*t))
            p = np.asarray(curve)
        m = np.zeros((h, w), np.uint8)
        cv2.fillPoly(m, [np.rint(p).astype(np.int32)], 255)
        return np.clip(blur(m / 255.0, feather*d), 0, 1)

    def ellipse(cx, cy, rx, ry, angle=0, feather=0.0015):
        m = np.zeros((h, w), np.uint8)
        cv2.ellipse(m, (int(cx*w), int(cy*h)),
                    (max(1, int(rx*w)), max(1, int(ry*h))),
                    angle, 0, 360, 255, -1, cv2.LINE_AA)
        return np.clip(blur(m / 255.0, feather*d), 0, 1)

    def gaussian(cx, cy, rx, ry):
        return np.exp(-0.5*(((x-cx)/rx)**2 + ((y-cy)/ry)**2))

    old_head = shape([(0.0,.707),(.025,.670),(.066,.642),(.111,.615),
        (.154,.601),(.207,.611),(.247,.587),(.273,.592),(.299,.626),
        (.314,.684),(.323,.743),(.336,.789),(.348,.844),(.285,.886),
        (.146,.910),(.020,.860),(0.0,.849)], smooth=False)
    body = shape([(0.0,.778),(.047,.755),(.122,.769),(.239,.770),
        (.304,.781),(.338,.814),(.358,.855),(.381,.899),
        (.405,.970),(.389,1.04),(-.035,1.04),(-.035,.830)])
    neck = shape([(.105,.798),(.173,.747),(.261,.732),(.307,.751),
        (.338,.776),(.347,.833),(.370,.900),(.329,.952),
        (.237,.965),(.145,.919),(.094,.858)])
    head = shape([(.038,.800),(.058,.743),(.074,.690),(.117,.647),
        (.178,.622),(.230,.628),(.276,.647),(.298,.674),
        (.327,.678),(.359,.689),(.374,.707),(.370,.734),
        (.350,.746),(.319,.751),(.301,.786),(.270,.816),
        (.239,.858),(.165,.885),(.083,.865)])
    ear = shape([(.132,.664),(.161,.660),(.187,.684),(.185,.733),
        (.194,.786),(.178,.833),(.152,.860),(.127,.866),
        (.106,.846),(.097,.807),(.096,.760),(.106,.706)])
    dog_mask = np.maximum.reduce([body, neck, head, ear])
    old_mask = np.maximum(old_head, body)

    # Fill just the obsolete feline outline; the new head covers the rest.
    removal = ((old_mask > .30) & (dog_mask < .91)).astype(np.uint8)*255
    if removal.any():
        radius = max(2, int(round(.013*d)))
        filled = cv2.inpaint(src, removal, radius, cv2.INPAINT_TELEA).astype(np.float32)
        residual = original - blur(original, .0022*d)
        grain = rng.normal(0, 1.4, (h, w, 1)).astype(np.float32)
        filled = np.clip(filled + .25*residual + grain, 0, 255)
        a = blur(removal / 255.0, .0012*d)[..., None]
        canvas = original*(1-a) + filled*a
    else:
        canvas = original.copy()

    def blend(color_image, mask):
        nonlocal canvas
        a = np.clip(mask, 0, 1)[..., None]
        canvas = canvas*(1-a) + np.asarray(color_image, np.float32)*a

    # Reuse fine animal texture, not any external imagery.
    gray = cv2.cvtColor(src, cv2.COLOR_RGB2GRAY).astype(np.float32)
    xa, xb = int(.025*w), max(int(.33*w), int(.025*w)+1)
    ya, yb = int(.66*h), max(int(.96*h), int(.66*h)+1)
    patch = gray[ya:yb, xa:xb]
    detail_patch = patch - blur(patch, .0025*d)
    fur_detail = cv2.resize(detail_patch, (w, h), interpolation=cv2.INTER_LINEAR)
    fine = rng.normal(0, 1.25, (h, w)).astype(np.float32)
    medium = blur(rng.normal(0, 1, (h, w)).astype(np.float32), .003*d)
    medium /= max(float(medium.std()), .001)
    texture = .42*fur_detail + fine + 1.4*medium

    # A soft local shadow falls onto wood, never across the television.
    shift = np.float32([[1, 0, .012*w], [0, 1, .017*h]])
    shadow = cv2.warpAffine(dog_mask, shift, (w, h), flags=cv2.INTER_LINEAR)
    shadow = blur(shadow, .011*d)*(1-dog_mask)
    wood_only = np.clip((y-(.49+.435*x))/.025, 0, 1)
    shadow *= wood_only * (x < .44) * (y > .62)
    canvas *= (1-.16*shadow[..., None])

    def coat(mask, base, shading, direction, count):
        nonlocal canvas
        value = np.asarray(base, np.float32)[None, None, :]*shading[..., None]
        value = value + texture[..., None]*np.array([1.0,.88,.67], np.float32)
        bright = np.zeros((h, w), np.uint8)
        dark = np.zeros((h, w), np.uint8)
        candidates = np.argwhere(mask > .75)
        if len(candidates):
            for _ in range(int(count)):
                py, px = candidates[rng.integers(len(candidates))]
                theta = direction + rng.normal(0, .23)
                length = rng.uniform(.0025, .010)*d
                qx = int(round(px + np.cos(theta)*length))
                qy = int(round(py + np.sin(theta)*length))
                layer = bright if rng.random() > .42 else dark
                cv2.line(layer, (int(px), int(py)), (qx, qy),
                         int(rng.integers(3, 12)), 1, cv2.LINE_AA)
        strokes = blur(bright.astype(np.float32)-dark.astype(np.float32), .0007*d)
        value += strokes[..., None]*np.array([1.0,.83,.61], np.float32)
        blend(np.clip(value, 0, 255), mask)

    # The body retains its source shading and silhouette, but loses tabby stripes.
    low = blur(gray, .014*d)
    body_shade = np.clip(.60 + low/150.0, .66, 1.33)
    body_shade += .10*gaussian(.172,.835,.14,.15)
    coat(body, [48,33,22], body_shade, 1.17, 1800)
    neck_shade = .70 + .40*gaussian(.260,.779,.070,.088)
    neck_shade -= .12*gaussian(.143,.875,.080,.085)
    coat(neck, [57,39,25], neck_shade, 1.13, 1250)

    # Rounded skull, illuminated from the screen above and to the right.
    head_shade = .67 + .48*gaussian(.225,.653,.093,.067)
    head_shade += .16*gaussian(.283,.711,.055,.062)
    head_shade -= .11*gaussian(.075,.798,.063,.077)
    coat(head, [65,45,28], head_shade, .63, 2400)

    # A subdued far ear folds against the upper rear of the skull.
    far_ear = shape([(.119,.650),(.145,.633),(.171,.641),(.185,.672),
                    (.174,.714),(.151,.737),(.129,.709)])
    far_shade = .65 + .20*gaussian(.143,.648,.036,.051)
    coat(far_ear, [57,38,23], far_shade, 1.43, 550)

    # Longer canine muzzle and lower jaw, with nonuniform fur coloration.
    jaw = shape([(.267,.739),(.303,.728),(.346,.732),(.368,.726),
                 (.362,.749),(.334,.773),(.298,.780),(.275,.766)])
    jaw_shade = .67 + .36*gaussian(.332,.741,.045,.025)
    coat(jaw, [59,41,27], jaw_shade, .13, 450)
    muzzle = shape([(.263,.684),(.290,.676),(.317,.681),(.350,.691),
                    (.369,.705),(.363,.730),(.340,.741),(.302,.741),
                    (.274,.723)])
    muzzle_shade = .73 + .42*gaussian(.315,.691,.052,.022)
    muzzle_shade -= .12*gaussian(.326,.735,.043,.016)
    coat(muzzle, [75,53,34], muzzle_shade, .18, 700)
    muzzle_tip = ellipse(.351,.714,.024,.025, -10)
    tip_shade = .72 + .25*gaussian(.350,.701,.024,.015)
    coat(muzzle_tip, [44,32,23], tip_shade, .12, 190)

    def curved_line(points, color, thickness, opacity=1):
        m = np.zeros((h, w), np.uint8)
        pts = np.rint(np.array([(a*w,b*h) for a,b in points])).astype(np.int32)
        cv2.polylines(m, [pts], False, 255, max(1,int(thickness*d)), cv2.LINE_AA)
        m = blur(m/255.0, .0010*d)*opacity
        blend(np.broadcast_to(np.asarray(color,np.float32), (h,w,3)), m)

    curved_line([(.290,.747),(.311,.751),(.335,.749),(.354,.734)],
                [19,15,12], .0023, .65)

    # Small side-view eye, mostly dark with a restrained screen reflection.
    eye_socket = ellipse(.281,.681,.012,.008, 12, .0020)
    blend(np.broadcast_to(np.array([28,20,14],np.float32),(h,w,3)), eye_socket*.80)
    eye = ellipse(.284,.681,.0065,.0048, -8, .0007)
    eye_rgb = np.zeros((h,w,3),np.float32)
    eye_rgb[:] = [11,10,8]
    eye_rgb += gaussian(.282,.679,.0038,.0030)[...,None]*np.array([18,13,6])
    blend(eye_rgb, eye)
    glint = ellipse(.286,.679,.0015,.0013, 0, .0005)
    blend(np.broadcast_to(np.array([126,124,104],np.float32),(h,w,3)), glint*.62)
    curved_line([(.269,.671),(.280,.668),(.290,.673)], [81,57,34], .002, .32)

    # Textured leathery nose at the end of the projecting muzzle.
    nose = shape([(.355,.692),(.370,.692),(.380,.701),(.379,.718),
                  (.370,.730),(.356,.725),(.350,.713)], feather=.0011)
    nose_light = gaussian(.363,.699,.014,.009)
    nose_rgb = np.zeros((h,w,3),np.float32)
    nose_rgb[:] = [15,15,13]
    nose_rgb += nose_light[...,None]*np.array([16,15,12])
    nose_rgb += fine[...,None]*.8
    blend(np.clip(nose_rgb,0,255), nose)
    nostril = ellipse(.371,.715,.0038,.0050, 25, .0008)
    blend(np.broadcast_to(np.array([7,7,6],np.float32),(h,w,3)),nostril*.88)
    curved_line([(.354,.700),(.360,.697),(.369,.699)], [68,64,52], .0015, .40)

    # The foreground ear is long and folded, hiding the original pointed cat ear.
    ear_shadow = blur(ear,.004*d)*head*(1-ear)*.45
    blend(np.broadcast_to(np.array([22,16,11],np.float32),(h,w,3)), ear_shadow)
    ear_shade = .67 + .28*gaussian(.139,.691,.034,.047)
    ear_shade += .16*gaussian(.160,.808,.027,.059)
    ear_shade -= .19*gaussian(.120,.789,.019,.061)
    coat(ear, [61,40,24], ear_shade, 1.52, 1500)
    fold = shape([(.148,.685),(.160,.699),(.153,.739),(.146,.776),
                  (.143,.817),(.135,.836),(.133,.795),(.137,.743)], feather=.0034)
    blend(np.broadcast_to(np.array([25,18,13],np.float32),(h,w,3)),fold*.34)
    curved_line([(.107,.764),(.109,.809),(.120,.838),(.139,.850)],
                [83,55,31], .0022, .20)

    # Recover only actual red/pink collar pixels, rather than nearby red wood.
    r, g, b = original[:,:,0], original[:,:,1], original[:,:,2]
    collar_area = shape([(.263,.871),(.286,.850),(.326,.821),
                         (.344,.832),(.315,.865),(.278,.891)], smooth=False)
    tag_area = shape([(.326,.746),(.344,.744),(.347,.793),(.325,.802)], smooth=False)
    red_pixels = ((r > 1.45*g) & (r > 1.25*b) & (r > 45)).astype(np.float32)
    pink_pixels = ((r > 85) & (r > 1.65*g) & (b > .30*r)).astype(np.float32)
    collar_restore = np.maximum(collar_area*red_pixels, tag_area*pink_pixels)
    collar_restore = np.clip(blur(collar_restore,.0007*d),0,1)
    blend(original, collar_restore)

    return Image.fromarray(np.clip(canvas,0,255).astype(np.uint8), 'RGB')
remove that toilet paper
magicbrush_train_357057_2 · remove · execution=passed
PASSinstr 4preserve 5quality 3
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The toilet paper roll on the shelf has been removed, and the rest of the bathroom scene is largely unchanged. However, the edited area has a noticeable blurry/painted artifact and some pattern distortion on and above the shelf.

l1=0.0011 · gain=0.0009 · mask_l1=0.0001 · preserve_l1=0.0021

reasoning / plan
{
 "visual_evidence": [
  "A small white toilet-paper roll stands on the white shelf above the toilet.",
  "The roll overlaps the patterned gold wall and casts a slight shadow on the shelf.",
  "The surrounding shelf and wall provide visible textures for filling the removed area."
 ],
 "target_object": "The toilet-paper roll standing on the shelf above the toilet",
 "target_region": "The small white roll near the left-center of the image, including its shadow on the shelf",
 "editing_intent": "Remove the roll and its shadow, restoring the patterned wall and white shelf behind it.",
 "editing_plan": [
  "Mask the roll silhouette and its small contact shadow.",
  "Estimate the shelf's rear edge from unobstructed neighboring pixels.",
  "Find a nearby wall-texture patch whose pattern best matches the boundary of the removal area.",
  "Copy matching wall and shelf textures into their respective portions of the mask, correcting local brightness differences.",
  "Feather the edit boundary while retaining the copied texture and image grain."
 ],
 "preservation_constraints": [
  "Keep the shelf's shape, edges, and position unchanged.",
  "Preserve the toilet, bidet, sink, mirror, and other bathroom fixtures.",
  "Leave the wall-mounted dispenser and its hanging white material unchanged.",
  "Do not change pixels outside the roll and its immediate shadow."
 ]
}
pixel code
def edit(image):
    import cv2
    import numpy as np
    from PIL import Image

    w, h = image.size
    original = np.asarray(image.convert('RGB'), dtype=np.uint8)
    src = original.astype(np.float32)
    scale = min(w, h)
    yy, xx = np.mgrid[0:h, 0:w].astype(np.float32)

    # The roll silhouette, with a small margin around its white edges.
    outline = np.array([
        [0.256, 0.394], [0.265, 0.388], [0.303, 0.389],
        [0.322, 0.397], [0.324, 0.444], [0.319, 0.456],
        [0.293, 0.469], [0.261, 0.458], [0.253, 0.440],
        [0.254, 0.408]
    ], dtype=np.float32)
    outline[:, 0] *= w
    outline[:, 1] *= h
    object_mask = np.zeros((h, w), np.uint8)
    cv2.fillPoly(object_mask, [np.rint(outline).astype(np.int32)], 255)
    margin = max(1, int(round(0.0022 * scale)))
    kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,
                                      (2 * margin + 1, 2 * margin + 1))
    object_mask = cv2.dilate(object_mask, kernel)

    # Estimate the shelf's rear boundary using white runs on either side.
    brightness = src.mean(axis=2)
    chroma = src.max(axis=2) - src.min(axis=2)
    white = (brightness > 172) & (chroma < 40)
    expected_slope = 0.143 * h / w
    expected_intercept = 0.398 * h
    points = []
    run = max(3, int(round(0.011 * h)))
    before = max(2, int(round(0.006 * h)))
    xs = list(range(int(0.177 * w), int(0.235 * w), max(1, int(0.004 * w))))
    xs += list(range(int(0.347 * w), int(0.439 * w), max(1, int(0.004 * w))))
    for x in xs:
        predicted = expected_slope * x + expected_intercept
        lo = max(before, int(predicted - 0.015 * h))
        hi = min(h - run - 1, int(predicted + 0.015 * h))
        candidates = []
        for y in range(lo, hi + 1):
            if white[y:y + run, x].mean() >= 0.83 and white[y - before:y, x].mean() <= 0.5:
                candidates.append(y)
        if candidates:
            y = min(candidates, key=lambda value: abs(value - predicted))
            points.append((x, y))
    slope, intercept = expected_slope, expected_intercept
    if len(points) >= 8:
        p = np.asarray(points, np.float32)
        for _ in range(3):
            design = np.column_stack((p[:, 0], np.ones(len(p))))
            fit = np.linalg.lstsq(design, p[:, 1], rcond=None)[0]
            residual = np.abs(design @ fit - p[:, 1])
            keep = residual < max(1.5, 0.004 * h)
            if keep.sum() < 6:
                break
            p = p[keep]
        if 0.07 * h / w < fit[0] < 0.22 * h / w:
            slope, intercept = float(fit[0]), float(fit[1])
    rear_edge = slope * xx + intercept

    shadow = np.zeros((h, w), np.uint8)
    cv2.ellipse(shadow,
                (int(round(0.294 * w)), int(round(0.465 * h))),
                (max(1, int(round(0.052 * w))), max(1, int(round(0.011 * h)))),
                0, 0, 360, 255, -1)
    shadow[yy < rear_edge + 1] = 0
    mask = cv2.bitwise_or(object_mask, shadow)

    ring_radius = max(3, int(round(0.012 * scale)))
    ring_kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,
                                            (2 * ring_radius + 1, 2 * ring_radius + 1))
    ring = (cv2.dilate(mask, ring_kernel) > 0) & (mask == 0)
    wall_ring = ring & (yy < rear_edge - max(1, 0.003 * h))
    ry, rx = np.where(wall_ring)

    def sample_at(xcoords, ycoords, data=src, nearest=False):
        return cv2.remap(data, np.asarray(xcoords, np.float32),
                         np.asarray(ycoords, np.float32),
                         cv2.INTER_NEAREST if nearest else cv2.INTER_LINEAR,
                         borderMode=cv2.BORDER_REFLECT_101)

    # Search one horizontal wallpaper repeat to the right. The boundary
    # comparison chooses the local phase rather than inventing a pattern.
    best_score = float('inf')
    wall_dx, wall_dy = 0.080 * w, 0.0
    if len(rx) >= 12:
        observed = src[ry, rx]
        for dx in np.linspace(0.073 * w, 0.094 * w, 15):
            for dy in np.linspace(-0.012 * h, 0.012 * h, 13):
                sx = (rx.astype(np.float32) + dx).reshape(-1, 1)
                sy = (ry.astype(np.float32) + dy).reshape(-1, 1)
                donor_mask = sample_at(sx, sy, mask, True).reshape(-1)
                valid = (donor_mask == 0)
                valid &= sy[:, 0] < slope * sx[:, 0] + intercept - max(1, 0.003 * h)
                if valid.sum() < max(12, int(0.60 * len(rx))):
                    continue
                sampled = sample_at(sx, sy).reshape(-1, 3)
                difference = observed[valid] - sampled[valid]
                offset = np.median(difference, axis=0)
                error = np.mean(np.abs(difference - offset), axis=1)
                score = np.mean(np.minimum(error, 65.0))
                score += 0.35 * abs(dx / w - 0.080) / 0.01
                if score < best_score:
                    best_score = score
                    wall_dx, wall_dy = float(dx), float(dy)

    wall_patch = sample_at(xx + wall_dx, yy + wall_dy)
    shelf_dx = 0.086 * w
    shelf_dy = slope * shelf_dx
    shelf_patch = sample_at(xx + shelf_dx, yy + shelf_dy)

    def correct_patch(patch, dx, dy, context, is_shelf=False):
        source_covered = sample_at(xx + dx, yy + dy, mask, True) > 0
        valid = context & (~source_covered)
        donor_edge = slope * (xx + dx) + intercept
        if is_shelf:
            valid &= yy + dy > donor_edge + max(1, 0.002 * h)
        else:
            valid &= yy + dy < donor_edge - max(1, 0.002 * h)
        py, px = np.where(valid)
        if len(px) < 8:
            return patch
        differences = src[py, px] - patch[py, px]
        center = np.median(differences, axis=0)
        if not is_shelf:
            return np.clip(patch + np.clip(center, -24, 24), 0, 255)
        # A robust low-frequency correction preserves the donor's grain.
        deviation = np.mean(np.abs(differences - center), axis=1)
        good = deviation < max(8.0, float(np.percentile(deviation, 75)))
        if good.sum() < 8:
            return np.clip(patch + np.clip(center, -24, 24), 0, 255)
        gx, gy = px[good], py[good]
        design = np.column_stack(((gx / w - 0.29), (gy / h - 0.46), np.ones(len(gx))))
        regularizer = np.diag([1.0, 1.0, 0.0001])
        coefficients = np.linalg.solve(design.T @ design + regularizer,
                                       design.T @ differences[good])
        correction = ((xx / w - 0.29)[..., None] * coefficients[0] +
                      (yy / h - 0.46)[..., None] * coefficients[1] + coefficients[2])
        return np.clip(patch + np.clip(correction, -24, 24), 0, 255)

    wall_patch = correct_patch(wall_patch, wall_dx, wall_dy, wall_ring)
    shelf_ring = ring & (yy > rear_edge + max(1, 0.003 * h))
    shelf_patch = correct_patch(shelf_patch, shelf_dx, shelf_dy, shelf_ring, True)

    # Keep the real, narrow wall/shelf edge rather than blurring the fill.
    edge_width = max(0.65, 0.0014 * h)
    shelf_alpha = np.clip((yy - rear_edge) / edge_width + 0.5, 0, 1)
    fill = wall_patch * (1 - shelf_alpha[..., None]) + shelf_patch * shelf_alpha[..., None]

    # Feather only inside the protected removal mask; all other pixels stay exact.
    distance = cv2.distanceTransform(mask, cv2.DIST_L2, 5)
    feather_width = max(1.0, 0.0025 * scale)
    alpha = np.clip(distance / feather_width, 0, 1)
    alpha = alpha * alpha * (3 - 2 * alpha)
    result = np.rint(src * (1 - alpha[..., None]) + fill * alpha[..., None])
    result = np.clip(result, 0, 255).astype(np.uint8)
    result[mask == 0] = original[mask == 0]
    output = Image.fromarray(result, 'RGB')
    if image.mode == 'RGBA':
        output = output.convert('RGBA')
        output.putalpha(image.getchannel('A'))
    return output
edit a castle in the image instead of the buildings
magicbrush_train_546597_2 · other · execution=passed
FAILinstr 4preserve 3quality 3
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The buildings were replaced with a castle-like structure, matching the requested edit. The street, sky, traffic light, cars, and pedestrian are partly preserved, though there are noticeable artifacts and some foreground blending issues. The castle is recognizable but looks synthetic and does not fully match the original perspective or lighting.

l1=0.2430 · gain=-0.0234 · mask_l1=0.0024 · preserve_l1=0.2781

reasoning / plan
{
 "visual_evidence": [
  "Tall beige buildings occupy the left side.",
  "An ornate pale building with a dark domed tower stands near the center.",
  "More buildings recede along the street on the right.",
  "Blue sky is visible above the buildings.",
  "Streetlights, a traffic signal, vehicles, and pavement are in the foreground."
 ],
 "target_object": "The buildings lining the street",
 "target_region": "The architectural skyline and facades above the foreground pavement",
 "editing_intent": "Replace the buildings with a textured stone castle featuring a crenellated keep, round towers, slate roofs, and arched entrances, while retaining the street foreground.",
 "editing_plan": [
  "Mask the existing building silhouette and separately protect visible foreground objects.",
  "Reconstruct exposed sky using the source image's sky colors and fine texture.",
  "Construct a castle with shaded stone walls, perspective battlements, cylindrical towers, and tiled conical roofs.",
  "Add recessed openings, masonry joints, wooden gates, architectural trim, and contact shadows.",
  "Feather the new architecture into the scene and restore the original foreground objects."
 ],
 "preservation_constraints": [
  "Keep the original image dimensions.",
  "Preserve sky outside the replaced architecture and new castle silhouette.",
  "Preserve the road and foreground pavement.",
  "Preserve the traffic signal, overhead support, streetlamp, visible vehicles, and foreground tree."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    w, h = image.size
    src = np.asarray(image.convert('RGB')).astype(np.float32)
    rng = np.random.default_rng(2718)
    yy, xx = np.mgrid[0:h, 0:w].astype(np.float32)
    xx /= max(w - 1, 1)
    yy /= max(h - 1, 1)
    scale = min(w, h)
    aa = max(0.45, scale * 0.001)

    def polygon(points):
        m = np.zeros((h, w), np.uint8)
        p = np.round(np.asarray(points) * np.array([w - 1, h - 1])).astype(np.int32)
        cv2.fillPoly(m, [p], 255)
        return m.astype(np.float32) / 255.0

    def rectangle(x0, y0, x1, y1):
        return polygon([(x0, y0), (x1, y0), (x1, y1), (x0, y1)])

    def ellipse(cx, cy, rx, ry):
        m = np.zeros((h, w), np.uint8)
        cv2.ellipse(m, (int(cx * (w - 1)), int(cy * (h - 1))),
                    (max(1, int(rx * w)), max(1, int(ry * h))), 0, 0, 360, 255, -1)
        return m.astype(np.float32) / 255.0

    def stroke(points, width):
        m = np.zeros((h, w), np.uint8)
        p = np.round(np.asarray(points) * np.array([w - 1, h - 1])).astype(np.int32)
        cv2.polylines(m, [p], False, 255, max(1, int(width * scale)), cv2.LINE_AA)
        return m.astype(np.float32) / 255.0

    def soften(m, sigma=aa):
        return cv2.GaussianBlur(m.astype(np.float32), (0, 0), sigma)

    old = polygon([
        (0, 0), (.379, 0), (.429, .035), (.451, .067), (.458, .097),
        (.433, .124), (.437, .294), (.461, .267), (.461, .197),
        (.453, .172), (.466, .132), (.476, .092), (.483, .063),
        (.525, .031), (.536, .026), (.535, 0), (.567, 0),
        (.566, .031), (.607, .055), (.625, .091), (.636, .132),
        (.649, .149), (.650, .190), (.635, .223), (.648, .254),
        (.699, .298), (.704, .284), (.730, .282), (.751, .302),
        (.767, .353), (.805, .347), (.816, .382), (.832, .399),
        (.844, .398), (.846, .420), (.870, .413), (.875, .381),
        (.883, .431), (.890, .419), (.904, .474), (.930, .503),
        (.936, .486), (.949, .498), (.956, .556), (.979, .570),
        (.980, .605), (1, .622), (1, .933), (0, .933)
    ])

    sky_select = (xx > .69) & (yy < .255) & (src[:, :, 2] > src[:, :, 0] + 30)
    sy, sx = np.where(sky_select)
    if len(sx) > 20:
        step = max(1, len(sx) // 5000)
        sy, sx = sy[::step], sx[::step]
        mat = np.column_stack([np.ones(len(sx)), xx[sy, sx], yy[sy, sx]])
        coef = np.linalg.lstsq(mat, src[sy, sx], rcond=None)[0]
        coef[1] = np.clip(coef[1], -35, 35)
        coef[2] = np.clip(coef[2], -85, 85)
        sky = coef[0] + xx[:, :, None] * coef[1] + yy[:, :, None] * coef[2]
    else:
        sky = np.empty_like(src)
        sky[:] = [99, 156, 213]
    sky_noise = rng.normal(0, 1.0, (h, w, 3)).astype(np.float32)
    sky += sky_noise + cv2.GaussianBlur(sky_noise, (0, 0), max(1, scale * .006))
    sky = np.clip(sky, 0, 255)
    a = soften(old)[:, :, None]
    canvas = src * (1 - a) + sky * a
    castle_mask = np.zeros((h, w), np.float32)

    fine = rng.normal(0, 1.8, (h, w)).astype(np.float32)
    coarse = rng.normal(0, 1, (max(4, h // 28), max(4, w // 28))).astype(np.float32)
    coarse = cv2.resize(coarse, (w, h), interpolation=cv2.INTER_CUBIC)
    medium = rng.normal(0, 1, (max(8, h // 8), max(8, w // 8))).astype(np.float32)
    medium = cv2.resize(medium, (w, h), interpolation=cv2.INTER_CUBIC)
    wall_samples = (xx < .39) & (yy < .7) & (src[:, :, 0] > 145) & (src[:, :, 1] > 130)
    wall_samples &= (src[:, :, 0] > src[:, :, 2] + 12)
    stone_color = np.median(src[wall_samples], axis=0) if wall_samples.any() else np.array([190, 182, 156])
    stone_color = np.clip(stone_color, [165, 155, 130], [208, 200, 180])

    def apply(m, color, feather=True):
        nonlocal canvas, castle_mask
        am = soften(m) if feather else m
        if np.ndim(color) == 1:
            color = np.asarray(color, np.float32)[None, None, :]
        canvas = canvas * (1 - am[:, :, None]) + np.clip(color, 0, 255) * am[:, :, None]
        castle_mask = np.maximum(castle_mask, m)

    def masonry(points=None, mask=None, factor=1.0, center=None, radius=None,
                 slope=0.0, course=.024, block=.061, origin=0.0):
        m = polygon(points) if mask is None else mask
        v = yy - slope * (xx - origin)
        u = xx.copy()
        lighting = np.ones((h, w), np.float32) * factor
        if center is not None:
            t = np.clip((xx - center) / radius, -.999, .999)
            u = center + np.arcsin(t) * radius
            lighting *= .79 + .23 * np.sqrt(np.maximum(0, 1 - t * t)) - .115 * t
        row = np.floor(v / course)
        offset = (row % 2) * .47 + .09 * np.sin(row * 2.37)
        bcoord = u / block + offset
        col = np.floor(bcoord)
        block_noise = np.sin(row * 17.13 + col * 43.71) * np.cos(row * 7.73 - col * 13.17)
        surface = (stone_color[None, None, :] * lighting[:, :, None]
                   + (fine + coarse * 4.2 + medium * 2.2 + block_noise * 6.0)[:, :, None])
        yf = np.mod(v, course)
        xf = np.mod(bcoord, 1.0) * block
        joint = np.exp(-np.square(yf / .0013)) + .72 * np.exp(-np.square(xf / .0011))
        surface -= joint[:, :, None] * np.array([24, 23, 20])
        bevel = np.exp(-np.square((yf - .0023) / .001))
        surface += bevel[:, :, None] * 4.2
        surface += (1 - yy)[:, :, None] * np.array([3, 3, 2])
        apply(m, surface)
        return m

    def band(x0, x1, y0, thickness=.013, factor=1.05, slope=0):
        y1 = y0 + slope * (x1 - x0)
        masonry([(x0, y0), (x1, y1), (x1, y1 + thickness), (x0, y0 + thickness)],
                factor=factor, course=.012, block=.068, slope=slope, origin=x0)
        shadow = polygon([(x0, y0 + thickness), (x1, y1 + thickness),
                          (x1, y1 + thickness + .004), (x0, y0 + thickness + .004)])
        apply(shadow, stone_color * (factor * .66) + fine[:, :, None])

    def arch_mask(cx, top, bottom, width):
        r = width / 2
        angles = np.linspace(np.pi, 0, 48)
        pts = [(cx + r * np.cos(t), top + r - r * np.sin(t)) for t in angles]
        pts += [(cx + r, bottom), (cx - r, bottom)]
        return polygon(pts)

    def opening(cx, top, bottom, width, gate=False):
        rim = .009 if gate else .005
        outer = arch_mask(cx, top - rim, bottom + .002, width + 2 * rim)
        masonry(mask=outer, factor=1.08, course=.022, block=.043)
        inner = arch_mask(cx, top, bottom, width)
        edge = cv2.dilate((inner * 255).astype(np.uint8), np.ones((3, 3), np.uint8)).astype(np.float32) / 255
        edge = np.maximum(0, edge - inner) * outer
        apply(edge, stone_color * .62 + fine[:, :, None])
        depth = np.clip((yy - top) / max(bottom - top, .001), 0, 1)
        horizontal = np.clip((xx - cx) / max(width / 2, .001), -1, 1)
        if gate:
            planks = np.mod((xx - cx) / (width / 10), 1)
            grain = np.sin(xx * w * .71 + medium * 1.7) * 2.0
            material = np.array([66, 55, 40])[None, None, :] + (depth * 8 - horizontal * 5 + fine + grain)[:, :, None]
            material -= np.exp(-np.square(planks / .065))[:, :, None] * 15
        else:
            material = np.array([32, 36, 34])[None, None, :] + (depth * 9 - horizontal * 3 + fine * .5)[:, :, None]
        apply(inner, material)
        if gate:
            center_seam = stroke([(cx, top + width * .50), (cx, bottom)], .002) * inner
            apply(center_seam, [25, 24, 20])
            for by in [top + (bottom - top) * .56, top + (bottom - top) * .83]:
                bar = rectangle(cx - width * .46, by, cx + width * .46, by + .005) * inner
                apply(bar, np.array([42, 43, 38]) + fine[:, :, None] * .6)
                for bx in np.linspace(cx - width * .4, cx + width * .4, 6):
                    apply(ellipse(bx, by + .002, .0017, .0017) * inner, [105, 101, 86])
        else:
            highlight = stroke([(cx + width / 2 - .0015, top + width / 2),
                                (cx + width / 2 - .0015, bottom - .001)], .002) * outer
            apply(highlight, stone_color * .79)

    def roof(cx, apex, bottom, radius):
        m = polygon([(cx, apex), (cx + radius, bottom), (cx - radius, bottom)])
        t = np.clip((yy - apex) / max(bottom - apex, .001), .015, 1)
        u = np.clip((xx - cx) / (radius * t), -1, 1)
        rows = t * 24 + .45 * u * u
        joints = np.exp(-np.square(np.mod(rows, 1) / .075))
        tiles = np.mod((u + 1) * (3 + 12 * t) + (np.floor(rows) % 2) * .5, 1)
        seams = np.exp(-np.square(tiles / .045))
        light = .98 - .24 * u - .12 * u * u
        material = np.array([67, 75, 78])[None, None, :] * light[:, :, None]
        material += (fine * 1.2 + medium * 2 - joints * 11 - seams * 5)[:, :, None]
        apply(m, material)
        apply(ellipse(cx, bottom, radius, .008), np.array([45, 49, 48]) + fine[:, :, None])
        finial = stroke([(cx, apex - .014), (cx, apex + .005)], .003)
        apply(finial, [57, 61, 58])
        apply(ellipse(cx, apex - .012, .003, .003), [64, 66, 61])

    def battlements(x0, x1, top, slope=0, pitch=.054, height=.037, depth=.009, factor=1.0):
        count = max(2, int((x1 - x0) / pitch))
        pitch = (x1 - x0) / count
        for i in range(count):
            left = x0 + i * pitch
            right = min(x1, left + pitch * .56)
            yl = top + slope * (left - x0)
            yr = top + slope * (right - x0)
            masonry([(left, yl - height), (right, yr - height),
                     (right, yr + .008), (left, yl + .008)],
                    factor=factor, course=.018, block=.042, slope=slope, origin=x0)
            masonry([(right, yr - height), (right + depth, yr - height + .007),
                     (right + depth, yr + .007), (right, yr)],
                    factor=factor * .72, course=.018, block=.032, slope=slope, origin=x0)
            cap = polygon([(left, yl - height), (right, yr - height),
                           (right + depth, yr - height + .006), (left + depth, yl - height + .006)])
            apply(cap, stone_color * (factor * 1.10) + fine[:, :, None])

    # The distant curtain wall recedes toward the right edge.
    masonry([(.627, .421), (1, .604), (1, .929), (.627, .929)],
            factor=.86, slope=.49, origin=.627, course=.021, block=.047)
    band(.627, 1, .443, .017, .92, .49)
    battlements(.636, 1, .426, slope=.49, pitch=.043, height=.026, depth=.005, factor=.92)
    band(.636, 1, .718, .009, .86, .16)
    for cx in [.671, .855, .886, .988]:
        top = .52 + .48 * (cx - .64)
        opening(cx, top, top + .068, .017)
    for cx in [.676, .86, .891, .989]:
        opening(cx, .779 + .1 * (cx - .64), .855 + .1 * (cx - .64), .017)

    # Far tower, softened by distance but still showing individual stone courses.
    masonry([(.901, .547), (.980, .547), (.980, .925), (.901, .925)],
            factor=.99, center=.9405, radius=.0395, course=.019, block=.04)
    band(.898, .983, .549, .012, .98)
    roof(.9405, .403, .543, .050)
    opening(.936, .630, .674, .016)
    opening(.940, .764, .811, .017)

    # The middle-distance round tower.
    masonry([(.709, .426), (.828, .426), (.828, .928), (.709, .928)],
            factor=1.035, center=.7685, radius=.0595, course=.024, block=.05)
    masonry(mask=ellipse(.7685, .428, .061, .011), factor=1.04,
            center=.7685, radius=.061, course=.018, block=.05)
    band(.703, .833, .452, .014, 1.04)
    roof(.7685, .272, .423, .076)
    for ty in [.514, .660, .800]:
        opening(.753, ty, ty + .062, .022)
        opening(.803, ty + .008, ty + .066, .013)
    masonry([(.704, .879), (.835, .879), (.839, .928), (.700, .928)],
            factor=.98, center=.7685, radius=.069, course=.025, block=.055)

    # Large keep: illuminated front and a darker right-hand face.
    masonry([(0, .103), (.326, .103), (.326, .930), (0, .930)], factor=1.02,
            course=.026, block=.066)
    masonry([(.326, .103), (.432, .158), (.432, .930), (.326, .930)],
            factor=.77, slope=.20, origin=.326, course=.025, block=.052)
    band(0, .326, .135, .018, 1.10)
    band(.326, .432, .135, .017, .84, .52)
    battlements(0, .326, .105, pitch=.053, height=.047, depth=.009, factor=1.05)
    battlements(.332, .432, .111, slope=.52, pitch=.037, height=.038, depth=.005, factor=.80)
    for by in [.398, .687]:
        band(0, .326, by, .010, 1.025)
        band(.326, .432, by, .010, .80, .045)
    for cx in [.063, .166, .270]:
        for ty in [.234, .458, .707]:
            opening(cx, ty, ty + .072, .026)
    for ty in [.282, .490, .701]:
        opening(.377, ty, ty + .070, .017)
    # Buttresses have lit fronts, dark returns, and sloped shoulders.
    for bx in [.012, .116, .310]:
        masonry([(bx - .012, .315), (bx + .010, .315),
                 (bx + .018, .930), (bx - .020, .930)], factor=1.05,
                course=.027, block=.034)
        masonry([(bx + .010, .315), (bx + .020, .325),
                 (bx + .029, .930), (bx + .018, .930)], factor=.77,
                course=.027, block=.025)
        apply(polygon([(bx - .012, .315), (bx + .010, .315),
                       (bx + .020, .325), (bx - .012, .325)]),
              stone_color * 1.10 + fine[:, :, None])
    opening(.215, .785, .931, .097, gate=True)
    opening(.064, .828, .931, .065, gate=True)

    # Dominant foreground tower with cylindrical lighting and a slate cone.
    masonry([(.424, .228), (.656, .228), (.656, .931), (.424, .931)],
            factor=1.09, center=.540, radius=.116, course=.025, block=.058)
    masonry(mask=ellipse(.540, .229, .117, .016), factor=1.08,
            center=.540, radius=.117, course=.022, block=.053)
    roof(.540, .028, .225, .131)
    for by in [.257, .431, .674]:
        band(.418, .662, by, .014, 1.06)
    for ty in [.310, .494, .710]:
        opening(.494, ty, ty + .068, .025)
        opening(.584, ty + .004, ty + .067, .026)
        opening(.640, ty + .014, ty + .069, .013)
    # A widened tower foot casts a narrow contact shadow onto the pavement.
    masonry([(.424, .858), (.656, .858), (.667, .931), (.413, .931)],
            factor=1.035, center=.540, radius=.128, course=.024, block=.064)
    band(.414, .666, .860, .012, 1.08)
    opening(.542, .790, .934, .104, gate=True)

    # Subtle base shadow, confined to the original architectural footprint.
    base_shadow = np.exp(-np.square((yy - .931) / .006)) * .20
    base_shadow *= (yy < .939).astype(np.float32)
    canvas *= 1 - base_shadow[:, :, None]

    # Restore the original street furniture, foliage, vehicles, and roadway.
    protect = np.zeros((h, w), np.float32)
    protect = np.maximum(protect, (yy >= .941).astype(np.float32))
    protect = np.maximum(protect, polygon([
        (0, .934), (.25, .933), (.43, .938), (.58, .935),
        (.73, .925), (1, .924), (1, 1), (0, 1)
    ]))
    lamp_head = polygon([(.274, .596), (.273, .577), (.289, .571),
                         (.312, .579), (.320, .585), (.310, .594), (.292, .597)])
    protect = np.maximum(protect, lamp_head)
    protect = np.maximum(protect, stroke([(.283, .594), (.287, .960)], .012))
    signal = polygon([(.649, .482), (.692, .475), (.707, .482),
                      (.710, .566), (.702, .578), (.660, .582), (.650, .566)])
    protect = np.maximum(protect, signal)
    protect = np.maximum(protect, stroke([(.695, .506), (1, .463)], .008))
    protect = np.maximum(protect, stroke([(.715, .502), (.724, .925)], .009))
    protect = np.maximum(protect, stroke([(.967, .646), (.971, .925)], .005))
    hsv = cv2.cvtColor(src.astype(np.uint8), cv2.COLOR_RGB2HSV)
    leaf_box = rectangle(.393, .791, .475, .930)
    leaves = ((hsv[:, :, 0] > 24) & (hsv[:, :, 0] < 95) &
              (hsv[:, :, 1] > 35) & (hsv[:, :, 2] < 155)).astype(np.float32) * leaf_box
    leaves = cv2.morphologyEx(leaves, cv2.MORPH_CLOSE, np.ones((3, 3), np.uint8))
    protect = np.maximum(protect, leaves)
    protect = np.maximum(protect, stroke([(.448, .846), (.448, .928)], .006))
    bollard = polygon([(.417, .872), (.427, .864), (.435, .877),
                       (.435, .933), (.429, .945), (.417, .942)])
    protect = np.maximum(protect, bollard)
    car = polygon([(.480, .912), (.499, .898), (.530, .897), (.546, .908),
                   (.563, .910), (.568, .932), (.490, .937), (.477, .927)])
    protect = np.maximum(protect, car)
    far_car = polygon([(.747, .906), (.772, .892), (.798, .892),
                       (.814, .905), (.861, .906), (.875, .921), (.749, .925)])
    dark_vehicle = (np.max(src, axis=2) < 105).astype(np.float32)
    protect = np.maximum(protect, far_car * dark_vehicle)
    right_car = polygon([(.932, .891), (.949, .869), (.977, .869),
                         (.992, .885), (1, .887), (1, .928), (.932, .928)])
    protect = np.maximum(protect, right_car)
    p = soften(protect, max(.35, scale * .0008))[:, :, None]
    canvas = canvas * (1 - p) + src * p
    return Image.fromarray(np.clip(canvas, 0, 255).astype(np.uint8), 'RGB')
replace the white truck with a white motorcycle
magicbrush_train_62756_2 · replace / change · execution=passed
FAILinstr 4preserve 4quality 2
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The central white truck was removed and replaced with a white motorcycle in the correct area. Most unrelated content, including the people, tents, and other vans, is preserved. However, the motorcycle looks like a flat illustration rather than a realistic object in the scene, with imperfect integration, lighting, and shadowing.

l1=0.0368 · gain=-0.0070 · mask_l1=0.0032 · preserve_l1=0.0505

reasoning / plan
{
 "visual_evidence": [
  "A white Mercedes commercial vehicle occupies the center of the image.",
  "Its front faces the camera, with a dark windshield, black bumper, and visible wheels.",
  "A man in a dark suit stands partly in front of its left side.",
  "The pavement is wet and contains vehicle shadows and reflections.",
  "A yellow vehicle is on the left, and a silver van is on the right."
 ],
 "target_object": "The central white truck",
 "target_region": "The central vehicle between the yellow vehicle and silver van, including its pavement shadow and reflection, but excluding the foreground man.",
 "editing_intent": "Replace the white truck with a parked white motorcycle, matching the overcast lighting, perspective, wet pavement, and foreground occlusion.",
 "editing_plan": [
  "Mask the central truck and its shadow while protecting the foreground man.",
  "Remove the truck and reconstruct the exposed building, adjoining van edge, and pavement using texture sampled from the source image.",
  "Replace the truck reflection with neighboring wet-pavement texture.",
  "Construct a white motorcycle with shaded tires, alloy wheels, frame, engine, white body panels, seat, windshield, mirrors, lights, and a stand.",
  "Add a soft contact shadow and faint wet-pavement reflection.",
  "Antialias the synthesized motorcycle, match image grain, and restore the protected foreground pixels."
 ],
 "preservation_constraints": [
  "Preserve both visible men, including the foreground man's silhouette.",
  "Preserve the yellow vehicle and its canopy.",
  "Preserve the silver van except for reconstructing the small portion previously hidden by the truck.",
  "Preserve the sign, support poles, trees, and surrounding building.",
  "Preserve pavement and curb outside the truck's footprint, shadow, and reflection."
 ]
}
pixel code
def edit(image):
    import math
    import cv2
    import numpy as np
    from PIL import Image, ImageDraw

    w, h = image.size
    src = np.asarray(image.convert('RGB')).copy()
    rng = np.random.default_rng(17)
    yy, xx = np.mgrid[0:h, 0:w].astype(np.float32)
    X, Y = xx / w, yy / h
    unit = min(w, h)

    def polygon_mask(points):
        m = np.zeros((h, w), np.uint8)
        pts = np.array([(round(x*w), round(y*h)) for x, y in points], np.int32)
        cv2.fillPoly(m, [pts], 255)
        return m

    person = polygon_mask([
        (.305,.405),(.326,.405),(.341,.413),(.345,.429),
        (.342,.445),(.357,.452),(.371,.471),(.380,.495),
        (.382,.518),(.374,.540),(.358,.558),(.356,.594),
        (.348,.624),(.343,.655),(.338,.686),(.340,.708),
        (.334,.731),(.324,.736),(.313,.727),(.303,.706),
        (.295,.680),(.286,.651),(.281,.622),(.272,.597),
        (.264,.569),(.261,.537),(.263,.502),(.269,.476),
        (.284,.458),(.301,.447),(.300,.422)
    ])
    protected = cv2.dilate(person, np.ones((3,3), np.uint8), iterations=1)
    truck = polygon_mask([
        (.364,.310),(.386,.300),(.595,.299),(.612,.304),
        (.624,.324),(.636,.375),(.656,.375),(.666,.385),
        (.665,.414),(.649,.422),(.658,.475),(.663,.530),
        (.660,.612),(.652,.640),(.634,.650),(.611,.650),
        (.600,.632),(.409,.638),(.398,.653),(.366,.649),
        (.354,.627),(.348,.584),(.347,.528),(.350,.455),
        (.355,.422),(.339,.413),(.340,.380),(.356,.374)
    ])
    shadow_mask = np.zeros((h,w), np.uint8)
    cv2.ellipse(shadow_mask, (round(.510*w), round(.647*h)),
                (round(.151*w), max(1,round(.023*h))), 0, 0, 360, 255, -1)
    removal = cv2.max(truck, shadow_mask)
    k = max(3, int(round(unit*.007)) | 1)
    removal = cv2.dilate(removal, np.ones((k,k), np.uint8))
    removal[protected > 0] = 0
    healed = cv2.inpaint(src, removal, max(2, int(unit*.012)), cv2.INPAINT_TELEA)

    # Continue the actual corrugated wall texture down behind the removed truck.
    wall_y = (.140 + np.mod(Y-.300, .061))*h
    wall_x = np.clip(xx, .346*w, .665*w)
    wall = cv2.remap(src, wall_x.astype(np.float32), wall_y.astype(np.float32),
                     cv2.INTER_LINEAR, borderMode=cv2.BORDER_REFLECT_101).astype(np.float32)
    wall *= np.clip(.98 - .55*np.maximum(Y-.300, 0), .82, .99)[...,None]
    # Copy wet masonry at a similar horizontal scale, without smoothing its grain.
    road_x = np.clip(xx + .300*w, 0, w-1)
    road_y = np.clip((.709 + (Y-.526)*.55)*h, 0, h-1)
    road = cv2.remap(src, road_x.astype(np.float32), road_y.astype(np.float32),
                     cv2.INTER_LINEAR, borderMode=cv2.BORDER_REFLECT_101).astype(np.float32)
    road *= np.clip(.84 + (Y-.526)*.88, .83, 1.0)[...,None]
    ground_transition = np.clip((Y-.511)/.017, 0, 1)
    ground_transition = ground_transition*ground_transition*(3-2*ground_transition)
    fill = wall*(1-ground_transition[...,None]) + road*ground_transition[...,None]
    # The right edge exposes a narrow continuation of the existing silver van.
    side = cv2.remap(src, np.clip(xx+.058*w,0,w-1).astype(np.float32), yy,
                    cv2.INTER_LINEAR, borderMode=cv2.BORDER_REFLECT_101).astype(np.float32)
    side_weight = np.clip((X-.631)/.012,0,1)
    side_weight *= np.clip((Y-.310)/.015,0,1)*np.clip((.592-Y)/.017,0,1)
    fill = fill*(1-side_weight[...,None]) + side*side_weight[...,None]
    fill += rng.normal(0, .65, (h,w,1)).astype(np.float32)
    a = cv2.GaussianBlur(removal.astype(np.float32)/255, (0,0), max(.65,unit*.0018))
    a[protected > 0] = 0
    base = healed.astype(np.float32)*(1-a[...,None]) + fill*a[...,None]
    base[protected > 0] = src[protected > 0]

    # Remove the old large vehicle reflection using neighboring source pavement.
    reflection_mask = np.zeros((h,w), np.uint8)
    cv2.ellipse(reflection_mask, (round(.513*w),round(.738*h)),
                (round(.147*w),max(1,round(.047*h))),0,0,360,255,-1)
    ra = cv2.GaussianBlur(reflection_mask.astype(np.float32)/255,(0,0),max(1,unit*.011))
    ra *= np.clip((Y-.685)/.018,0,1)
    ra[protected > 0] = 0
    pavement = cv2.remap(src,np.clip(xx+.295*w,0,w-1).astype(np.float32),yy,
                        cv2.INTER_LINEAR,borderMode=cv2.BORDER_REFLECT_101).astype(np.float32)
    base = base*(1-ra[...,None]) + pavement*ra[...,None]

    # Motorcycle and shadow are rendered above image resolution for clean edges.
    ss = 3
    W, H = w*ss, h*ss
    work = cv2.resize(np.clip(base,0,255),(W,H),interpolation=cv2.INTER_CUBIC)
    coverage = np.zeros((H,W),np.float32)
    gy, gx = np.mgrid[0:H,0:W].astype(np.float32)
    grain = rng.normal(0,1.0,(H,W)).astype(np.float32)
    grain = cv2.GaussianBlur(grain,(0,0),.65)
    ground = .643
    cast = np.exp(-(((gx/W-.526)/.124)**2 + ((gy/H-.641)/.012)**2)*1.65)
    contact = np.exp(-(((gx/W-.531)/.108)**2 + ((gy/H-.642)/.0045)**2)*1.5)
    shade = np.clip(.22*cast+.14*contact,0,.33)
    pr_hi = cv2.resize(protected,(W,H),interpolation=cv2.INTER_NEAREST)
    shade[pr_hi>0] = 0
    work *= 1-shade[...,None]

    def newmask():
        return Image.new('L',(W,H),0)

    def paint(mask, color, depth=8, opacity=1):
        box = mask.getbbox()
        if box is None:
            return
        x0,y0,x1,y1 = box
        m = np.asarray(mask.crop(box),dtype=np.float32)/255*opacity
        rh,rw = m.shape
        vy,vx = np.mgrid[0:rh,0:rw].astype(np.float32)
        lighting = depth*(.68-.83*vy/max(rh-1,1)-.36*vx/max(rw-1,1))
        tex = grain[y0:y1,x0:x1]*1.45
        material = np.clip(np.array(color,dtype=np.float32)[None,None,:] + lighting[...,None]+tex[...,None],0,255)
        region = work[y0:y1,x0:x1]
        region[:] = region*(1-m[...,None])+material*m[...,None]
        old = coverage[y0:y1,x0:x1]
        old[:] = 1-(1-old)*(1-m)

    def poly(points,color,depth=8,opacity=1):
        mask = newmask()
        ImageDraw.Draw(mask).polygon([(round(x*W),round(y*H)) for x,y in points],fill=255)
        paint(mask,color,depth,opacity)

    def ellipse(box,color,depth=8,opacity=1):
        mask = newmask()
        ImageDraw.Draw(mask).ellipse(tuple(round(v*(W if i%2==0 else H)) for i,v in enumerate(box)),fill=255)
        paint(mask,color,depth,opacity)

    def line(points,color,width=.003,depth=5,opacity=1):
        mask = newmask()
        d = ImageDraw.Draw(mask)
        pts = [(round(x*W),round(y*H)) for x,y in points]
        thick = max(1,round(width*min(W,H)))
        d.line(pts,fill=255,width=thick,joint='curve')
        r = thick/2
        for px,py in (pts[0],pts[-1]):
            d.ellipse((px-r,py-r,px+r,py+r),fill=255)
        paint(mask,color,depth,opacity)

    def wheel(cx,cy,rx,ry,front=False):
        ellipse((cx-rx,cy-ry,cx+rx,cy+ry),(24,26,27),9)
        ellipse((cx-rx*.90,cy-ry*.91,cx+rx*.90,cy+ry*.91),(43,46,46),10)
        ellipse((cx-rx*.75,cy-ry*.76,cx+rx*.75,cy+ry*.76),(112,117,116),20)
        ellipse((cx-rx*.66,cy-ry*.68,cx+rx*.66,cy+ry*.68),(32,36,37),5)
        for j in range(8):
            t = 2*math.pi*j/8+.19
            p1=(cx+rx*.10*math.cos(t),cy+ry*.10*math.sin(t))
            p2=(cx+rx*.65*math.cos(t+.07),cy+ry*.67*math.sin(t+.07))
            line([p1,p2],(147,155,155),.0027,15)
            line([(p1[0]-.001,p1[1]-.001),(p2[0]-.001,p2[1]-.001)],(202,207,204),.0009,3)
        dr = .47 if front else .36
        ellipse((cx-rx*dr,cy-ry*dr,cx+rx*dr,cy+ry*dr),(135,140,138),17)
        ellipse((cx-rx*dr*.76,cy-ry*dr*.76,cx+rx*dr*.76,cy+ry*dr*.76),(73,79,78),7)
        for j in range(12):
            t=2*math.pi*j/12
            px=cx+rx*dr*.86*math.cos(t)
            py=cy+ry*dr*.86*math.sin(t)
            ellipse((px-.0014,py-.0014,px+.0014,py+.0014),(41,45,45),2)
        ellipse((cx-.005,cy-.005,cx+.005,cy+.005),(167,175,171),17)
        ellipse((cx-.002,cy-.002,cx+.002,cy+.002),(43,47,45),4)
        arc=[]
        for t in np.linspace(math.pi*1.12,math.pi*1.72,22):
            arc.append((cx+rx*.95*math.cos(t),cy+ry*.95*math.sin(t)))
        line(arc,(87,91,88),.0012,4,.55)

    wheel(.443,.597,.041,.046)
    wheel(.611,.597,.043,.047,True)

    # Rear suspension, swingarm, tubular frame, and engine.
    line([(.446,.595),(.515,.574),(.525,.555)],(61,67,66),.013,13)
    line([(.447,.594),(.514,.577)],(146,152,150),.0045,13)
    line([(.464,.516),(.489,.575)],(32,37,36),.009,7)
    line([(.468,.520),(.488,.568)],(176,181,173),.004,13)
    for j in range(7):
        y=.526+j*.0055
        x=.470+j*.0023
        line([(x-.004,y),(x+.006,y+.002)],(87,91,87),.0022,9)
    poly([(.471,.503),(.533,.500),(.566,.526),(.543,.575),(.492,.578),(.475,.551)],(36,42,42),9)
    line([(.475,.505),(.500,.561),(.546,.565),(.568,.511)],(81,87,84),.006,13)
    poly([(.508,.534),(.545,.534),(.555,.555),(.548,.575),(.514,.576),(.501,.558)],(79,83,80),16)
    ellipse((.509,.548,.548,.582),(114,119,113),23)
    ellipse((.514,.552,.543,.576),(81,87,82),13)
    ellipse((.524,.560,.532,.569),(151,157,148),17)
    for j in range(6):
        y=.529+j*.004
        line([(.503,y),(.541,y-.003)],(155,161,154),.0016,8)
    line([(.540,.548),(.551,.577),(.572,.587)],(99,103,95),.0048,18)
    line([(.542,.548),(.553,.575)],(186,187,173),.0015,8)
    line([(.497,.573),(.486,.632),(.480,.642)],(56,61,58),.0038,9)
    line([(.478,.642),(.490,.642)],(66,70,65),.003,6)

    # Tapered metal exhaust, passenger footrest, and rear lighting.
    poly([(.422,.556),(.466,.562),(.499,.575),(.495,.586),(.454,.580),(.421,.568)],(128,133,127),22)
    line([(.427,.559),(.466,.566),(.492,.577)],(218,222,209),.002,7)
    ellipse((.415,.554,.431,.570),(69,74,70),13)
    ellipse((.418,.557,.427,.567),(25,29,28),4)
    line([(.489,.561),(.478,.574)],(161,165,156),.003,9)
    line([(.477,.573),(.490,.574)],(48,53,50),.004,6)
    poly([(.418,.491),(.409,.526),(.423,.530),(.431,.501)],(43,49,47),8)
    poly([(.410,.510),(.424,.514),(.421,.525),(.408,.521)],(193,198,188),8)
    poly([(.414,.493),(.438,.494),(.437,.503),(.414,.502)],(134,45,37),12)
    ellipse((.405,.500,.415,.508),(178,114,48),17)

    # White tail and dark saddle, with curved panel outlines.
    poly([(.412,.483),(.422,.478),(.446,.480),(.470,.486),(.495,.491),(.495,.507),(.472,.511),(.444,.502),(.422,.498)],(230,233,225),22)
    line([(.417,.485),(.447,.484),(.476,.492)],(250,251,242),.0022,5)
    poly([(.441,.480),(.458,.477),(.477,.480),(.500,.482),(.518,.489),(.516,.501),(.488,.502),(.468,.494),(.443,.490)],(31,36,36),12)
    line([(.446,.481),(.473,.484),(.495,.487),(.511,.493)],(93,98,95),.0018,6)
    poly([(.468,.503),(.495,.507),(.507,.523),(.490,.536),(.475,.528)],(217,223,216),19)
    poly([(.479,.514),(.491,.516),(.498,.523),(.489,.529),(.480,.524)],(55,63,62),9)

    # Rounded fuel tank and white, sculpted front fairing.
    poly([(.496,.488),(.501,.478),(.513,.470),(.534,.470),(.546,.477),(.554,.489),(.555,.505),(.545,.518),(.525,.520),(.510,.511),(.498,.501)],(231,235,228),27)
    line([(.507,.482),(.520,.477),(.536,.480),(.544,.485)],(251,252,243),.0025,5)
    ellipse((.521,.470,.536,.477),(106,114,110),14)
    ellipse((.524,.471,.534,.475),(192,198,188),12)
    poly([(.543,.513),(.552,.492),(.571,.481),(.591,.486),(.607,.501),(.604,.522),(.590,.547),(.579,.571),(.559,.578),(.543,.569),(.548,.548),(.534,.532)],(224,231,224),30)
    poly([(.546,.530),(.559,.522),(.578,.522),(.564,.547),(.552,.560),(.546,.551)],(56,66,65),15)
    line([(.554,.526),(.571,.525)],(125,136,130),.0016,6)
    poly([(.562,.553),(.581,.538),(.579,.558),(.569,.570),(.556,.571)],(191,203,199),18)
    line([(.579,.495),(.594,.507),(.591,.526),(.582,.542)],(249,252,243),.002,5)
    line([(.547,.568),(.560,.573),(.574,.565)],(115,131,128),.0016,7)

    # Fork legs and the curved white front mudguard.
    line([(.580,.514),(.606,.594)],(69,76,74),.008,14)
    line([(.587,.511),(.615,.597)],(150,159,154),.006,22)
    line([(.587,.517),(.609,.582)],(221,225,212),.002,9)
    line([(.580,.519),(.597,.571)],(196,202,186),.003,15)
    poly([(.564,.563),(.570,.551),(.584,.544),(.601,.543),(.617,.545),(.632,.552),(.643,.563),(.640,.570),(.627,.560),(.611,.555),(.594,.555),(.579,.558),(.571,.569)],(226,233,225),24)
    line([(.575,.552),(.591,.547),(.608,.548),(.625,.553)],(250,251,239),.0018,6)
    poly([(.597,.577),(.608,.577),(.613,.589),(.606,.595),(.596,.590)],(65,74,69),13)
    ellipse((.606,.591,.617,.602),(175,184,169),17)
    ellipse((.610,.594,.614,.599),(54,61,54),6)

    # Front cowl, unlit glass headlight, windshield, handlebars, and mirrors.
    poly([(.563,.475),(.576,.460),(.589,.459),(.601,.469),(.611,.485),(.613,.499),(.602,.509),(.584,.507),(.568,.493)],(234,239,231),26)
    poly([(.595,.484),(.607,.489),(.610,.497),(.601,.503),(.588,.498),(.586,.490)],(74,89,87),12)
    poly([(.597,.487),(.605,.491),(.606,.496),(.600,.500),(.591,.496),(.591,.490)],(193,208,199),19)
    line([(.595,.490),(.603,.494)],(243,246,224),.0018,4)
    poly([(.567,.462),(.558,.440),(.560,.429),(.573,.421),(.585,.424),(.594,.441),(.601,.467),(.585,.473)],(116,140,140),22,.87)
    poly([(.563,.441),(.564,.431),(.574,.425),(.583,.428),(.591,.443),(.594,.455),(.579,.460)],(164,185,181),16,.61)
    line([(.560,.433),(.563,.428),(.575,.423),(.584,.427)],(211,223,212),.0012,4,.82)
    line([(.571,.467),(.550,.459),(.530,.464)],(44,52,50),.0035,10)
    line([(.530,.464),(.520,.462)],(29,35,33),.004,7)
    line([(.570,.463),(.597,.469),(.610,.466)],(70,80,74),.003,11)
    line([(.610,.466),(.619,.468)],(33,39,35),.004,7)
    line([(.543,.459),(.536,.439),(.526,.433)],(56,65,62),.0024,11)
    ellipse((.512,.422,.536,.435),(42,51,48),15)
    ellipse((.515,.424,.532,.431),(126,147,139),14)
    line([(.597,.465),(.608,.444),(.617,.438)],(62,72,66),.0024,10)
    ellipse((.612,.429,.634,.441),(45,55,49),15)
    ellipse((.615,.431,.630,.437),(134,154,141),14)
    ellipse((.603,.506,.614,.514),(159,116,57),15)
    line([(.571,.474),(.579,.476)],(40,50,47),.002,6)

    rendered = cv2.resize(np.clip(work,0,255),(w,h),interpolation=cv2.INTER_AREA)
    obj_a = cv2.resize(coverage,(w,h),interpolation=cv2.INTER_AREA)
    # A faint, softened motorcycle reflection follows the wet ground plane.
    reflected_y = (ground-(Y-ground)/.42)*h
    ref_rgb = cv2.remap(rendered,xx,reflected_y.astype(np.float32),cv2.INTER_LINEAR,
                        borderMode=cv2.BORDER_REFLECT_101)
    ref_a = cv2.remap(obj_a,xx,reflected_y.astype(np.float32),cv2.INTER_LINEAR,
                      borderMode=cv2.BORDER_CONSTANT,borderValue=0)
    ref_a *= (Y>ground+.006).astype(np.float32)
    ref_a *= np.clip(1-(Y-ground)/.115,0,1)*.14
    ref_a = cv2.GaussianBlur(ref_a,(0,0),max(.8,unit*.0037))
    ref_rgb = cv2.GaussianBlur(ref_rgb,(0,0),max(.7,unit*.0028))
    ref_a[protected>0] = 0
    result = rendered*(1-ref_a[...,None]) + ref_rgb*ref_a[...,None]
    result[protected>0] = src[protected>0]
    return Image.fromarray(np.clip(result,0,255).astype(np.uint8), 'RGB')
remove the items from every shelf
magicbrush_train_357057_3 · remove · execution=passed
FAILinstr 3preserve 5quality 4
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The basket and toiletries on the upper left shelf were mostly removed, but an item remains on the right glass shelf near the sink, so not every shelf was cleared. Unrelated bathroom content is well preserved, and the edit quality is generally acceptable aside from minor remnants/blur on the shelves.

l1=0.0027 · gain=-0.0007 · mask_l1=0.0011 · preserve_l1=0.0044

reasoning / plan
{
 "visual_evidence": [
  "The upper white shelf holds a wicker basket with green and blue toiletries.",
  "The wider white shelf above the toilet appears empty.",
  "A small metallic container sits on the narrow shelf beneath the mirror.",
  "A green soap item is visible in the wall-mounted soap dish."
 ],
 "target_object": "Items resting on the shelves and in the soap dish",
 "target_region": "Upper-left shelf, narrow shelf beneath the mirror, and right-side soap dish",
 "editing_intent": "Remove the shelf contents and soap while leaving the shelves, dish, and bathroom fixtures intact.",
 "editing_plan": [
  "Mask the basket, its contents, the metallic container, and the soap.",
  "Reconstruct exposed patterned wall using texture patches matched from unobstructed wall areas in the source image.",
  "Restore the small obscured portions of the white shelf and narrow shelf edge.",
  "Reconstruct the empty soap-dish interior with sampled color, shallow shading, and fine noise.",
  "Feather the edited boundaries and preserve all other pixels."
 ],
 "preservation_constraints": [
  "Keep both white shelves and the narrow shelf beneath the mirror.",
  "Keep the soap-dish rim, body, and mounting.",
  "Preserve the wallpaper pattern, mirror, hair dryer, tissue dispenser, toilet, sinks, taps, and plumbing.",
  "Do not change the already-empty lower white shelf."
 ]
}
pixel code
def edit(image):
    import cv2
    import numpy as np
    from PIL import Image

    image = image.convert('RGB')
    w, h = image.size
    original = np.asarray(image).copy()
    result = original.copy()
    rng = np.random.default_rng(47)
    yy, xx = np.mgrid[0:h, 0:w]
    X = xx / float(w)
    Y = yy / float(h)

    def polygon(points):
        m = np.zeros((h, w), np.uint8)
        p = np.array([[round(x*w), round(y*h)] for x, y in points], np.int32)
        cv2.fillPoly(m, [p], 255)
        return m

    def rectangle(x0, y0, x1, y1):
        return ((X >= x0) & (X <= x1) & (Y >= y0) & (Y <= y1)).astype(np.uint8)*255

    def blend_pixels(new_pixels, mask, sigma=0.0013):
        nonlocal result
        if not np.any(mask):
            return
        alpha = cv2.GaussianBlur(mask.astype(np.float32)/255.0, (0, 0), max(0.45, sigma*min(w,h)))
        result = np.clip(result.astype(np.float32)*(1-alpha[...,None]) + new_pixels.astype(np.float32)*alpha[...,None], 0, 255).astype(np.uint8)

    basket = polygon([(0.277,0.198),(0.307,0.198),(0.311,0.205),(0.350,0.205),(0.351,0.215),(0.361,0.216),(0.366,0.242),(0.360,0.271),(0.276,0.271),(0.268,0.242),(0.269,0.215),(0.277,0.212)])
    metal = polygon([(0.943,0.480),(0.969,0.480),(0.976,0.487),(0.974,0.507),(0.969,0.522),(0.939,0.519),(0.939,0.497)])
    soap = polygon([(0.834,0.615),(0.851,0.611),(0.883,0.611),(0.905,0.614),(0.917,0.624),(0.910,0.638),(0.852,0.640),(0.833,0.630)])

    # Only verified unobstructed wallpaper is eligible for patch sourcing.
    safe = np.zeros((h,w), np.uint8)
    for box in [(0.014,0.015,0.400,0.414),(0.014,0.305,0.445,0.414),(0.012,0.075,0.198,0.550),(0.289,0.535,0.694,0.819),(0.767,0.457,0.999,0.725)]:
        safe = cv2.bitwise_or(safe, rectangle(*box))
    exclusions = [
        rectangle(0.202,0.246,0.475,0.296),
        rectangle(0.395,0.000,0.605,0.146),
        rectangle(0.474,0.127,0.555,0.412),
        rectangle(0.383,0.530,0.535,0.690),
        rectangle(0.676,0.690,0.742,0.774),
        rectangle(0.824,0.488,0.999,0.554),
        rectangle(0.813,0.604,0.944,0.684)
    ]
    for m in exclusions + [basket, metal, soap]:
        safe[m > 0] = 0

    # Match the surrounding ornamental pattern rather than smearing it.
    gray = cv2.cvtColor(original, cv2.COLOR_RGB2GRAY).astype(np.float32)
    hp = gray - cv2.GaussianBlur(gray, (0,0), max(1.0, 0.008*w))

    def restore_wall(mask):
        if not np.any(mask):
            return
        ys, xs = np.where(mask > 0)
        pad = max(4, round(0.020*min(w,h)))
        x0, x1 = max(0,int(xs.min())-pad), min(w,int(xs.max())+pad+1)
        y0, y1 = max(0,int(ys.min())-pad), min(h,int(ys.max())+pad+1)
        local_mask = mask[y0:y1,x0:x1]
        kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2*pad+1,2*pad+1))
        expanded = cv2.dilate(mask, kernel)
        ring = ((expanded > 0) & (mask == 0) & (safe > 0)).astype(np.uint8)
        local_ring = ring[y0:y1,x0:x1]
        support = ((local_mask > 0) | (local_ring > 0)).astype(np.float32)
        if int(local_ring.sum()) < 12:
            filled = cv2.inpaint(result, mask, max(2,round(0.009*w)), cv2.INPAINT_TELEA)
            blend_pixels(filled, mask)
            return
        template = hp[y0:y1,x0:x1]
        scores = cv2.matchTemplate(hp, template, cv2.TM_SQDIFF, mask=local_ring)
        scores = np.nan_to_num(scores, nan=1e20, posinf=1e20, neginf=1e20)
        valid_count = cv2.matchTemplate((safe>0).astype(np.float32), support, cv2.TM_CCORR)
        valid = valid_count >= float(support.sum())*0.998
        scores[~valid] = 1e20
        if not np.any(valid):
            filled = cv2.inpaint(result, mask, max(2,round(0.009*w)), cv2.INPAINT_TELEA)
            blend_pixels(filled, mask)
            return
        sy, sx = np.unravel_index(np.argmin(scores), scores.shape)
        ph, pw = template.shape
        patch = original[sy:sy+ph,sx:sx+pw].astype(np.float32)
        target_patch = original[y0:y1,x0:x1].astype(np.float32)
        r = local_ring > 0
        offset = np.median(target_patch[r]-patch[r], axis=0)
        patch += np.clip(offset, -28, 28)
        patch += rng.normal(0, 0.45, patch.shape).astype(np.float32)
        canvas = result.copy()
        canvas[y0:y1,x0:x1] = np.clip(patch,0,255).astype(np.uint8)
        blend_pixels(canvas, mask)

    # Split the basket removal at the existing shelf's upper surface.
    shelf_top = 0.253 + 0.035*(X-0.215)
    basket_wall = np.where((basket>0) & (Y<shelf_top),255,0).astype(np.uint8)
    basket_shelf = np.where((basket>0) & (Y>=shelf_top),255,0).astype(np.uint8)
    restore_wall(basket_wall)

    if np.any(basket_shelf):
        filled = cv2.inpaint(result, basket_shelf, max(2,round(0.014*w)), cv2.INPAINT_TELEA).astype(np.float32)
        rows = np.where(np.any(basket_shelf>0,axis=1))[0]
        sample_columns = ((X[0]>=0.221)&(X[0]<=0.263)) | ((X[0]>=0.369)&(X[0]<=0.426))
        for y in rows:
            samples = original[y, sample_columns].astype(np.float32)
            brightness = samples.mean(axis=1)
            neutral = (samples.max(axis=1)-samples.min(axis=1)) < 40
            samples = samples[(brightness>150)&neutral]
            if len(samples) >= 3:
                color = np.median(samples,axis=0)
                columns = np.where(basket_shelf[y]>0)[0]
                noise = rng.normal(0,0.8,(len(columns),1))
                filled[y,columns] = 0.91*(color[None,:]+noise)+0.09*filled[y,columns]
        blend_pixels(np.clip(filled,0,255).astype(np.uint8),basket_shelf)

    # Preserve the narrow shelf and only repair the small interrupted edge.
    rail_y = 0.507 + 0.090*(X-0.843)
    metal_wall = np.where((metal>0)&(Y<rail_y-0.002),255,0).astype(np.uint8)
    metal_rail = np.where((metal>0)&(Y>=rail_y-0.002),255,0).astype(np.uint8)
    restore_wall(metal_wall)
    if np.any(metal_rail):
        repaired = cv2.inpaint(result, metal_rail, max(2,round(0.006*w)), cv2.INPAINT_TELEA)
        blend_pixels(repaired,metal_rail,0.001)

    # Remove the projecting soap, retaining the dish's exterior and rim.
    cx, cy = 0.879, 0.636
    rx, ry = 0.038, 0.012
    u = (X-cx)/rx
    v = (Y-cy)/ry
    ellipse_distance = u*u+v*v
    interior = ellipse_distance < 1.0
    dish_back = 0.627 + 0.017*np.minimum(np.abs(u),1.0)**2
    soap_wall = np.where((soap>0)&(~interior)&(Y<dish_back),255,0).astype(np.uint8)
    restore_wall(soap_wall)

    rim_samples = []
    for box in [(0.832,0.637,0.847,0.650),(0.908,0.637,0.923,0.650),(0.860,0.653,0.899,0.661)]:
        m = rectangle(*box)>0
        p = original[m].astype(np.float32)
        if len(p):
            rim_samples.append(p)
    rim = np.median(np.concatenate(rim_samples,axis=0),axis=0)
    white_sample = original[rectangle(0.300,0.462,0.370,0.476)>0].astype(np.float32)
    shelf_white = np.median(white_sample,axis=0) if len(white_sample) else np.array([220.,220.,213.])
    base = 0.77*rim + 0.23*shelf_white
    # A shallow concave opening: shaded back, softly lit center and front.
    radial = np.clip(ellipse_distance,0,1)
    back_shadow = 15*np.exp(-((v+0.69)/0.22)**2)
    bowl_shading = 5.0*(1-radial) + 4.0*v - back_shadow
    texture = rng.normal(0,0.9,(h,w))
    bowl = base[None,None,:] + bowl_shading[...,None] + texture[...,None]
    bowl = np.clip(bowl,0,255).astype(np.uint8)
    interior_alpha = np.clip((1.0-ellipse_distance)/0.17,0,1)
    interior_mask = (interior_alpha*255).astype(np.uint8)
    blend_pixels(bowl, interior_mask,0.0009)

    # Any small soap remnants at the inner lip are filled from the new dish.
    lip_remnant = ((soap>0)&(~interior)&(Y>=dish_back)&(Y<0.643)).astype(np.uint8)*255
    if np.any(lip_remnant):
        repaired = cv2.inpaint(result, lip_remnant, max(2,round(0.004*w)), cv2.INPAINT_TELEA)
        blend_pixels(repaired,lip_remnant,0.0009)

    return Image.fromarray(result, 'RGB')
let the man wear a sombrero
magicbrush_train_50058_2 · add / insert · execution=passed
PASSinstr 4preserve 5quality 4
source
GPT-6.1-Sol output
MagicBrush target (reference only)

A sombrero was added to the man's head area and the rest of the scene is essentially unchanged. The edit is visually decent, though the hat appears somewhat pasted on and sits awkwardly over the existing helmet rather than fully integrating as something he is naturally wearing.

l1=0.0075 · gain=-0.0003 · mask_l1=0.0019 · preserve_l1=0.0275

reasoning / plan
{
 "visual_evidence": [
  "The man is wearing a light-colored helmet and green-tinted goggles.",
  "His head is above a bright yellow jacket near the upper center of the image.",
  "He is airborne with a red snowboard against a pale, snowy background."
 ],
 "target_object": "The man's headwear",
 "target_region": "The helmet and surrounding space immediately above the man's head",
 "editing_intent": "Replace the visible helmet shell with a realistically shaded, woven-straw sombrero while retaining the goggles and face.",
 "editing_plan": [
  "Mask and inpaint the exposed helmet shell without removing the goggles or face.",
  "Add a small textured hair region beneath the new hat.",
  "Construct a wide, slightly tilted and curled straw brim and a tall, rounded crown.",
  "Add woven texture, a decorative hatband, edge highlights, and crown and facial shadows.",
  "Feather the new headwear into the photograph and preserve all pixels outside the edit."
 ],
 "preservation_constraints": [
  "Keep the man's face and visible goggles recognizable.",
  "Do not change his pose, yellow jacket, blue trousers, or red snowboard.",
  "Preserve the snowy background and foreground terrain outside the hat area.",
  "Match the photograph's soft lighting and modest image sharpness."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    image = image.convert('RGB')
    w, h = image.size
    original = np.asarray(image).copy()
    rng = np.random.default_rng(27)

    # Remove only the exposed helmet shell, avoiding the goggles and face.
    shell_points = np.array([
        [.438,.320],[.435,.307],[.440,.289],[.454,.275],
        [.478,.265],[.507,.267],[.530,.281],[.542,.303],
        [.542,.309],[.500,.316],[.477,.328],[.470,.355],
        [.457,.351],[.446,.339]
    ], dtype=np.float32)
    removal = np.zeros((h,w), np.uint8)
    cv2.fillPoly(removal, [np.round(shell_points * [w,h]).astype(np.int32)], 255)
    filled = cv2.inpaint(original, removal, max(2, int(round(w*.007))), cv2.INPAINT_TELEA)

    # Supersample the constructed object for soft, photographic edges.
    W, H = 2*w, 2*h
    canvas = np.asarray(Image.fromarray(filled).resize((W,H), Image.Resampling.LANCZOS)).astype(np.float32)
    yy, xx = np.mgrid[0:H,0:W].astype(np.float32)
    u, v = (xx+.5)/W, (yy+.5)/H
    scale = min(W,H)/1024.0
    edge_sigma = max(.45, .7*scale)
    changed = cv2.resize(removal.astype(np.float32)/255, (W,H), interpolation=cv2.INTER_LINEAR)

    def soften(mask, sigma=edge_sigma):
        return np.clip(cv2.GaussianBlur(mask.astype(np.float32), (0,0), sigma), 0, 1)

    def polygon(points):
        m = np.zeros((H,W), np.uint8)
        pts = np.round(np.asarray(points)*[W,H]).astype(np.int32)
        cv2.fillPoly(m, [pts], 255)
        return soften(m.astype(np.float32)/255)

    def put(rgb, alpha):
        nonlocal canvas, changed
        alpha = np.clip(alpha,0,1)
        canvas = canvas*(1-alpha[...,None]) + np.asarray(rgb, dtype=np.float32)*alpha[...,None]
        changed = np.maximum(changed, alpha)

    noise = rng.normal(0,1,(H,W)).astype(np.float32)
    fine = cv2.GaussianBlur(noise, (0,0), max(.35,.42*scale))
    coarse = cv2.GaussianBlur(noise, (0,0), max(1.0,3.0*scale))
    coarse /= max(float(coarse.std()), .0001)

    # A narrow dark hair/temple area replaces the helmet's exposed side.
    hair_mask = polygon([
        [.446,.315],[.474,.312],[.484,.327],[.478,.345],
        [.466,.352],[.453,.344]
    ])
    hair_strands = np.sin((u*W*1.5 + v*H*.36)) + .5*np.sin(u*W*3.3-v*H*.2)
    hair_light = 4*hair_strands + 3*fine + 2*coarse
    hair = np.stack([39+hair_light,31+hair_light*.85,24+hair_light*.65],axis=-1)
    put(np.clip(hair,0,255), hair_mask)

    # Only foreground skin, goggles, and hood receive the soft hat shadow.
    src_hi = np.asarray(image.resize((W,H), Image.Resampling.LANCZOS)).astype(np.float32)
    saturation = src_hi.max(axis=2)-src_hi.min(axis=2)
    shadow = np.exp(-(((u-.486)/.061)**2 + ((v-.337)/.023)**2)*1.8)
    shadow *= np.clip((v-.318)/.014,0,1)
    shadow *= np.clip((saturation-18)/38,0,1)*.17
    put(canvas*np.array([.76,.78,.80],np.float32), soften(shadow, max(.7,1.5*scale)))

    # A tilted ellipse with raised outer sides gives the brim a curled profile.
    qx = (u-.488)/.160
    centerline = .297 - .075*(u-.488) - .012*qx*qx
    qy = (v-centerline)/.026
    radius = np.sqrt(qx*qx+qy*qy)
    theta = np.arctan2(qy,qx)
    brim_mask = soften((radius <= 1).astype(np.float32))

    rings = np.sin(radius*228 + .65*np.sin(theta*19))
    spokes = np.sin(theta*235 + radius*11)
    weave = 2.0*rings + 1.1*spokes + .6*rings*spokes
    light = .96 - .075*qx - .055*qy + .06*(1-np.minimum(radius,1))
    rim_dark = np.exp(-((radius-.989)/.016)**2)
    rim_highlight = np.exp(-((radius-.949)/.021)**2)
    light += .12*rim_highlight - .24*rim_dark
    variation = weave + 1.65*fine + 1.35*coarse
    brim = np.stack([
        201*light+variation,
        162*light+variation*.9,
        103*light+variation*.7
    ],axis=-1)

    # Crown shadow falls primarily on the forward-right part of the brim.
    crown_shadow = np.exp(-(((u-.510)/.061)**2+((v-.304)/.010)**2)*1.6)
    brim *= (1-.20*crown_shadow)[...,None]
    brim = np.clip(brim,0,255)
    put(brim, brim_mask)

    def bezier(p0,p1,p2,p3,n=40):
        t = np.linspace(0,1,n)[:,None]
        a,b,c,d = [np.asarray(p,dtype=np.float32)[None,:] for p in (p0,p1,p2,p3)]
        return ((1-t)**3*a + 3*(1-t)**2*t*b + 3*(1-t)*t*t*c + t**3*d)

    crown_path = np.concatenate([
        bezier((.435,.304),(.440,.281),(.448,.236),(.457,.217)),
        bezier((.457,.217),(.462,.198),(.472,.187),(.487,.185)),
        bezier((.487,.185),(.508,.181),(.518,.191),(.524,.208)),
        bezier((.524,.208),(.535,.235),(.539,.270),(.549,.296)),
        bezier((.549,.296),(.520,.315),(.465,.318),(.435,.304))
    ])
    crown_mask = polygon(crown_path)
    z = np.clip((v-.185)/.124,0,1)
    half_width = .027+.031*z
    crown_center = .489+.004*z
    side = (u-crown_center)/half_width
    cylinder = np.sqrt(np.clip(1-side*side,0,1))
    crown_light = .91 - .13*side + .13*cylinder - .075*z
    crown_light -= .055*np.exp(-((side-.60)/.13)**2)
    crown_light += .035*np.exp(-((side+.46)/.16)**2)
    row_phase = (v*H/2.55) + .8*cylinder
    vertical_phase = (side*33 + .15*np.sin(v*H*.17))
    straw = 1.8*np.sin(2*np.pi*row_phase)
    straw += 1.3*np.sin(2*np.pi*vertical_phase)
    straw += .65*np.sin(2*np.pi*(row_phase+vertical_phase))
    straw += 1.9*fine + 1.25*coarse
    crown = np.stack([
        211*crown_light+straw,
        173*crown_light+straw*.90,
        114*crown_light+straw*.72
    ],axis=-1)

    # A curved leather-and-thread band follows the crown's rounded base.
    band_top = .273 + .006*(1-np.clip(side*side,0,1)) - .003*side
    band_t = (v-band_top)/.018
    band_mask = soften(((band_t>=0)&(band_t<=1)).astype(np.float32))*crown_mask
    leather = np.stack([
        97*crown_light+2*fine,
        61*crown_light+1.6*fine,
        33*crown_light+fine
    ],axis=-1)
    edge_thread = np.exp(-((band_t-.13)/.045)**2) + np.exp(-((band_t-.86)/.045)**2)
    leather += edge_thread[...,None]*np.array([51,44,27],np.float32)
    zigzag = np.abs(((side*5.5)%1)-.5)*1.16+.20
    stitch = np.exp(-((band_t-zigzag)/.050)**2)
    stitch *= .65+.35*np.cos(side*W*2.1)**2
    thread = np.zeros_like(leather)+np.array([183,135,61],np.float32)
    leather = leather*(1-stitch[...,None]*.85)+thread*stitch[...,None]*.85
    crown = np.clip(crown,0,255)
    put(crown, crown_mask)
    put(np.clip(leather,0,255), band_mask)

    # The forward lip sits in front of the crown, not behind it.
    front = brim_mask*soften((qy>.13).astype(np.float32))
    put(brim, front)

    # Fine irregular fibers and a narrow light-catching rim.
    lip = np.exp(-((radius-.956)/.014)**2)*brim_mask
    lip *= .40+.20*np.clip(-qx,0,1)
    lip *= .72+.28*np.sin(theta*119+radius*29)**2
    lip_color = np.zeros_like(canvas)+np.array([224,191,135],np.float32)
    put(lip_color, lip*.23)

    # Downsample only the affected region; every other source pixel is preserved.
    rendered = np.asarray(Image.fromarray(np.clip(canvas,0,255).astype(np.uint8)).resize((w,h),Image.Resampling.LANCZOS)).astype(np.float32)
    affected = cv2.resize(np.clip(changed,0,1),(w,h),interpolation=cv2.INTER_AREA)
    affected = np.clip(affected,0,1)
    result = original.astype(np.float32)*(1-affected[...,None]) + rendered*affected[...,None]
    return Image.fromarray(np.clip(np.round(result),0,255).astype(np.uint8), 'RGB')
make the cat lick his paw
magicbrush_train_373038_1 · replace / change · execution=passed
PASSinstr 4preserve 4quality 3
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The edit successfully makes the cat appear to lick a paw by adding a raised paw near the mouth and a visible tongue. The rest of the scene is largely unchanged, though the added paw/limb looks somewhat unnatural and blended imperfectly.

l1=0.0205 · gain=-0.0007 · mask_l1=0.0104 · preserve_l1=0.0236

reasoning / plan
{
 "visual_evidence": [
  "A pale, gray-striped cat is curled inside a black mesh basket.",
  "The cat's eyes, pink nose, and light-colored muzzle are visible.",
  "Light-colored paws and foreleg fur are visible against the curled body.",
  "A red scooter and part of a dark wheel surround the basket."
 ],
 "target_object": "The cat's front paw and mouth",
 "target_region": "Immediately below the muzzle, extending toward the light-colored chest",
 "editing_intent": "Raise a fur-textured front paw to the cat's mouth and show a short pink tongue touching it.",
 "editing_plan": [
  "Extract a softly masked paw patch from the cat's visible light-colored paw.",
  "Construct a bent foreleg using texture sampled from the cat's own fur.",
  "Rotate and position the paw beneath the muzzle, blending it into the new foreleg.",
  "Add soft contact shadows and preserve the source photograph's lighting and texture.",
  "Paint a small shaded tongue extending from the mouth to the raised paw."
 ],
 "preservation_constraints": [
  "Keep the cat's eyes, nose, ears, facial markings, and expression intact.",
  "Preserve the curled body and all pixels outside the local paw-and-mouth edit.",
  "Do not change the basket, scooter, wheel, or background.",
  "Retain the photographic fur texture rather than using flat fills."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    w, h = image.size
    original = np.asarray(image.convert('RGB')).astype(np.float32)
    result = original.copy()
    scale = min(w, h)
    rng = np.random.default_rng(23)
    yy, xx = np.mgrid[0:h, 0:w].astype(np.float32)
    X, Y = xx / w, yy / h

    def feather(mask, radius):
        return np.clip(cv2.GaussianBlur(mask.astype(np.float32), (0, 0), max(radius, 0.25)), 0, 1)

    def polygon_mask(points):
        supersample = 3
        canvas = np.zeros((h * supersample, w * supersample), np.uint8)
        pts = np.asarray(points, np.float32) * np.array([w, h], np.float32)
        pts = np.round(pts * supersample).astype(np.int32)
        cv2.fillPoly(canvas, [pts], 255)
        return cv2.resize(canvas, (w, h), interpolation=cv2.INTER_AREA).astype(np.float32) / 255

    def bezier_shape(start, segments):
        points = [start]
        p0 = np.asarray(start, np.float32)
        for c1, c2, end in segments:
            p1, p2, p3 = [np.asarray(p, np.float32) for p in (c1, c2, end)]
            for t in np.linspace(0, 1, 22)[1:]:
                points.append((1-t)**3*p0 + 3*(1-t)**2*t*p1 + 3*(1-t)*t*t*p2 + t**3*p3)
            p0 = p3
        return polygon_mask(points)

    def blend(texture, alpha):
        nonlocal result
        a = np.clip(alpha, 0, 1)[..., None]
        result = result * (1-a) + np.asarray(texture, np.float32) * a

    # A softly curved foreleg, attached to the existing chest.
    controls = np.array([[0.474, 0.578], [0.429, 0.569], [0.389, 0.542], [0.350, 0.503]], np.float32)
    ts = np.linspace(0, 1, 95).astype(np.float32)
    centers, normals, widths = [], [], []
    for t in ts:
        p = (1-t)**3*controls[0] + 3*(1-t)**2*t*controls[1] + 3*(1-t)*t*t*controls[2] + t**3*controls[3]
        d = 3*(1-t)**2*(controls[1]-controls[0]) + 6*(1-t)*t*(controls[2]-controls[1]) + 3*t*t*(controls[3]-controls[2])
        normal = np.array([-d[1], d[0]], np.float32)
        normal /= np.linalg.norm(normal) + 1e-8
        centers.append(p)
        normals.append(normal)
        widths.append(0.034*(1-t) + 0.023*t)
    centers, normals, widths = np.asarray(centers), np.asarray(normals), np.asarray(widths)
    outline = list(centers + normals*widths[:, None]) + list((centers - normals*widths[:, None])[::-1])
    leg_mask = feather(polygon_mask(outline), 0.0015*scale)

    nearest = np.zeros((h, w), np.int32)
    best = np.full((h, w), np.inf, np.float32)
    for i, center in enumerate(centers):
        distance = (X-center[0])**2 + (Y-center[1])**2
        choose = distance < best
        best[choose] = distance[choose]
        nearest[choose] = i
    cx, cy = centers[nearest, 0], centers[nearest, 1]
    nx, ny = normals[nearest, 0], normals[nearest, 1]
    across = np.clip(((X-cx)*nx + (Y-cy)*ny) / widths[nearest], -1, 1)
    along = ts[nearest]
    map_x = ((0.456 + 0.050*across) * w).astype(np.float32)
    map_y = ((0.490 + 0.093*along) * h).astype(np.float32)
    leg_texture = cv2.remap(original, map_x, map_y, cv2.INTER_CUBIC, borderMode=cv2.BORDER_REFLECT_101)
    shading = 1.025 - 0.115*np.abs(across)**1.7 - 0.025*across
    leg_texture = np.clip(leg_texture * shading[..., None], 0, 255)
    leg_mask *= np.clip(along / 0.22, 0, 1)

    # Copy the existing pale paw, excluding its surrounding basket and fur.
    paw_source_mask = bezier_shape((0.058, 0.548), [
        ((0.066, 0.535), (0.083, 0.539), (0.091, 0.559)),
        ((0.102, 0.578), (0.102, 0.603), (0.095, 0.626)),
        ((0.091, 0.645), (0.078, 0.651), (0.056, 0.645)),
        ((0.035, 0.635), (0.031, 0.615), (0.037, 0.588)),
        ((0.039, 0.570), (0.047, 0.553), (0.058, 0.548))
    ])
    paw_source_mask = feather(paw_source_mask, 0.0012*scale)
    source_center = np.array([0.068*w, 0.598*h], np.float32)
    destination_center = np.array([0.354*w, 0.518*h], np.float32)
    angle = np.deg2rad(34)
    rotation = 0.91*np.array([[np.cos(angle), np.sin(angle)], [-np.sin(angle), np.cos(angle)]], np.float32)
    transform = np.column_stack([rotation, destination_center - rotation @ source_center]).astype(np.float32)
    paw_mask = cv2.warpAffine(paw_source_mask, transform, (w, h), flags=cv2.INTER_LINEAR)
    paw_texture = cv2.warpAffine(original, transform, (w, h), flags=cv2.INTER_CUBIC, borderMode=cv2.BORDER_REFLECT_101)

    # The new limb lies on the chest; its shadow stays local and softly edged.
    union = np.maximum(leg_mask, paw_mask)
    shadow_transform = np.array([[1, 0, 0.004*w], [0, 1, 0.005*h]], np.float32)
    shadow = cv2.warpAffine(union, shadow_transform, (w, h), flags=cv2.INTER_LINEAR)
    shadow = feather(shadow, 0.004*scale) * (1-union*0.65)
    result *= (1 - 0.14*shadow[..., None])
    blend(leg_texture, leg_mask)
    blend(np.clip(paw_texture*1.015, 0, 255), paw_mask)

    # A narrow mouth opening, placed below the original pink nose.
    mouth_canvas = np.zeros((h*3, w*3), np.uint8)
    mouth_points = np.array([[0.291, 0.447], [0.299, 0.450], [0.307, 0.451]], np.float32)
    mouth_points = np.round(mouth_points*np.array([w*3, h*3])).astype(np.int32)
    cv2.polylines(mouth_canvas, [mouth_points], False, 255, max(1, round(0.0030*scale*3)), cv2.LINE_AA)
    mouth_mask = cv2.resize(mouth_canvas, (w, h), interpolation=cv2.INTER_AREA).astype(np.float32)/255
    mouth_mask = feather(mouth_mask, 0.00065*scale)
    blend(np.array([91, 65, 61], np.float32), mouth_mask*0.65)

    # A rounded tongue reaches the upper-left edge of the raised paw.
    tongue_mask = bezier_shape((0.298, 0.449), [
        ((0.306, 0.448), (0.309, 0.454), (0.313, 0.461)),
        ((0.317, 0.468), (0.327, 0.473), (0.326, 0.481)),
        ((0.325, 0.487), (0.317, 0.487), (0.312, 0.479)),
        ((0.306, 0.472), (0.301, 0.461), (0.298, 0.449))
    ])
    tongue_mask = feather(tongue_mask, 0.00065*scale)
    interior = cv2.distanceTransform((tongue_mask > 0.45).astype(np.uint8), cv2.DIST_L2, 5)
    interior /= max(float(interior.max()), 1.0)
    length = np.clip((Y-0.449)/0.035, 0, 1)
    edge_color = np.array([176, 92, 104], np.float32)
    center_color = np.array([232, 151, 158], np.float32)
    tongue = edge_color + interior[..., None]*(center_color-edge_color)
    tongue += length[..., None]*np.array([7, 6, 4], np.float32)
    noise = rng.normal(0, 1.35, (h, w)).astype(np.float32)
    tongue += noise[..., None]
    # Subtle longitudinal groove and a moist highlight, both confined to the tongue.
    centerline_x = 0.302 + 0.019*length
    groove = np.exp(-((X-centerline_x)/0.0011)**2) * np.sin(np.pi*length)
    tongue -= groove[..., None]*np.array([12, 9, 8], np.float32)
    highlight = np.exp(-(((X-0.314)/0.0035)**2 + ((Y-0.469)/0.006)**2))
    tongue += highlight[..., None]*np.array([17, 14, 13], np.float32)
    tongue_shadow = cv2.warpAffine(tongue_mask, np.array([[1, 0, 0.001*w], [0, 1, 0.002*h]], np.float32), (w, h))
    tongue_shadow = feather(tongue_shadow, 0.0015*scale)*(1-tongue_mask)
    result *= 1-0.12*tongue_shadow[..., None]
    blend(np.clip(tongue, 0, 255), tongue_mask)

    return Image.fromarray(np.clip(result, 0, 255).astype(np.uint8), 'RGB')
make the elephant raise its trunk
magicbrush_train_549042_1 · replace / change · execution=passed
FAILinstr 3preserve 4quality 2
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The edit attempts to add a raised, curled trunk, but the original downward trunk remains visible, making the elephant look like it has an unnatural extra/duplicated trunk. Most unrelated background and body content is preserved, but the edit has obvious seams, mismatched texture, and unrealistic blending.

l1=0.0345 · gain=-0.0098 · mask_l1=0.0121 · preserve_l1=0.0602

reasoning / plan
{
 "visual_evidence": [
  "The elephant faces the camera in the foreground.",
  "Its wrinkled trunk hangs downward and reaches the bottom edge of the image.",
  "A gray block wall, green vegetation, and sunlit ground are visible behind it.",
  "The elephant has visible tusks, blue straps, and a saddle above its head."
 ],
 "target_object": "The elephant's trunk",
 "target_region": "The central hanging trunk, extending from the lower face to the bottom edge",
 "editing_intent": "Replace the downward-hanging trunk with a naturally curved trunk raised upward toward the right.",
 "editing_plan": [
  "Mask the hanging portion of the trunk without covering the tusks or adjacent legs.",
  "Reconstruct the exposed background and body using nearby pixels from the same image.",
  "Extract the trunk's existing skin texture and warp it along an upward-curving, tapering centerline.",
  "Add subtle rounded shading and a small textured opening at the curled tip.",
  "Feather the reconstructed regions and trunk edges while preserving the rest of the image."
 ],
 "preservation_constraints": [
  "Keep the elephant's eyes, ears, tusks, legs, saddle, and blue straps unchanged wherever they are not occluded by the raised trunk.",
  "Preserve the wall, vegetation, and ground outside the affected region.",
  "Retain the original image dimensions and natural skin texture.",
  "Do not add other animals, people, or accessories."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    original = np.asarray(image.convert('RGB')).copy()
    w, h = image.size
    scale = min(w, h)
    yy, xx = np.mgrid[0:h, 0:w].astype(np.float32)
    rng = np.random.default_rng(23)

    # Remove only the hanging trunk below its attachment to the face.
    outline = np.array([
        [0.586, 0.576], [0.733, 0.576], [0.743, 0.634],
        [0.744, 0.710], [0.744, 0.794], [0.752, 0.877],
        [0.762, 0.955], [0.752, 1.020], [0.681, 1.020],
        [0.661, 0.955], [0.643, 0.888], [0.628, 0.812],
        [0.611, 0.731], [0.601, 0.653]
    ], dtype=np.float32)
    outline *= np.array([w, h], dtype=np.float32)
    removal = np.zeros((h, w), np.uint8)
    cv2.fillPoly(removal, [np.rint(outline).astype(np.int32)], 255)
    dilation = max(1, int(round(scale * 0.004)))
    removal = cv2.dilate(removal, cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2*dilation+1, 2*dilation+1)))
    cleaned = cv2.inpaint(original, removal, max(2, int(scale*0.012)), cv2.INPAINT_TELEA).astype(np.float32)

    # Rebuild the narrow exposed strip with real adjacent body and landscape
    # textures. Sampling at the same height preserves the wall courses.
    body_edge = np.interp(yy[:, 0] / h,
        [0.0, 0.576, 0.635, 0.700, 0.790, 0.880, 1.0],
        [0.650, 0.650, 0.639, 0.628, 0.625, 0.628, 0.638]).astype(np.float32)[:, None] * w
    body_x = np.clip(xx - 0.112*w, 0, w-1).astype(np.float32)
    background_x = np.clip((0.800 + 0.85*(xx/w - 0.620))*w, 0, w-1).astype(np.float32)
    body_patch = cv2.remap(original, body_x, yy, cv2.INTER_LINEAR, borderMode=cv2.BORDER_REFLECT_101).astype(np.float32)
    landscape_patch = cv2.remap(original, background_x, yy, cv2.INTER_LINEAR, borderMode=cv2.BORDER_REFLECT_101).astype(np.float32)
    edge_width = max(0.75, scale*0.0022)
    landscape_weight = np.clip((xx-body_edge)/edge_width + 0.5, 0, 1)
    landscape_weight = landscape_weight*landscape_weight*(3-2*landscape_weight)
    # A small natural shadow at the exposed leg edge, not a broad blur.
    edge_shadow = np.exp(-np.maximum(xx-body_edge, 0)/max(1.0, scale*0.010))
    edge_shadow *= (xx >= body_edge).astype(np.float32)
    edge_shadow *= np.clip((yy/h-0.73)/0.15, 0, 1)
    landscape_patch *= (1.0-0.10*edge_shadow[..., None])
    reconstructed = body_patch*(1-landscape_weight[..., None]) + landscape_patch*landscape_weight[..., None]
    # The patches already contain scene grain; add only a very small residual.
    reconstructed += rng.normal(0, 0.32, (h, w, 1)).astype(np.float32)
    feather = cv2.GaussianBlur(removal.astype(np.float32)/255.0, (0, 0), max(0.55, scale*0.0015))
    base = cleaned*(1-feather[..., None]) + reconstructed*feather[..., None]
    untouched = removal == 0
    outside_feather = feather < 0.002
    base[untouched & outside_feather] = original[untouched & outside_feather]

    # A smooth raised-trunk curve: broad attachment, outward bend, upward
    # sweep, and a gently curled tip. Coordinates are resolution-relative.
    controls = np.array([
        [0.655, 0.558], [0.735, 0.608], [0.817, 0.595],
        [0.877, 0.529], [0.894, 0.444], [0.868, 0.376],
        [0.825, 0.356], [0.806, 0.373]
    ], np.float32) * np.array([w, h], np.float32)
    extended = np.vstack([2*controls[0]-controls[1], controls,
                          2*controls[-1]-controls[-2]])
    curve = []
    for i in range(1, len(extended)-2):
        p0, p1, p2, p3 = extended[i-1:i+3]
        for u in np.linspace(0, 1, 35, endpoint=False):
            point = 0.5*((2*p1) + (-p0+p2)*u +
                         (2*p0-5*p1+4*p2-p3)*u*u +
                         (-p0+3*p1-3*p2+p3)*u*u*u)
            curve.append(point)
    curve.append(controls[-1])
    curve = np.asarray(curve, np.float32)
    arc = np.r_[0.0, np.cumsum(np.linalg.norm(np.diff(curve, axis=0), axis=1))]
    count = max(140, int(scale*0.46))
    sampled_arc = np.linspace(0, arc[-1], count)
    path = np.column_stack([np.interp(sampled_arc, arc, curve[:, 0]),
                            np.interp(sampled_arc, arc, curve[:, 1])]).astype(np.float32)
    tangents = np.gradient(path, axis=0)
    tangents /= np.maximum(np.linalg.norm(tangents, axis=1, keepdims=True), 1e-6)
    normals = np.column_stack([-tangents[:, 1], tangents[:, 0]])

    # Find longitudinal and cross-sectional coordinates for each output pixel.
    nearest = np.full((h, w), np.inf, np.float32)
    longitudinal = np.zeros((h, w), np.float32)
    lateral = np.zeros((h, w), np.float32)
    normal_x = np.zeros((h, w), np.float32)
    normal_y = np.zeros((h, w), np.float32)
    for i in range(count-1):
        p = path[i]
        v = path[i+1]-p
        v2 = float(np.dot(v, v))
        if v2 < 1e-8:
            continue
        projection = np.clip(((xx-p[0])*v[0]+(yy-p[1])*v[1])/v2, 0, 1)
        cx = p[0]+projection*v[0]
        cy = p[1]+projection*v[1]
        dx, dy = xx-cx, yy-cy
        distance2 = dx*dx+dy*dy
        update = distance2 < nearest
        nx = normals[i, 0]*(1-projection)+normals[i+1, 0]*projection
        ny = normals[i, 1]*(1-projection)+normals[i+1, 1]*projection
        norm = np.maximum(np.sqrt(nx*nx+ny*ny), 1e-6)
        nx, ny = nx/norm, ny/norm
        nearest[update] = distance2[update]
        longitudinal[update] = ((i+projection)/(count-1))[update]
        lateral[update] = (dx*nx+dy*ny)[update]
        normal_x[update], normal_y[update] = nx[update], ny[update]

    radii = np.interp(longitudinal,
        [0, 0.14, 0.30, 0.47, 0.64, 0.80, 0.93, 1],
        [0.067, 0.063, 0.055, 0.046, 0.037, 0.027, 0.019, 0.016]).astype(np.float32)*w
    cross = np.clip(lateral/np.maximum(radii, 1), -1, 1)

    # Texture coordinates follow the original trunk axis. Sampling a little
    # inside its edges prevents background colors from contaminating skin.
    source_y = (0.558 + 0.426*longitudinal)*h
    source_axis_y = np.array([0.558, 0.640, 0.740, 0.840, 0.925, 0.984], np.float32)*h
    source_axis_x = np.array([0.658, 0.670, 0.680, 0.692, 0.708, 0.719], np.float32)*w
    source_width = np.array([0.064, 0.059, 0.053, 0.046, 0.037, 0.028], np.float32)*w
    source_center = np.interp(source_y, source_axis_y, source_axis_x).astype(np.float32)
    source_radius = np.interp(source_y, source_axis_y, source_width).astype(np.float32)
    source_slope = np.interp(source_y, source_axis_y,
        np.gradient(source_axis_x, source_axis_y)).astype(np.float32)
    source_norm = np.sqrt(1+source_slope*source_slope)
    texture_x = source_center + cross*source_radius/source_norm
    texture_y = source_y - cross*source_radius*source_slope/source_norm
    texture_x = np.clip(texture_x, 0, w-1).astype(np.float32)
    texture_y = np.clip(texture_y, 0, h-1).astype(np.float32)
    trunk = cv2.remap(original, texture_x, texture_y, cv2.INTER_CUBIC,
                      borderMode=cv2.BORDER_REFLECT_101).astype(np.float32)

    # Retain the photographed wrinkles while adapting cylindrical shading
    # to the new direction and the bright upper-right illumination.
    lighting = 0.70*normal_x-0.71*normal_y
    cylindrical = np.sqrt(np.maximum(0, 1-cross*cross))
    gain = 0.94 + 0.065*cylindrical + 0.075*lighting*cross
    trunk *= gain[..., None]
    trunk += rng.normal(0, 0.30, (h, w, 1)).astype(np.float32)

    # A restrained, textured terminal opening makes the curled end read as
    # the trunk tip rather than a cut-off tube.
    end = path[-1]
    direction = tangents[-1]
    side = normals[-1]
    tip_radius = 0.016*w
    opening_center = end + direction*(0.32*tip_radius)
    tx, ty = xx-opening_center[0], yy-opening_center[1]
    along = tx*direction[0]+ty*direction[1]
    across = tx*side[0]+ty*side[1]
    ellipse = (along/max(1, 0.27*tip_radius))**2 + (across/max(1, 0.53*tip_radius))**2
    opening = np.clip((1.20-ellipse)/0.35, 0, 1)
    opening *= (longitudinal > 0.955).astype(np.float32)
    interior = trunk*0.32 + np.array([10.0, 9.0, 7.0], np.float32)
    interior += rng.normal(0, 0.7, (h, w, 1)).astype(np.float32)
    trunk = trunk*(1-opening[..., None]*0.86) + interior*(opening[..., None]*0.86)

    edge = max(0.8, scale*0.0024)
    alpha = np.clip((radii-np.sqrt(nearest))/edge + 0.5, 0, 1)
    alpha = alpha*alpha*(3-2*alpha)
    # Blend the attachment into the original face, keeping its upper contour.
    root_blend = np.clip(longitudinal/0.075, 0, 1)
    alpha *= 0.35 + 0.65*root_blend
    result = base*(1-alpha[..., None]) + trunk*alpha[..., None]
    return Image.fromarray(np.clip(result, 0, 255).astype(np.uint8), 'RGB')
change the motorcycle into an ATV
magicbrush_train_274516_1 · replace / change · execution=passed
FAILinstr 4preserve 4quality 2
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The foreground motorcycle was changed into an ATV-like vehicle, while the surrounding street scene and background motorcycle are mostly preserved. However, the ATV is a flat, cartoonish overlay with poor perspective, lighting, and integration, making the edit visually unrealistic.

l1=0.0884 · gain=-0.0231 · mask_l1=0.0207 · preserve_l1=0.1102

reasoning / plan
{
 "visual_evidence": [
  "A large silver motorcycle occupies the lower-right foreground.",
  "Its rear wheel, long exhaust, tail, and frame are visible beneath the rider.",
  "The helmeted rider leans forward, with a bent leg and boot visible beside the motorcycle.",
  "Another motorcycle, a car, storefronts, and pedestrians appear in the background."
 ],
 "target_object": "The foreground motorcycle",
 "target_region": "The vehicle beneath the foreground rider, extending from the silver tail near the image center to the right edge",
 "editing_intent": "Replace the foreground motorcycle with a silver sport ATV, retaining the rider and the surrounding street scene.",
 "editing_plan": [
  "Mask the foreground motorcycle while protecting the rider.",
  "Remove exposed motorcycle components using inpainting and texture sampled from the road.",
  "Construct a perspective-matched ATV with four chunky tires, silver fenders, a saddle, a metal chassis, and an engine.",
  "Add tire tread, wheel hubs, panel reflections, surface texture, and a soft road shadow.",
  "Feather the rendered edges and restore the original rider over the ATV."
 ],
 "preservation_constraints": [
  "Keep the foreground rider, helmet, clothing, and pose.",
  "Keep the smaller background motorcycle and its rider.",
  "Keep the car, pedestrians, buildings, signs, and storefronts.",
  "Do not change the image dimensions or the overall lighting."
 ]
}
pixel code
def edit(image):
    import cv2
    import numpy as np
    from PIL import Image

    w, h = image.size
    scale = 2
    W, H = w * scale, h * scale
    original = np.asarray(image.convert('RGB')).copy()
    src = cv2.resize(original, (W, H), interpolation=cv2.INTER_CUBIC)
    rng = np.random.default_rng(43)

    def points(coords):
        return np.round(np.asarray(coords, dtype=np.float32) * [W, H]).astype(np.int32)

    def smooth(coords, rounds=2):
        p = np.asarray(coords, dtype=np.float32)
        for _ in range(rounds):
            q = np.roll(p, -1, axis=0)
            p = np.stack((0.75*p + 0.25*q, 0.25*p + 0.75*q), axis=1).reshape(-1, 2)
        return p

    def polygon_mask(coords, rounded=False):
        m = np.zeros((H, W), np.uint8)
        cv2.fillPoly(m, [points(smooth(coords) if rounded else coords)], 255, lineType=cv2.LINE_AA)
        return m

    # Preserve the visible rider, including the bent leg and boot.
    rider_outline = [(.618,.399),(.636,.344),(.669,.274),(.714,.207),
                     (.753,.150),(.771,.071),(.820,.016),(.912,.009),
                     (.977,.044),(1.0,.093),(1.0,.427),(.954,.431),
                     (.888,.377),(.827,.332),(.796,.333),(.786,.403),
                     (.806,.443),(.867,.473),(.904,.510),(.926,.548),
                     (.904,.582),(.862,.615),(.833,.651),(.811,.680),
                     (.772,.704),(.779,.737),(.808,.773),(.765,.807),
                     (.718,.790),(.682,.767),(.653,.735),(.653,.704),
                     (.673,.664),(.689,.625),(.705,.590),(.672,.564),
                     (.635,.523),(.611,.479),(.609,.435)]
    rider = polygon_mask(rider_outline)
    rider = cv2.GaussianBlur(rider, (0, 0), 0.45*scale).astype(np.float32)/255.0

    old_vehicle = polygon_mask([(.281,.400),(.373,.400),(.537,.420),
                               (.589,.459),(.709,.456),(.804,.421),
                               (.895,.422),(1.0,.452),(1.0,.906),
                               (.703,.909),(.590,.940),(.451,.947),
                               (.365,.898),(.323,.808),(.318,.725),
                               (.275,.666),(.277,.599),(.319,.554),
                               (.302,.495)])
    removal = (old_vehicle.astype(np.float32)*(1.0-rider)).astype(np.uint8)
    removal = cv2.dilate(removal, np.ones((3*scale,3*scale), np.uint8))
    removal = (removal.astype(np.float32)*(1.0-rider)).astype(np.uint8)
    filled = cv2.inpaint(src, removal, max(3, int(.015*W)), cv2.INPAINT_TELEA)

    # Rebuild exposed asphalt from clean road pixels rather than a smooth fill.
    road_patch = src[int(.700*H):int(.947*H), int(.026*W):int(.264*W)]
    ph, pw = road_patch.shape[:2]
    road = cv2.copyMakeBorder(road_patch, 0, H+ph, 0, W+pw, cv2.BORDER_REFLECT_101)
    road = road[ph//3:ph//3+H, pw//4:pw//4+W].astype(np.float32)
    road = cv2.GaussianBlur(road, (0,0), 0.42*scale)
    road += rng.normal(0, 0.85, (H,W,1)).astype(np.float32)
    yy = np.arange(H, dtype=np.float32)[:,None]/H
    lower_weight = np.clip((yy-.59)/.12, 0, 1)
    clean_rows = src[:,int(.035*W):int(.24*W)].mean(axis=1).astype(np.float32)
    clean_rows = cv2.GaussianBlur(clean_rows[:,None,:], (1,0), 0, sigmaY=10*scale)[:,0,:]
    road_mean = road.mean(axis=1)
    road += (clean_rows-road_mean)[:,None,:]*0.55
    ra = cv2.GaussianBlur(removal.astype(np.float32)/255.0,(0,0),.7*scale)
    ra *= lower_weight
    canvas = filled.astype(np.float32)*(1-ra[:,:,None]) + road*ra[:,:,None]

    Y, X = np.mgrid[0:H,0:W].astype(np.float32)
    X /= W
    Y /= H
    fine = rng.normal(0,1,(H,W)).astype(np.float32)
    coarse = cv2.resize(rng.normal(0,1,(max(2,H//25),max(2,W//25))).astype(np.float32),
                        (W,H), interpolation=cv2.INTER_CUBIC)

    def put(color, mask, opacity=1.0, feather=.45):
        nonlocal canvas
        a = mask.astype(np.float32)/255.0
        if feather > 0:
            a = cv2.GaussianBlur(a,(0,0),feather*scale)
        a = np.clip(a*opacity,0,1)[:,:,None]
        c = np.asarray(color,dtype=np.float32)
        canvas = canvas*(1-a)+c*a

    def material(mask, base, light=20, noise=1.2, shiny=False):
        loc = np.where(mask>32)
        if len(loc[0]) == 0:
            return
        y0,y1 = loc[0].min()/H, loc[0].max()/H
        x0,x1 = loc[1].min()/W, loc[1].max()/W
        v = np.clip((Y-y0)/max(.001,y1-y0),0,1)
        u = np.clip((X-x0)/max(.001,x1-x0),0,1)
        shade = light*(.70-1.30*v-.22*u)
        shade += 2.0*coarse + noise*fine
        if shiny:
            shade += light*.58*np.exp(-((v-.22)/.085)**2)
            shade -= light*.25*np.exp(-((v-.67)/.12)**2)
        c = np.asarray(base,dtype=np.float32)[None,None,:]+shade[:,:,None]
        put(np.clip(c,0,255),mask)

    def poly(coords, base, light=20, rounded=True, shiny=False):
        m = polygon_mask(coords,rounded)
        material(m,base,light,1.3,shiny)
        return m

    def ellipse(cx,cy,rx,ry,base,light=12):
        m = np.zeros((H,W),np.uint8)
        cv2.ellipse(m,(int(cx*W),int(cy*H)),(max(1,int(rx*W)),max(1,int(ry*H))),
                    0,0,360,255,-1,cv2.LINE_AA)
        material(m,base,light)
        return m

    def line(coords,color,width,opacity=1.0):
        m = np.zeros((H,W),np.uint8)
        cv2.polylines(m,[points(coords)],False,255,max(1,int(width*W)),cv2.LINE_AA)
        for px,py in points([coords[0],coords[-1]]):
            cv2.circle(m,(int(px),int(py)),max(1,int(width*W/2)),255,-1,cv2.LINE_AA)
        put(color,m,opacity,.32)

    def tube(coords,width=.015):
        line(coords,(23,28,28),width+.006)
        line(coords,(96,105,105),width)
        line([(x-.001,y-.002) for x,y in coords],(189,194,191),width*.32)
        line([(x+.001,y+.002) for x,y in coords],(48,54,54),width*.20)

    # Broad, low-contrast cast shadow on the road.
    shadow = np.exp(-(((X-.696)/.351)**2 + ((Y-.924)/.047)**2)*1.9)
    shadow += .52*np.exp(-(((X-.437)/.139)**2+((Y-.925)/.022)**2)*1.7)
    shadow += .65*np.exp(-(((X-.958)/.153)**2+((Y-.969)/.021)**2)*1.7)
    shadow = np.clip(shadow*.29,0,.37)*(1-rider)
    canvas *= (1-shadow[:,:,None])

    def wheel(cx,cy,rx,ry,depth,far=False):
        # Thick barrel of rubber, followed by the nearer sidewall and rim.
        farcx, farcy = cx+depth,cy-.016
        ellipse(farcx,farcy,rx,ry,(24,27,27),9)
        poly([(cx-rx,cy),(farcx-rx,farcy),(farcx-rx*.70,farcy-ry*.73),
              (farcx,farcy-ry),(farcx+rx*.72,farcy-ry*.72),
              (farcx+rx,farcy),(cx+rx,cy),(cx+rx*.72,cy+ry*.72),
              (cx,cy+ry),(cx-rx*.72,cy+ry*.72)],(25,28,28),9)
        outer = ellipse(cx,cy,rx,ry,(27,30,30),9)
        dx=(X-cx)/rx
        dy=(Y-cy)/ry
        rad=np.sqrt(dx*dx+dy*dy)
        rubber = 26+8*(-dy)-8*np.exp(-((rad-.75)/.15)**2)
        rubber += 4*np.exp(-((rad-.93)/.045)**2)+1.45*fine+1.4*coarse
        put(np.stack((rubber*.94,rubber,rubber*1.015),axis=2),outer)
        n=30 if not far else 23
        for k in range(n):
            ang=2*np.pi*k/n
            da=.046 if not far else .06
            for row in range(2):
                t=row*.58
                centerx=cx+depth*t
                centery=cy-.016*t
                r0=.88 if row==0 else .98
                r1=1.055 if row==0 else 1.07
                a=ang+row*.043
                p=[(centerx+rx*r0*np.cos(a-da),centery+ry*r0*np.sin(a-da)),
                   (centerx+rx*r1*np.cos(a-da),centery+ry*r1*np.sin(a-da)),
                   (centerx+rx*r1*np.cos(a+da),centery+ry*r1*np.sin(a+da)),
                   (centerx+rx*r0*np.cos(a+da),centery+ry*r0*np.sin(a+da))]
                brightness=31-7*np.sin(a)+rng.uniform(-3,3)
                poly(p,(brightness*.94,brightness,brightness),5,True)
        # Sidewall beads and shallow moulded radial details.
        for rr,col in [(.78,(39,42,41)),(.70,(17,20,20))]:
            m=np.zeros((H,W),np.uint8)
            cv2.ellipse(m,(int(cx*W),int(cy*H)),(int(rx*rr*W),int(ry*rr*H)),
                        0,0,360,255,max(1,int(.0022*W)),cv2.LINE_AA)
            put(col,m,.8)
        for k in range(22):
            a=k*2*np.pi/22
            line([(cx+rx*.74*np.cos(a),cy+ry*.74*np.sin(a)),
                  (cx+rx*.85*np.cos(a+.028),cy+ry*.85*np.sin(a+.028))],
                 (45,47,45),.0013,.45)
        hrx,hry=rx*.48,ry*.48
        ellipse(cx,cy,hrx,hry,(107,115,117),35)
        ellipse(cx,cy,hrx*.84,hry*.84,(26,31,32),9)
        for k in range(5):
            a=2*np.pi*k/5-.3
            p=[(cx+hrx*.19*np.cos(a-.35),cy+hry*.19*np.sin(a-.35)),
               (cx+hrx*.83*np.cos(a-.14),cy+hry*.83*np.sin(a-.14)),
               (cx+hrx*.83*np.cos(a+.14),cy+hry*.83*np.sin(a+.14)),
               (cx+hrx*.19*np.cos(a+.35),cy+hry*.19*np.sin(a+.35))]
            poly(p,(163,172,173),30,True,True)
        ellipse(cx,cy,hrx*.32,hry*.32,(113,121,121),25)
        ellipse(cx,cy,hrx*.12,hry*.12,(44,48,47),10)
        for k in range(4):
            a=k*np.pi/2+.4
            ellipse(cx+hrx*.23*np.cos(a),cy+hry*.23*np.sin(a),
                    rx*.027,ry*.027,(202,205,196),15)

    # Smaller opposite-side wheels establish the four-wheel layout.
    wheel(.565,.665,.075,.102,.021,True)
    wheel(.952,.680,.081,.107,.019,True)

    # Frame, axles, and dark underbody.
    poly([(.396,.592),(.560,.553),(.748,.571),(.914,.588),(1.02,.660),
          (1.03,.776),(.875,.822),(.659,.798),(.484,.739)],(28,34,34),13)
    tube([(.451,.746),(.606,.742),(.782,.769),(.968,.802)],.024)
    tube([(.466,.599),(.580,.674),(.725,.716),(.908,.744)],.017)
    tube([(.531,.573),(.620,.653),(.578,.746)],.013)
    tube([(.766,.579),(.829,.714),(.947,.784)],.013)
    tube([(.487,.678),(.674,.734),(.874,.741)],.011)

    # Engine and cooling fins, visible below the saddle.
    poly([(.620,.579),(.731,.579),(.790,.630),(.786,.709),
          (.730,.750),(.632,.722),(.600,.652)],(68,76,76),23,True,True)
    for i in range(7):
        y=.611+i*.010
        line([(.630,y),(.738,y+.012)],(32,38,38),.0042)
        line([(.630,y-.002),(.738,y+.010)],(143,150,144),.0020)
    ellipse(.718,.711,.048,.044,(132,139,135),28)
    ellipse(.718,.711,.034,.031,(83,92,89),19)
    for a in np.linspace(0,2*np.pi,6,endpoint=False):
        ellipse(.718+.037*np.cos(a),.711+.033*np.sin(a),.003,.003,(198,201,184),10)

    # Wide silver rear body, unlike the motorcycle's narrow tail.
    poly([(.293,.465),(.316,.421),(.421,.418),(.550,.438),
          (.643,.492),(.671,.561),(.596,.604),(.491,.570),
          (.375,.554),(.303,.536)],(165,177,181),38,True,True)
    poly([(.295,.496),(.405,.513),(.541,.552),(.591,.586),
          (.562,.636),(.468,.607),(.357,.608),(.317,.576)],(104,119,126),28,True,True)
    line([(.310,.470),(.418,.465),(.536,.489),(.604,.532)],(224,229,228),.004,.74)
    line([(.316,.535),(.421,.550),(.529,.583)],(48,62,66),.005,.72)
    # Small rear lamp and grab rail.
    poly([(.294,.480),(.337,.486),(.340,.512),(.298,.504)],(125,24,23),18,True,True)
    line([(.300,.489),(.331,.493)],(232,75,57),.003,.68)
    tube([(.316,.433),(.376,.406),(.506,.426),(.557,.451)],.008)

    # Saddle, front bodywork, and the broad front mudguard.
    poly([(.530,.446),(.645,.445),(.749,.468),(.813,.508),
          (.786,.544),(.662,.514),(.547,.488)],(24,31,35),15,True)
    line([(.549,.458),(.659,.470),(.767,.502)],(72,81,85),.003,.6)
    poly([(.809,.438),(.875,.424),(.951,.447),(1.034,.481),
          (1.039,.583),(.954,.620),(.864,.582),(.809,.530)],
         (160,177,185),37,True,True)
    poly([(.844,.541),(.932,.520),(1.042,.559),(1.074,.626),
          (.994,.658),(.907,.630),(.839,.610)],(105,123,130),30,True,True)
    line([(.848,.468),(.917,.465),(.989,.496)],(230,234,229),.004,.72)
    line([(.864,.577),(.933,.587),(1.025,.613)],(43,60,66),.006,.72)
    poly([(.820,.549),(.856,.559),(.881,.598),(.848,.644),
          (.811,.641),(.779,.597)],(46,62,68),18,True,True)
    for i in range(3):
        line([(.827+i*.013,.581),(.839+i*.013,.615)],(19,30,33),.005)
    tube([(.903,.463),(.944,.430),(1.013,.455)],.009)

    # Full-size near-side tires with deep tread and metallic hubs.
    wheel(.432,.793,.119,.146,.041)
    wheel(.950,.816,.124,.154,.042)

    # Raised fender lips overlap the tires and give the ATV a wide stance.
    poly([(.303,.616),(.329,.566),(.412,.547),(.511,.575),
          (.574,.615),(.573,.652),(.529,.643),(.482,.610),
          (.395,.595),(.343,.622)],(143,161,169),36,True,True)
    line([(.322,.604),(.378,.575),(.451,.583),(.527,.618)],(217,226,226),.004,.68)
    poly([(.833,.646),(.852,.599),(.929,.577),(1.012,.604),
          (1.068,.650),(1.056,.692),(1.003,.678),(.951,.643),
          (.888,.632),(.860,.666)],(139,158,168),35,True,True)
    line([(.852,.635),(.899,.607),(.961,.618),(1.014,.649)],(222,229,227),.004,.7)

    # Foot platform under the preserved boot; no long motorcycle exhaust.
    poly([(.580,.752),(.691,.751),(.824,.780),(.839,.803),
          (.767,.832),(.646,.805),(.579,.785)],(34,42,44),14,True)
    tube([(.578,.775),(.671,.805),(.766,.824),(.837,.794)],.012)
    for i in range(6):
        x=.615+i*.029
        line([(x,.770+(x-.615)*.16),(x+.018,.795+(x-.615)*.16)],
             (101,110,108),.0038)
    tube([(.527,.696),(.565,.738),(.602,.759)],.010)
    # Small exposed suspension springs and links.
    for x,y in [(.570,.660),(.852,.700)]:
        tube([(x-.015,y-.032),(x+.020,y+.044)],.009)
        for i in range(7):
            t=i/6
            line([(x-.018+.030*t,y-.022+.060*t),
                  (x+.006+.030*t,y-.030+.060*t)],(166,169,146),.0032)

    # Restore the untouched person, with only a subpixel transition at the outline.
    canvas = canvas*(1-rider[:,:,None])+src.astype(np.float32)*rider[:,:,None]
    result = cv2.resize(np.clip(canvas,0,255).astype(np.uint8),(w,h),interpolation=cv2.INTER_AREA)
    # Keep distant scenery pixel-exact outside the foreground edit.
    protected = np.zeros((h,w),np.uint8)
    protected[:int(.394*h),:] = 255
    protected[:, :int(.266*w)] = 255
    result[protected>0] = original[protected>0]
    return Image.fromarray(result, 'RGB')
let the zebra have its legs up in the air
magicbrush_train_17324_1 · replace / change · execution=passed
PASSinstr 4preserve 4quality 3
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The zebra has been repositioned so its legs are up in the air, satisfying the main request. The background and unrelated animals are mostly preserved, though the edited zebra looks somewhat unnatural with visible compositing/pose artifacts and an awkward head/body alignment.

l1=0.0849 · gain=-0.0452 · mask_l1=0.0386 · preserve_l1=0.1558

reasoning / plan
{
 "visual_evidence": [
  "A large black-and-white zebra faces left in the foreground.",
  "The zebra's legs extend downward into dry, golden grass.",
  "The background contains a pale sky, distant hills, and small animals on the right."
 ],
 "target_object": "The foreground zebra",
 "target_region": "The zebra's body, head, and legs in the left and central foreground",
 "editing_intent": "Reposition the zebra onto its back in the grass, with its legs pointing upward into the air.",
 "editing_plan": [
  "Segment the zebra, including its legs, mane, and visible tail.",
  "Remove its original silhouette by synthesizing grass from clean, nearby portions of the same image.",
  "Rotate and reposition the extracted zebra so its back rests near the ground and its legs extend upward.",
  "Add subtle ground-contact shadows, feather the silhouette, and restore a few foreground grass strands along its lower edge."
 ],
 "preservation_constraints": [
  "Keep the image dimensions unchanged.",
  "Preserve the sky, distant hills, and background animals.",
  "Retain the zebra's original striped texture and recognizable anatomy.",
  "Preserve the field's photographic texture and warm coloring outside the affected area."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    image = image.convert('RGB')
    w, h = image.size
    src = np.asarray(image).copy()
    rng = np.random.default_rng(27)
    scale = min(w, h)

    def polygon(points):
        return np.array([[round(x*w), round(y*h)] for x, y in points], np.int32)

    body_points = [
        (0.000,0.492),(0.020,0.460),(0.037,0.414),(0.059,0.374),
        (0.073,0.334),(0.079,0.300),(0.091,0.285),(0.112,0.290),
        (0.121,0.308),(0.152,0.302),(0.192,0.310),(0.244,0.331),
        (0.283,0.350),(0.305,0.379),(0.358,0.374),(0.420,0.356),
        (0.480,0.347),(0.542,0.339),(0.586,0.343),(0.623,0.358),
        (0.659,0.391),(0.680,0.428),(0.687,0.472),(0.675,0.521),
        (0.653,0.555),(0.648,0.584),(0.628,0.607),(0.604,0.606),
        (0.580,0.582),(0.548,0.601),(0.495,0.609),(0.434,0.610),
        (0.405,0.605),(0.397,0.627),(0.370,0.626),(0.351,0.627),
        (0.324,0.606),(0.287,0.584),(0.258,0.556),(0.232,0.547),
        (0.207,0.529),(0.174,0.513),(0.144,0.488),(0.118,0.469),
        (0.095,0.492),(0.074,0.522),(0.041,0.553),(0.024,0.562),
        (0.000,0.545)
    ]
    leg_points = [
        [(0.340,0.543),(0.381,0.569),(0.398,0.625),(0.410,0.672),
         (0.436,0.748),(0.444,0.771),(0.419,0.779),(0.398,0.737),
         (0.375,0.690),(0.357,0.635),(0.341,0.606)],
        [(0.299,0.584),(0.341,0.605),(0.348,0.657),(0.354,0.699),
         (0.376,0.745),(0.381,0.767),(0.354,0.775),(0.332,0.742),
         (0.321,0.694),(0.313,0.654)],
        [(0.598,0.528),(0.649,0.518),(0.635,0.592),(0.618,0.650),
         (0.617,0.714),(0.629,0.756),(0.606,0.768),(0.592,0.728),
         (0.590,0.676),(0.589,0.615),(0.582,0.586)],
        [(0.526,0.577),(0.558,0.589),(0.572,0.637),(0.549,0.683),
         (0.527,0.740),(0.519,0.764),(0.496,0.761),(0.505,0.725),
         (0.529,0.672),(0.531,0.641),(0.512,0.610)]
    ]
    rough = np.zeros((h,w), np.uint8)
    body = np.zeros_like(rough)
    cv2.fillPoly(body, [polygon(body_points)], 255)
    rough[:] = body
    for points in leg_points:
        cv2.fillPoly(rough, [polygon(points)], 255)
    tail = polygon([(0.670,0.487),(0.664,0.557),(0.652,0.609),
                    (0.645,0.658),(0.636,0.683)])
    cv2.polylines(rough, [tail], False, 255, max(2,round(0.008*w)))

    rad = max(1, round(scale*0.006))
    kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2*rad+1,2*rad+1))
    expanded = cv2.dilate(rough, kernel)
    core = cv2.erode(rough, kernel)
    labels = np.full((h,w), cv2.GC_BGD, np.uint8)
    labels[expanded > 0] = cv2.GC_PR_BGD
    labels[rough > 0] = cv2.GC_PR_FGD
    labels[core > 0] = cv2.GC_FGD
    bg_model = np.zeros((1,65), np.float64)
    fg_model = np.zeros((1,65), np.float64)
    cv2.setRNGSeed(27)
    try:
        cv2.grabCut(src, labels, None, bg_model, fg_model, 4, cv2.GC_INIT_WITH_MASK)
        animal = np.where((labels == cv2.GC_FGD) | (labels == cv2.GC_PR_FGD),255,0).astype(np.uint8)
        animal[expanded == 0] = 0
    except cv2.error:
        animal = rough.copy()
    if np.count_nonzero(animal) < 0.045*w*h:
        animal = rough.copy()

    # Remove only the old zebra silhouette, using real field patches.
    remove_rad = max(2,round(scale*0.009))
    remove_kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,
                                             (2*remove_rad+1,2*remove_rad+1))
    removal = cv2.dilate(animal, remove_kernel)
    yy, xx = np.where(removal > 0)
    x0, x1 = int(xx.min()), int(xx.max())+1
    y0, y1 = int(yy.min()), int(yy.max())+1
    pw = max(12,round(w*0.100))
    ph = max(12,round(h*0.096))
    sx_step = max(1,round(pw*0.74))
    sy_step = max(1,round(ph*0.74))
    accum = np.zeros((h,w,3),np.float32)
    weights = np.zeros((h,w),np.float32)
    feather_x = max(2,round(pw*0.25))
    feather_y = max(2,round(ph*0.25))
    wx = np.ones(pw,np.float32)
    wy = np.ones(ph,np.float32)
    wx[:feather_x] = np.linspace(0.03,1,feather_x)
    wx[-feather_x:] = np.linspace(1,0.03,feather_x)
    wy[:feather_y] = np.linspace(0.03,1,feather_y)
    wy[-feather_y:] = np.linspace(1,0.03,feather_y)
    patch_weight = wy[:,None]*wx[None,:]

    for oy in range(y0-ph,y1+ph,sy_step):
        for ox in range(x0-pw,x1+pw,sx_step):
            donor_y = int(np.clip(oy+rng.integers(-max(1,round(.018*h)),
                                                   max(2,round(.018*h))+1),
                                  round(.275*h),h-ph))
            donor_left = round(.715*w)
            donor_right = round((.84 if donor_y < .407*h else .995)*w)-pw
            donor_right = max(donor_left, min(w-pw, donor_right))
            donor_left = min(donor_left, donor_right)
            donor_x = int(rng.integers(donor_left,donor_right+1))
            patch = src[donor_y:donor_y+ph,donor_x:donor_x+pw].astype(np.float32)
            if rng.random() < .5:
                patch = patch[:,::-1].copy()
            xa, xb = max(0,ox), min(w,ox+pw)
            ya, yb = max(0,oy), min(h,oy+ph)
            if xa >= xb or ya >= yb:
                continue
            px0, py0 = xa-ox, ya-oy
            piece = patch[py0:py0+yb-ya,px0:px0+xb-xa]
            blend_weight = patch_weight[py0:py0+yb-ya,px0:px0+xb-xa]
            accum[ya:yb,xa:xb] += piece*blend_weight[:,:,None]
            weights[ya:yb,xa:xb] += blend_weight

    field = accum/np.maximum(weights[:,:,None],1e-6)
    field[weights == 0] = src[weights == 0]
    field += rng.normal(0,.45,(h,w,1)).astype(np.float32)
    fill_alpha = cv2.GaussianBlur(removal.astype(np.float32)/255,
                                 (0,0),max(.6,scale*.0022))
    background = src.astype(np.float32)*(1-fill_alpha[:,:,None]) + field*fill_alpha[:,:,None]
    background = np.clip(background,0,255)

    # Invert the actual animal, placing its back in the grass and its legs above it.
    matte = cv2.GaussianBlur(animal.astype(np.float32)/255,
                            (0,0),max(.45,scale*.0012))
    transform = np.array([[-1,0,.820*w],[0,-1,1.155*h]],np.float32)
    moved_alpha = cv2.warpAffine(matte,transform,(w,h),flags=cv2.INTER_LINEAR,
                                 borderMode=cv2.BORDER_CONSTANT,borderValue=0)
    premult = src.astype(np.float32)*matte[:,:,None]
    moved_premult = cv2.warpAffine(premult,transform,(w,h),flags=cv2.INTER_LINEAR,
                                   borderMode=cv2.BORDER_CONSTANT,borderValue=0)
    moved_rgb = moved_premult/np.maximum(moved_alpha[:,:,None],1e-5)
    vertical = np.clip((np.arange(h,dtype=np.float32)/h-.375)/.50,0,1)
    relight = 1.045-.075*vertical
    moved_rgb = np.clip(moved_rgb*relight[:,None,None],0,255)

    # Soft contact shadows retain the underlying grass texture.
    shadow = np.zeros((h,w),np.uint8)
    cv2.ellipse(shadow,(round(.357*w),round(.823*h)),
                (max(1,round(.252*w)),max(1,round(.013*h))),0,0,360,255,-1)
    cv2.ellipse(shadow,(round(.687*w),round(.855*h)),
                (max(1,round(.093*w)),max(1,round(.011*h))),0,0,360,180,-1)
    soft_shadow = cv2.GaussianBlur(shadow.astype(np.float32)/255,
                                   (0,0),max(1,scale*.010))
    background *= (1-.19*soft_shadow[:,:,None])
    result = background*(1-moved_alpha[:,:,None]) + moved_rgb*moved_alpha[:,:,None]

    # Restore a few authentic foreground grass strands at ground-contact edges.
    gray = cv2.cvtColor(src,cv2.COLOR_RGB2GRAY).astype(np.float32)
    local = cv2.GaussianBlur(gray,(0,0),max(.8,scale*.0025))
    detail = np.abs(gray-local)
    grass_strength = np.clip((detail-5)/15,0,1)
    occlusion = np.zeros((h,w),np.float32)
    band_height = max(3,round(.018*h))
    for x in range(w):
        occupied = np.flatnonzero(moved_alpha[:,x] > .35)
        if len(occupied) == 0:
            continue
        bottom = int(occupied[-1])
        if bottom < .795*h:
            continue
        top = max(round(.795*h),bottom-band_height)
        rows = np.arange(top,bottom+1)
        ramp = (rows-top+1)/max(1,bottom-top+1)
        occlusion[rows,x] = grass_strength[rows,x]*ramp*.70
    occlusion *= moved_alpha
    result = result*(1-occlusion[:,:,None]) + background*occlusion[:,:,None]
    return Image.fromarray(np.clip(result,0,255).astype(np.uint8),'RGB')
Place a vase of flowers on the table in the kitchen.
magicbrush_train_563771_1 · other · execution=passed
PASSinstr 5preserve 5quality 4
source
GPT-6.1-Sol output
MagicBrush target (reference only)

A vase with flowers was added on the kitchen table/cart as requested. The rest of the scene is essentially unchanged. The added object is reasonably placed, though it looks slightly artificial and not perfectly integrated with the lighting and perspective.

l1=0.0089 · gain=-0.0015 · mask_l1=0.0045 · preserve_l1=0.0122

reasoning / plan
{
 "visual_evidence": [
  "A metal kitchen table with a reflective top stands near the center of the image.",
  "There is open space on the right half of its tabletop.",
  "Daylight enters from the window on the left.",
  "The table's lower shelves and legs are visible."
 ],
 "target_object": "A new vase containing flowers",
 "target_region": "The right half of the central metal kitchen tabletop",
 "editing_intent": "Add a small, shaded ceramic vase with a natural-looking bouquet, resting on the tabletop with a soft contact shadow.",
 "editing_plan": [
  "Locate the tabletop using image-relative coordinates.",
  "Synthesize a soft shadow that follows the tabletop perspective.",
  "Draw slender stems, shaded leaves, and overlapping cream and muted pink flower petals.",
  "Construct a rounded ceramic vase with directional shading, a highlighted rim, and surface texture.",
  "Antialias and blend the added pixels while preserving the original image outside the addition."
 ],
 "preservation_constraints": [
  "Keep the kitchen layout, cabinets, window, pendant light, and appliances unchanged.",
  "Preserve the metal table's structure, shelves, and existing contents.",
  "Do not alter the foreground, television, doorway, or surrounding walls outside the added object's footprint.",
  "Keep the vase's base on the tabletop and match the left-side daylight."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image, ImageDraw

    original = image.convert('RGB')
    w, h = image.size
    scale = 3
    W, H = w * scale, h * scale
    rng = np.random.default_rng(31)
    premul = np.zeros((H, W, 3), dtype=np.float32)
    coverage = np.zeros((H, W), dtype=np.float32)

    def paint(x0, y0, mask, color):
        hh, ww = mask.shape
        if hh == 0 or ww == 0:
            return
        a = np.clip(mask, 0, 1).astype(np.float32)
        c = np.asarray(color, dtype=np.float32)
        region = premul[y0:y0 + hh, x0:x0 + ww]
        region[:] = region * (1 - a[..., None]) + c * a[..., None]
        old = coverage[y0:y0 + hh, x0:x0 + ww]
        old[:] = a + old * (1 - a)

    def oval(cx, cy, rx, ry, angle, color, opacity=1.0, kind='petal'):
        cx, cy, rx, ry = cx * W, cy * H, rx * W, ry * H
        ca, sa = np.cos(angle), np.sin(angle)
        bx = abs(rx * ca) + abs(ry * sa) + 3
        by = abs(rx * sa) + abs(ry * ca) + 3
        x0, x1 = max(0, int(cx - bx)), min(W, int(cx + bx) + 1)
        y0, y1 = max(0, int(cy - by)), min(H, int(cy + by) + 1)
        yy, xx = np.mgrid[y0:y1, x0:x1].astype(np.float32)
        dx, dy = xx - cx, yy - cy
        u = (dx * ca + dy * sa) / max(rx, 0.1)
        v = (-dx * sa + dy * ca) / max(ry, 0.1)
        q = u * u + v * v
        mask = np.clip((1 - np.sqrt(q)) * min(rx, ry) + 0.5, 0, 1) * opacity
        dome = np.sqrt(np.clip(1 - q, 0, 1))
        light = 0.78 + 0.22 * dome - 0.055 * u - 0.075 * v
        if kind == 'petal':
            light += 0.055 * np.exp(-((v + 0.12) / 0.17) ** 2)
            light -= 0.035 * np.exp(-((v - 0.20) / 0.11) ** 2)
            light += 0.018 * np.sin(u * 17 + v * 5)
        elif kind == 'leaf':
            light += 0.10 * np.exp(-(v / 0.09) ** 2)
            light += 0.027 * np.sin(19 * u + 8 * np.abs(v))
        noise = rng.normal(0, 0.7, q.shape)
        rgb = np.asarray(color)[None, None, :] * light[..., None] + noise[..., None]
        paint(x0, y0, mask, np.clip(rgb, 0, 255))

    def shadow(cx, cy, rx, ry, opacity):
        x0, x1 = max(0, int((cx - 3 * rx) * W)), min(W, int((cx + 3 * rx) * W) + 1)
        y0, y1 = max(0, int((cy - 3 * ry) * H)), min(H, int((cy + 3 * ry) * H) + 1)
        yy, xx = np.mgrid[y0:y1, x0:x1].astype(np.float32)
        dx = (xx / W - cx) / rx
        dy = (yy / H - cy) / ry
        mask = opacity * np.exp(-0.5 * (dx * dx + dy * dy))
        mask[mask < 0.001] = 0
        paint(x0, y0, mask, (58, 55, 46))

    def stroke(points, width, color, opacity=1):
        pts = [(float(x * W), float(y * H)) for x, y in points]
        pad = max(3, int(width * W) + 2)
        x0 = max(0, int(min(p[0] for p in pts)) - pad)
        y0 = max(0, int(min(p[1] for p in pts)) - pad)
        x1 = min(W, int(max(p[0] for p in pts)) + pad + 1)
        y1 = min(H, int(max(p[1] for p in pts)) + pad + 1)
        m = Image.new('L', (x1 - x0, y1 - y0), 0)
        d = ImageDraw.Draw(m)
        d.line([(p[0] - x0, p[1] - y0) for p in pts], fill=255,
               width=max(1, int(round(width * W))), joint='curve')
        mask = np.asarray(m, dtype=np.float32) / 255 * opacity
        paint(x0, y0, mask, color)

    def curved_stem(start, control, end, width, color):
        t = np.linspace(0, 1, 35)
        pts = []
        for z in t:
            x = (1-z)**2 * start[0] + 2*(1-z)*z*control[0] + z*z*end[0]
            y = (1-z)**2 * start[1] + 2*(1-z)*z*control[1] + z*z*end[1]
            pts.append((x, y))
        stroke(pts, width, color)

    # Soft daylight shadow on the metal top, directed slightly to the right.
    shadow(0.634, 0.492, 0.020, 0.0038, 0.16)
    shadow(0.614, 0.4868, 0.0135, 0.0023, 0.30)

    flowers = [
        (0.589, 0.348, 0.0115, (222, 178, 170), 0.5),
        (0.622, 0.332, 0.0105, (237, 226, 203), 1.2),
        (0.642, 0.355, 0.0112, (204, 139, 139), 0.1),
        (0.571, 0.378, 0.0110, (240, 228, 207), 1.0),
        (0.607, 0.372, 0.0120, (232, 199, 183), 0.7),
        (0.658, 0.386, 0.0105, (237, 224, 203), 1.6),
        (0.628, 0.395, 0.0100, (210, 153, 153), 0.4)
    ]
    for i, (fx, fy, radius, color, phase) in enumerate(flowers):
        curved_stem((0.613 + (i % 3 - 1) * 0.002, 0.418),
                    ((fx + 0.613) / 2 + 0.003, 0.389), (fx, fy),
                    0.0015, (76 + i * 2, 91 + i, 57))
        curved_stem((0.613, 0.417), ((fx + 0.613) / 2 + 0.002, 0.389),
                    (fx, fy), 0.00055, (126, 138, 85))

    leaves = [
        (0.587, 0.390, 0.012, 0.0038, -2.55),
        (0.579, 0.360, 0.011, 0.0032, -2.15),
        (0.600, 0.400, 0.013, 0.0040, -2.70),
        (0.638, 0.407, 0.012, 0.0035, -0.40),
        (0.649, 0.369, 0.011, 0.0034, -0.70),
        (0.628, 0.361, 0.010, 0.0030, -0.85),
        (0.612, 0.348, 0.009, 0.0028, -1.95),
        (0.652, 0.398, 0.011, 0.0032, 0.05)
    ]
    for i, leaf in enumerate(leaves):
        oval(*leaf, (87 + i % 3 * 7, 111 + i % 2 * 9, 66), kind='leaf')

    # Small, irregular flowers: overlapping shaded petals, then textured centers.
    for i, (fx, fy, radius, color, phase) in enumerate(flowers):
        n = 7 if i % 2 else 8
        for k in range(n):
            theta = phase + 2 * np.pi * k / n + rng.uniform(-0.12, 0.12)
            reach = radius * rng.uniform(0.43, 0.56)
            px = fx + reach * np.cos(theta)
            py = fy + reach * np.sin(theta) * 0.84
            petal_color = np.asarray(color) + rng.uniform(-7, 7, 3)
            oval(px, py, radius * rng.uniform(0.48, 0.59),
                 radius * rng.uniform(0.25, 0.34), theta,
                 np.clip(petal_color, 0, 255))
        for k in range(5):
            theta = phase + k * 2 * np.pi / 5 + 0.30
            oval(fx + radius * 0.23 * np.cos(theta),
                 fy + radius * 0.20 * np.sin(theta),
                 radius * 0.35, radius * 0.21, theta,
                 np.clip(np.asarray(color) + 7, 0, 255))
        oval(fx, fy + radius * 0.04, radius * 0.25,
             radius * 0.20, 0, (159, 125, 61), kind='center')
        for k in range(11):
            theta = rng.uniform(0, 2*np.pi)
            rr = radius * rng.uniform(0.02, 0.20)
            oval(fx + np.cos(theta) * rr, fy + np.sin(theta) * rr * 0.8,
                 0.00065, 0.00055, theta, (213, 183, 95), kind='center')

    # Rounded ivory ceramic vase, with a narrow mouth and fuller body.
    cx, top, bottom = 0.613, 0.407, 0.486
    x0, x1 = int((cx - 0.029) * W), int((cx + 0.029) * W) + 1
    y0, y1 = int((top - 0.003) * H), int((bottom + 0.003) * H) + 1
    x0, y0, x1, y1 = max(0, x0), max(0, y0), min(W, x1), min(H, y1)
    yy, xx = np.mgrid[y0:y1, x0:x1].astype(np.float32)
    xn, yn = xx / W, yy / H
    t = (yn - top) / (bottom - top)
    knots = np.array([0, 0.16, 0.37, 0.59, 0.83, 1.0])
    radii = np.array([0.010, 0.0105, 0.022, 0.0255, 0.0235, 0.0185])
    tc = np.clip(t, 0, 1)
    idx = np.clip(np.searchsorted(knots, tc, side='right') - 1, 0, len(knots)-2)
    u = (tc - knots[idx]) / (knots[idx+1] - knots[idx])
    ease = (1 - np.cos(np.pi * u)) / 2
    radius = radii[idx] * (1-ease) + radii[idx+1] * ease
    centerline = cx + 0.0006 * np.sin(tc * np.pi)
    dx = xn - centerline
    sides = np.clip((radius - np.abs(dx)) * W + 0.5, 0, 1)
    upper = np.clip((yn - top) * H + 0.5, 0, 1)
    lower_edge = bottom - 0.003 * (1 - np.sqrt(np.clip(1 - (dx/0.020)**2, 0, 1)))
    lower = np.clip((lower_edge - yn) * H + 0.5, 0, 1)
    mask = sides * upper * lower
    transverse = dx / np.maximum(radius, 1e-6)
    curve = np.sqrt(np.clip(1 - transverse**2, 0, 1))
    lighting = 0.70 + 0.25 * curve - 0.065 * transverse
    lighting -= 0.040 * tc
    highlight = np.exp(-((transverse + 0.43) / 0.19)**2) * 13
    low_noise = rng.normal(0, 1, (max(3, (y1-y0)//12), max(3, (x1-x0)//12))).astype(np.float32)
    low_noise = cv2.resize(low_noise, (x1-x0, y1-y0), interpolation=cv2.INTER_CUBIC)
    grain = rng.normal(0, 0.65, t.shape) + low_noise * 0.8
    ceramic = np.array([219, 222, 210], dtype=np.float32)
    rgb = ceramic[None, None, :] * lighting[..., None]
    rgb += highlight[..., None] + grain[..., None]
    rgb[..., 2] += 2 * (1 - curve)
    paint(x0, y0, mask, np.clip(rgb, 0, 255))

    # Mouth: a thin lit lip around the darker interior.
    oval(cx, top + 0.0006, 0.0105, 0.0024, 0, (213, 216, 202), kind='rim')
    oval(cx, top + 0.0004, 0.0081, 0.00135, 0, (76, 88, 66), kind='rim')
    stroke([(cx - 0.0085, top + 0.0012), (cx, top + 0.0020),
            (cx + 0.0085, top + 0.0012)], 0.0008, (226, 229, 215))
    for xshift in (-0.003, 0.001, 0.004):
        stroke([(cx + xshift, top - 0.003), (cx + xshift * 0.7, top + 0.0008)],
               0.0009, (90, 104, 65))

    # Downsample only the synthesized layer; original pixels remain untouched elsewhere.
    alpha = cv2.resize(coverage, (w, h), interpolation=cv2.INTER_AREA)
    foreground = cv2.resize(premul, (w, h), interpolation=cv2.INTER_AREA)
    sigma = max(0.12, w * 0.00045)
    alpha = cv2.GaussianBlur(alpha, (0, 0), sigma)
    foreground = cv2.GaussianBlur(foreground, (0, 0), sigma)
    base = np.asarray(original, dtype=np.float32)
    final = base * (1 - alpha[..., None]) + foreground
    noise = rng.normal(0, 0.65, (h, w, 1)).astype(np.float32)
    final += noise * alpha[..., None]
    final[alpha < 0.0001] = base[alpha < 0.0001]
    return Image.fromarray(np.clip(np.rint(final), 0, 255).astype(np.uint8), 'RGB')
Add a second player
magicbrush_train_130579_1 · add / insert · execution=passed
PASSinstr 5preserve 4quality 4
source
GPT-6.1-Sol output
MagicBrush target (reference only)

A second baseball player has been added to the scene, positioned to the left of the original. The original player and background are largely preserved, with only local changes around the added player. The added player looks visually consistent, though it is an obvious duplicate of the original and slightly awkwardly cropped at the bottom.

l1=0.0827 · gain=-0.0211 · mask_l1=0.0003 · preserve_l1=0.0993

reasoning / plan
{
 "visual_evidence": [
  "One baseball player wears a white uniform, dark cap, and black glove.",
  "The player stands on a field with green grass and a brown dirt area.",
  "There is open field space to the player's left.",
  "The player's lower legs continue beyond the bottom edge."
 ],
 "target_object": "A second baseball player",
 "target_region": "Open field on the left, with the added player's lower legs cropped by the bottom edge",
 "editing_intent": "Add a slightly smaller second player using the visible player's textured appearance, while retaining the original player.",
 "editing_plan": [
  "Outline the existing player's cap, body, glove, and trousers.",
  "Refine the outline with GrabCut, excluding any green grass between the legs.",
  "Extract and resize the player with premultiplied alpha to preserve clean edges.",
  "Place the second player in the open left side without overlapping the original.",
  "Add a faint ground shadow near the bottom edge and blend the copied player with feathered edges."
 ],
 "preservation_constraints": [
  "Keep the original player unchanged.",
  "Preserve the existing field outside the added player and its small shadow.",
  "Retain realistic fabric, skin, glove, and cap textures.",
  "Do not add unrelated equipment or change the framing."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    w, h = image.size
    source = np.asarray(image.convert('RGB')).copy()
    outline = [
        (.598,.108), (.626,.104), (.640,.079), (.662,.057),
        (.689,.052), (.730,.059), (.750,.077), (.763,.103),
        (.762,.136), (.752,.157), (.754,.187), (.739,.213),
        (.747,.232), (.786,.250), (.823,.279), (.847,.321),
        (.858,.361), (.854,.410), (.839,.452), (.828,.481),
        (.811,.504), (.793,.522), (.809,.537), (.807,.570),
        (.792,.591), (.804,.622), (.814,.670), (.812,.732),
        (.802,.805), (.808,.871), (.824,.955), (.832,1.0),
        (.541,1.0), (.542,.941), (.547,.870), (.546,.808),
        (.550,.739), (.561,.664), (.570,.611), (.573,.573),
        (.572,.543), (.579,.509), (.551,.513), (.516,.511),
        (.481,.498), (.460,.474), (.452,.442), (.455,.416),
        (.451,.390), (.458,.367), (.470,.349), (.488,.347),
        (.514,.362), (.542,.378), (.556,.391), (.562,.359),
        (.574,.316), (.591,.285), (.615,.263), (.649,.252),
        (.658,.238), (.637,.219), (.628,.196), (.622,.167),
        (.625,.141), (.644,.137), (.625,.128), (.599,.119)
    ]
    polygon = np.array([(round(x*(w-1)), round(y*(h-1))) for x,y in outline], dtype=np.int32)
    rough = np.zeros((h,w), np.uint8)
    cv2.fillPoly(rough, [polygon], 255)
    radius = max(2, round(min(w,h)*0.008))
    kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2*radius+1, 2*radius+1))
    outer = cv2.dilate(rough, kernel)
    inner = cv2.erode(rough, kernel)
    labels = np.full((h,w), cv2.GC_BGD, np.uint8)
    labels[outer > 0] = cv2.GC_PR_BGD
    labels[rough > 0] = cv2.GC_PR_FGD
    labels[inner > 0] = cv2.GC_FGD

    yy, xx = np.mgrid[0:h, 0:w]
    rgb = source.astype(np.float32)
    green = (rgb[:,:,1] > rgb[:,:,0]*1.13) & (rgb[:,:,1] > rgb[:,:,2]*1.13) & (rgb[:,:,1] > 45)
    lower_gap = green & (yy > .77*h) & (xx > .62*w) & (xx < .76*w)
    labels[lower_gap] = cv2.GC_BGD
    bg_model = np.zeros((1,65), np.float64)
    fg_model = np.zeros((1,65), np.float64)
    try:
        cv2.grabCut(source, labels, None, bg_model, fg_model, 6, cv2.GC_INIT_WITH_MASK)
        mask = np.where((labels == cv2.GC_FGD) | (labels == cv2.GC_PR_FGD), 255, 0).astype(np.uint8)
    except cv2.error:
        mask = rough.copy()
    mask[outer == 0] = 0
    mask[lower_gap] = 0

    count, components, stats, _ = cv2.connectedComponentsWithStats(mask, connectivity=8)
    if count > 1:
        biggest = 1 + int(np.argmax(stats[1:, cv2.CC_STAT_AREA]))
        mask = np.where(components == biggest, 255, 0).astype(np.uint8)
    if not np.any(mask):
        mask = rough.copy()
        mask[lower_gap] = 0

    alpha = cv2.GaussianBlur(mask.astype(np.float32)/255.0, (0,0), max(.45, min(w,h)*.0011))
    ys, xs = np.where(mask > 0)
    margin = max(2, round(min(w,h)*.004))
    x0 = max(0, int(xs.min())-margin)
    x1 = min(w, int(xs.max())+margin+1)
    y0 = max(0, int(ys.min())-margin)
    y1 = h
    cut_alpha = alpha[y0:y1, x0:x1]
    cut_rgb = source[y0:y1, x0:x1].astype(np.float32)
    new_h = max(1, round(.88*h))
    scale = new_h / float(y1-y0)
    new_w = max(1, round((x1-x0)*scale))
    left = round(.027*w)
    available = max(1, round(.433*w)-left)
    if new_w > available:
        scale *= available / float(new_w)
        new_w = available
        new_h = max(1, round((y1-y0)*scale))
    top = h-new_h
    premult = cut_rgb * cut_alpha[:,:,None]
    resized_alpha = cv2.resize(cut_alpha, (new_w,new_h), interpolation=cv2.INTER_AREA)
    resized_premult = cv2.resize(premult, (new_w,new_h), interpolation=cv2.INTER_AREA)
    resized_alpha = np.clip(resized_alpha, 0, 1)

    result = source.astype(np.float32)
    shadow_cx = left + .58*new_w
    shadow_cy = h + .016*h
    shadow = np.exp(-.5*((xx-shadow_cx)/max(1,.125*w))**2 - .5*((yy-shadow_cy)/max(1,.030*h))**2)
    shadow *= .10
    shadow[(yy < .70*h) | (xx >= .438*w)] = 0
    shadow *= (1.0-alpha)
    result *= (1.0-shadow[:,:,None])

    region = result[top:top+new_h, left:left+new_w]
    region[:] = resized_premult + region*(1.0-resized_alpha[:,:,None])
    # Guarantee that none of the original player's pixels are changed.
    original_player = alpha > .01
    result[original_player] = source[original_player]
    return Image.fromarray(np.clip(np.rint(result),0,255).astype(np.uint8), 'RGB')
Make the tree a palm tree.
magicbrush_train_247838_2 · replace / change · execution=passed
PASSinstr 4preserve 4quality 3
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The central tree has been changed into a palm tree, matching the requested edit. Most unrelated scene elements such as the snowy landscape, animals, water, and background remain intact, though some remnants/artifacts from the original tree and lighting remain near the base. The palm compositing is somewhat artificial and mismatched to the snowy scene, but it is recognizable and localized.

l1=0.0562 · gain=-0.0116 · mask_l1=0.0019 · preserve_l1=0.1271

reasoning / plan
{
 "visual_evidence": [
  "A large conical evergreen stands near the center of the image.",
  "Warm orange lights are scattered across its branches.",
  "A small dark building is partially visible to the tree's left.",
  "Snow, grazing animals, distant forest, and reflective water surround the tree."
 ],
 "target_object": "The large decorated evergreen tree",
 "target_region": "The central tree, from its pointed crown down to its base in the snow",
 "editing_intent": "Replace the evergreen with a realistically textured palm tree, retaining a few warm decorative lights and preserving the surrounding winter scene.",
 "editing_plan": [
  "Mask the evergreen's silhouette without including the animals or water.",
  "Replace the old canopy with background texture sampled from the nearby sky, forest, and snow, blending the perimeter.",
  "Construct a tapered, curved palm trunk with cylindrical shading and irregular bark rings.",
  "Render overlapping, arching palm fronds with individually curved, tapered leaflets and fine veins.",
  "Add a restrained snow shadow and warm decorative lights, then match texture and feather the new edges."
 ],
 "preservation_constraints": [
  "Preserve all grazing animals.",
  "Preserve the visible building and its snowy roof.",
  "Preserve the water, reflections, foreground snow, and distant landscape outside the tree replacement.",
  "Match the photograph's muted daylight, grain, and soft edge definition."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    w, h = image.size
    src = np.asarray(image.convert('RGB')).copy()
    rng = np.random.default_rng(24)
    unit = float(min(w, h))

    # Trace the existing tree rather than removing a rectangular region.
    outline = [(.456,.143),(.471,.150),(.480,.173),(.494,.181),
        (.501,.202),(.513,.208),(.521,.231),(.534,.238),
        (.532,.259),(.548,.278),(.546,.295),(.562,.321),
        (.555,.344),(.570,.363),(.564,.391),(.575,.411),
        (.572,.438),(.583,.463),(.581,.494),(.587,.512),
        (.578,.540),(.565,.558),(.552,.579),(.518,.585),
        (.466,.585),(.420,.582),(.387,.580),(.354,.562),
        (.338,.544),(.341,.518),(.347,.490),(.348,.469),
        (.350,.448),(.344,.432),(.334,.414),(.345,.395),
        (.339,.381),(.351,.367),(.344,.350),(.359,.332),
        (.353,.318),(.367,.302),(.365,.282),(.383,.276),
        (.380,.255),(.397,.250),(.395,.228),(.410,.215),
        (.411,.195),(.430,.181),(.432,.165),(.445,.158),
        (.447,.147)]
    mask = np.zeros((h,w), np.uint8)
    poly = np.rint(np.array(outline)*[w,h]).astype(np.int32)
    cv2.fillPoly(mask, [poly], 255)
    r = max(1, int(round(unit*.004)))
    mask = cv2.dilate(mask, cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(2*r+1,2*r+1)))

    # Protect the clearly visible bright roof on the left of the canopy.
    yy, xx = np.mgrid[0:h,0:w]
    roof_zone = (xx < .351*w) & (xx > .26*w) & (yy > .431*h) & (yy < .48*h)
    roof_white = roof_zone & (src.min(axis=2) > 173)
    mask[roof_white] = 0

    # Use real nearby background texture, not a blurred large-area inpaint.
    donor_x = np.clip(np.arange(w)+int(round(.315*w)), 0, w-1)
    donor = src[:,donor_x,:].copy()
    a = cv2.GaussianBlur(mask.astype(np.float32)/255, (0,0), max(.6,unit*.0018))
    base = src.astype(np.float32)*(1-a[...,None])+donor.astype(np.float32)*a[...,None]
    bx, by, bw, bh = cv2.boundingRect(mask)
    if bw > 0 and bh > 0:
        try:
            cloned = cv2.seamlessClone(donor, src, mask, (bx+bw//2,by+bh//2), cv2.NORMAL_CLONE)
            base = src.astype(np.float32)*(1-a[...,None])+cloned.astype(np.float32)*a[...,None]
        except cv2.error:
            pass
    base = np.clip(base,0,255)

    # A small, cool cast shadow stays entirely in the snow behind the animals.
    shadow = np.zeros((h,w),np.uint8)
    sp = np.array([(.453,.578),(.483,.574),(.621,.594),(.594,.605),(.495,.591)])
    cv2.fillPoly(shadow,[np.rint(sp*[w,h]).astype(np.int32)],255)
    sh = cv2.GaussianBlur(shadow.astype(np.float32)/255,(0,0),max(.8,.004*unit))
    snow = (base.min(axis=2)>135) & (yy>.565*h) & (yy<.608*h)
    sh *= snow*.17
    base = base*(1-sh[...,None])+np.array([103,126,152],np.float32)*sh[...,None]

    # Supersampling makes the narrow leaflets and bark edges photographic.
    scale = 3
    W,H = w*scale,h*scale
    U = unit*scale
    def point(p):
        return np.array([p[0]*W,p[1]*H],dtype=np.float64)
    def bezier(ctrl,t):
        p = np.array(ctrl,dtype=np.float64)
        t = np.asarray(t,dtype=np.float64)
        return ((1-t)[...,None]**3*p[0] + 3*(1-t)[...,None]**2*t[...,None]*p[1]
            + 3*(1-t)[...,None]*t[...,None]**2*p[2] + t[...,None]**3*p[3])
    def ip(points):
        return np.rint(points).astype(np.int32)
    def blend_layer(rgb, opacity, grain=1.4):
        nonlocal base
        ah = opacity.astype(np.float32)/255
        aa = cv2.resize(ah,(w,h),interpolation=cv2.INTER_AREA)
        prem = cv2.resize(rgb.astype(np.float32)*ah[...,None],(w,h),interpolation=cv2.INTER_AREA)
        noise = rng.normal(0,grain,(h,w)).astype(np.float32)
        coarse = cv2.GaussianBlur(rng.normal(0,1,(h,w)).astype(np.float32),(0,0),max(.6,unit*.003))
        prem += (noise+2.5*coarse)[...,None]*aa[...,None]
        base = np.clip(base*(1-aa[...,None])+prem,0,255)

    # Curved trunk, wider at the base, with left-lit cylindrical bark.
    tc = [point((.470,.582)),point((.485,.478)),point((.439,.354)),point((.465,.237))]
    t = np.linspace(0,1,220)
    center = bezier(tc,t)
    direction = np.gradient(center,axis=0)
    direction /= np.maximum(np.linalg.norm(direction,axis=1)[:,None],1e-6)
    normal = np.stack([-direction[:,1],direction[:,0]],axis=1)
    radius = U*(.014*(1-t)+.0075*t)
    trunk_poly = np.concatenate([center+normal*radius[:,None],(center-normal*radius[:,None])[::-1]])
    trunk_mask = np.zeros((H,W),np.uint8)
    cv2.fillPoly(trunk_mask,[ip(trunk_poly)],255)
    Y,X = np.mgrid[0:H,0:W].astype(np.float32)
    cx = np.interp(np.arange(H),center[::-1,1],center[::-1,0])[:,None]
    rr = np.interp(np.arange(H),center[::-1,1],radius[::-1])[:,None]
    u = np.clip((X-cx)/np.maximum(rr,1),-1.2,1.2)
    light = .67+.35*np.sqrt(np.maximum(0,1-u*u))-.20*u
    phase = Y/(U*.0105)+.25*u*u+.09*np.sin(Y/(U*.019))
    rings = np.exp(-((np.mod(phase,1)-.11)/.095)**2)
    highlights = np.exp(-((np.mod(phase,1)-.28)/.11)**2)
    bark_noise = rng.normal(0,3.1,(H,W)).astype(np.float32)
    fibers = 3*np.sin(X*.73+Y*.05)+2*np.sin(X*.24-Y*.025)
    trunk_rgb = np.empty((H,W,3),np.float32)
    for c, value in enumerate([130,112,78]):
        trunk_rgb[:,:,c] = value*light-24*rings+9*highlights+bark_noise+fibers
    blend_layer(np.clip(trunk_rgb,0,255),trunk_mask,1.4)
    del trunk_rgb, trunk_mask, X, Y, u, rings, highlights, bark_noise, fibers

    # Each frond has an arched rachis and many slender, curved leaflets.
    leaf_rgb = np.zeros((H,W,3),np.uint8)
    leaf_mask = np.zeros((H,W),np.uint8)
    root = (.465,.237)
    fronds = [
        [root,(.432,.169),(.346,.137),(.295,.184)],
        [root,(.452,.162),(.424,.123),(.386,.126)],
        [root,(.486,.169),(.469,.115),(.461,.102)],
        [root,(.506,.124),(.565,.121),(.609,.167)],
        [root,(.555,.174),(.691,.205),(.716,.283)],
        [root,(.533,.159),(.640,.223),(.670,.346)],
        [root,(.369,.162),(.260,.218),(.237,.297)],
        [root,(.365,.222),(.289,.314),(.285,.391)],
        [root,(.523,.240),(.592,.326),(.600,.417)],
        [root,(.381,.267),(.330,.347),(.340,.443)],
        [root,(.490,.271),(.531,.338),(.540,.408)],
        [root,(.434,.284),(.401,.325),(.399,.366)]
    ]
    def draw_path(points,color,width):
        cv2.polylines(leaf_rgb,[ip(points)],False,tuple(int(v) for v in color),max(1,int(round(width))),cv2.LINE_AA)
        cv2.polylines(leaf_mask,[ip(points)],False,255,max(1,int(round(width))),cv2.LINE_AA)
    def leaflet(start,control,end,width,color):
        q = np.linspace(0,1,12)
        path = (1-q)[:,None]**2*start+2*((1-q)*q)[:,None]*control+q[:,None]**2*end
        d = np.gradient(path,axis=0)
        d /= np.maximum(np.linalg.norm(d,axis=1)[:,None],1e-6)
        n = np.stack([-d[:,1],d[:,0]],axis=1)
        widths = width*np.sin(np.pi*q)**.75
        pp = np.concatenate([path+n*widths[:,None],(path-n*widths[:,None])[::-1]])
        cv2.fillPoly(leaf_rgb,[ip(pp)],tuple(int(v) for v in color),cv2.LINE_AA)
        cv2.fillPoly(leaf_mask,[ip(pp)],255,cv2.LINE_AA)
        vein_color = np.clip(np.asarray(color)+[10,11,4],0,255)
        draw_path(path[:10],vein_color,.00065*U)
    for k, normalized in enumerate(fronds):
        ctrl = [point(p) for p in normalized]
        path = bezier(ctrl,np.linspace(0,1,100))
        tone = np.array([44,67,34],dtype=float) + rng.uniform(-7,10)
        if k in (1,2,3,6):
            tone += [13,14,5]
        for j in range(99):
            draw_path(path[j:j+2],tone+[15,16,5],U*.0042*(1-.76*j/99))
        for f in np.linspace(.09,.965,29):
            f = float(np.clip(f+rng.uniform(-.007,.007),.05,.98))
            p = bezier(ctrl,f)
            d = bezier(ctrl,min(1,f+.003))-bezier(ctrl,max(0,f-.003))
            d /= max(np.linalg.norm(d),1e-6)
            n = np.array([-d[1],d[0]])
            length = U*(.008+.040*np.sin(np.pi*f)**.75)*rng.uniform(.84,1.12)
            for side in (-1,1):
                end = p+n*side*length+d*length*.30+np.array([0,U*.0045*f])
                control = p+n*side*length*.59+d*length*.025
                col = np.clip(tone+rng.uniform(-10,12)+([6,8,1] if side==-1 else [-3,-3,-2]),0,255)
                leaflet(p,control,end,U*.00165*(.4+.6*np.sin(np.pi*f)),col)
        draw_path(path,tone+[24,24,10],U*.0011)
    # Short overlapping leaf sheaths conceal the trunk-to-crown junction.
    for dx,dy in [(-.012,-.019),(.016,-.016),(-.007,-.027),(.009,-.023)]:
        p = point(root)
        e = point((root[0]+dx,root[1]+dy))
        leaflet(p,(p+e)/2+point((.003,0)),e,U*.004,[63,81,37])
    blend_layer(leaf_rgb,leaf_mask,1.6)

    # Retain the existing festive character with a few soft amber bulbs.
    lights = [(.331,.223),(.385,.192),(.452,.158),(.555,.185),
        (.631,.263),(.571,.334),(.344,.324),(.406,.310),
        (.465,.291),(.460,.384),(.470,.477),(.471,.547)]
    Y0,X0 = np.mgrid[0:h,0:w].astype(np.float32)
    for i,(lx,ly) in enumerate(lights):
        radius = unit*(.0049 if i<8 else .0043)
        dx = X0-lx*w
        dy = Y0-ly*h
        dist2 = dx*dx+dy*dy
        halo = .25*np.exp(-dist2/(2*(radius*2.6)**2))
        base = base*(1-halo[...,None])+np.array([237,130,32],np.float32)*halo[...,None]
        bulb = np.clip((radius+.65-np.sqrt(dist2))/1.3,0,1)*.92
        shine = np.exp(-((dx+radius*.26)**2+(dy+radius*.30)**2)/(radius*radius*.38))
        color = np.empty((h,w,3),np.float32)
        color[:,:,0] = 249+6*shine
        color[:,:,1] = 151+76*shine
        color[:,:,2] = 31+104*shine
        base = base*(1-bulb[...,None])+color*bulb[...,None]
    return Image.fromarray(np.clip(base,0,255).astype(np.uint8),'RGB')
Put a ball of icecream on top of the pancake.
magicbrush_train_441199_2 · add / insert · execution=passed
PASSinstr 5preserve 5quality 4
source
GPT-6.1-Sol output
MagicBrush target (reference only)

A ball of ice cream has been added on top of the pancake in the correct region. The rest of the scene is essentially unchanged. The ice cream is plausible, though it appears a bit smooth and lacks strong contact shadow, making it slightly less integrated.

l1=0.0215 · gain=-0.0074 · mask_l1=0.0001 · preserve_l1=0.0317

reasoning / plan
{
 "visual_evidence": [
  "A large round, browned pancake occupies the center of a white plate.",
  "A pale cut through the pancake runs diagonally down its middle.",
  "The pancake has a textured brown surface and pale, thick edges.",
  "Brown powder and dark sauce are visible near the lower edge of the plate."
 ],
 "target_object": "The pancake",
 "target_region": "The upper-middle portion of the pancake, overlapping part of the central cut",
 "editing_intent": "Add a realistic, rounded scoop of vanilla ice cream resting on the pancake.",
 "editing_plan": [
  "Construct a softly irregular scoop silhouette with a rounded top and slightly scalloped lower edge.",
  "Add a soft cast shadow and a narrower contact shadow on the pancake.",
  "Render warm ivory ice cream with directional lighting, curved scoop marks, fine pits, and uneven frozen texture.",
  "Feather the scoop boundary and composite it over the original pixels.",
  "Preserve the plate, pancake perimeter, sauce, powder, and surrounding background."
 ],
 "preservation_constraints": [
  "Do not change the pancake outside the scoop and its shadow.",
  "Keep the white plate and its existing stains unchanged.",
  "Preserve the background and original image dimensions.",
  "Keep the pancake's central cut visible below the added scoop."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    w, h = image.size
    original = np.asarray(image.convert('RGB'), dtype=np.float32)
    rng = np.random.default_rng(2718)
    scale = 2
    W, H = w * scale, h * scale
    yy, xx = np.mgrid[0:H, 0:W].astype(np.float32)
    xx = (xx + 0.5) / W
    yy = (yy + 0.5) / H
    cx, cy = 0.505, 0.393
    rx, ry = 0.121, 0.125
    X = (xx - cx) / rx
    Y = (yy - cy) / ry
    radius = np.sqrt(X * X + Y * Y)
    angle = np.arctan2(Y, X)

    def noise(cell_fraction):
        nw = max(3, int(np.ceil(1.0 / cell_fraction)))
        nh = max(3, int(np.ceil((h / float(w)) / cell_fraction)))
        small = rng.normal(0, 1, (nh, nw)).astype(np.float32)
        return cv2.resize(small, (W, H), interpolation=cv2.INTER_CUBIC)

    broad = noise(0.026)
    medium = noise(0.008)
    fine = noise(0.0025)
    contour = (1.0 + 0.010 * np.sin(11 * angle + 0.8)
               + 0.006 * np.sin(23 * angle - 0.5)
               + 0.008 * broad)
    lower_ripple = 0.919 + 0.027 * np.sin(11 * X + 0.3) + 0.012 * np.sin(27 * X)
    signed = np.maximum(radius - contour, Y - lower_ripple)
    feather = max(0.006, 0.65 / (W * rx))
    alpha = np.clip(0.5 - signed / (2.0 * feather), 0, 1)
    alpha = alpha * alpha * (3.0 - 2.0 * alpha)

    # Shadows remain entirely within the pancake's central surface.
    shadow_y = cy + 0.117
    broad_shadow = 0.31 * np.exp(-2.6 * (((xx - cx - 0.012) / 0.151) ** 2
                                       + ((yy - shadow_y - 0.006) / 0.039) ** 2))
    contact_shadow = 0.30 * np.exp(-2.4 * (((xx - cx) / 0.105) ** 2
                                         + ((yy - shadow_y) / 0.011) ** 2))
    shadow = 1.0 - (1.0 - broad_shadow) * (1.0 - contact_shadow)
    shadow = cv2.resize(shadow, (w, h), interpolation=cv2.INTER_AREA)
    shadow_tint = np.array([0.47, 0.40, 0.33], dtype=np.float32)
    canvas = original * (1.0 - shadow[..., None] * (1.0 - shadow_tint))

    # A softly lit spherical body, with the light coming from above-left.
    rr = np.minimum(radius, 0.998)
    Z = np.sqrt(np.maximum(1.0 - rr * rr, 0.003))
    norm = np.sqrt(X * X + Y * Y + Z * Z)
    nx, ny, nz = X / norm, Y / norm, Z / norm
    light = np.array([-0.38, -0.48, 0.79], dtype=np.float32)
    light /= np.linalg.norm(light)
    lambert = np.maximum(nx * light[0] + ny * light[1] + nz * light[2], 0)
    brightness = 0.72 + 0.285 * lambert
    lower_shading = np.clip((Y - 0.45) / 0.55, 0, 1)
    brightness -= 0.048 * lower_shading
    base = np.array([249.0, 237.0, 213.0], dtype=np.float32)
    scoop = brightness[..., None] * base
    scoop += (2.0 * broad + 1.7 * medium + 0.85 * fine)[..., None]

    # Irregular, shallow curved marks left by an ice-cream scoop.
    grooves = np.zeros((H, W), dtype=np.float32)
    ridges = np.zeros((H, W), dtype=np.float32)
    arc_specs = [(-0.61, -0.53, 0.44),
                 (-0.30, -0.76, 0.60),
                 (0.05, -0.71, 0.72),
                 (0.40, -0.53, 0.62)]
    for k, (level, left, right) in enumerate(arc_specs):
        t = np.linspace(left, right, 130)
        ax = t + 0.023 * np.sin(7 * t + k)
        ay = level + (0.15 + 0.025 * k) * t * t + 0.020 * np.sin(8 * t + 1.3 * k)
        pts = np.column_stack(((cx + rx * ax) * W, (cy + ry * ay) * H)).astype(np.int32)
        cv2.polylines(grooves, [pts], False, 1.0, max(1, int(round(W * 0.00125))), cv2.LINE_AA)
        shifted = pts.copy()
        shifted[:, 1] -= max(1, int(round(H * 0.0022)))
        cv2.polylines(ridges, [shifted], False, 1.0, max(1, int(round(W * 0.0016))), cv2.LINE_AA)
    sigma = max(0.45, W * 0.0008)
    grooves = cv2.GaussianBlur(grooves, (0, 0), sigma)
    ridges = cv2.GaussianBlur(ridges, (0, 0), sigma)
    intermittent = np.clip(0.65 + 0.45 * medium + 0.20 * broad, 0.12, 1.0)
    scoop += (3.1 * ridges - 5.2 * grooves)[..., None] * intermittent[..., None]

    # Fine frozen pores: tiny shaded recesses with understated bright rims.
    pits = np.zeros((H, W), dtype=np.float32)
    pit_rims = np.zeros((H, W), dtype=np.float32)
    for _ in range(240):
        px = rng.uniform(-0.94, 0.94)
        py = rng.uniform(-0.92, 0.88)
        if px * px + py * py > 0.89:
            continue
        ix = int((cx + rx * px) * W)
        iy = int((cy + ry * py) * H)
        pr = max(1, int(rng.uniform(0.0007, 0.0020) * W))
        strength = float(rng.uniform(0.25, 0.85))
        cv2.ellipse(pits, (ix, iy), (pr, max(1, int(pr * 0.65))),
                    float(rng.uniform(-40, 40)), 0, 360, strength, -1, cv2.LINE_AA)
        cv2.circle(pit_rims, (ix - 1, iy - 1), max(1, pr // 2), strength * 0.65, -1, cv2.LINE_AA)
    pits = cv2.GaussianBlur(pits, (0, 0), max(0.4, W * 0.00045))
    pit_rims = cv2.GaussianBlur(pit_rims, (0, 0), max(0.4, W * 0.0005))
    scoop += (-5.0 * pits + 2.4 * pit_rims)[..., None]

    # Soft surface sheen, not a glossy plastic highlight.
    sheen = np.exp(-(((X + 0.32) / 0.44) ** 2 + ((Y + 0.43) / 0.32) ** 2) * 2.0)
    scoop += sheen[..., None] * np.array([2.0, 3.0, 4.0], dtype=np.float32)
    scoop += rng.normal(0, 0.85, (H, W, 1)).astype(np.float32)
    scoop = np.clip(scoop, 0, 255)

    # Downsample premultiplied color to retain a clean, feathered contour.
    premultiplied = cv2.resize(scoop * alpha[..., None], (w, h), interpolation=cv2.INTER_AREA)
    a = cv2.resize(alpha, (w, h), interpolation=cv2.INTER_AREA)
    result = canvas * (1.0 - a[..., None]) + premultiplied
    untouched = (a == 0) & (shadow < 0.0005)
    result[untouched] = original[untouched]
    return Image.fromarray(np.clip(np.rint(result), 0, 255).astype(np.uint8), 'RGB')
Put a rat on the floor.
magicbrush_train_231874_1 · add / insert · execution=passed
PASSinstr 5preserve 5quality 4
source
GPT-6.1-Sol output
MagicBrush target (reference only)

A rat was added on the floor in an appropriate region, while the cat, chair, text, and background remain unchanged. The rat is somewhat cartoon-like and not perfectly matched to the photo lighting, but it is visually clear and acceptable.

l1=0.0125 · gain=0.0021 · mask_l1=0.0076 · preserve_l1=0.0138

reasoning / plan
{
 "visual_evidence": [
  "Dark brown tiled flooring is visible between the left pedestal and the wooden chair.",
  "A white cat is lying on the chair, holding a wooden bat.",
  "Large white captions occupy the top and bottom of the image.",
  "There is open floor above the bottom caption and left of the chair legs."
 ],
 "target_object": "A new rat on the visible floor",
 "target_region": "Open floor in the lower middle-left, above the bottom caption and clear of the chair legs",
 "editing_intent": "Add a small, realistically shaded gray-brown rat facing left, with fur, ears, paws, whiskers, a curved tail, and a contact shadow.",
 "editing_plan": [
  "Locate the clear floor using coordinates relative to the image dimensions.",
  "Create soft floor shadows and a tapered, curved tail.",
  "Construct the rat's paws, body, head, and ears with overlapping anatomical masks.",
  "Add directional fur texture, facial details, and lighting consistent with the dim scene.",
  "Antialias and feather the added pixels while preserving all surrounding content."
 ],
 "preservation_constraints": [
  "Do not alter either caption or the small bottom watermark.",
  "Preserve the cat, bat, chair, and left pedestal.",
  "Retain the floor texture outside the rat and its shadow.",
  "Do not change the image dimensions."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image, ImageDraw

    w, h = image.size
    src = np.asarray(image.convert('RGB'), dtype=np.float32)
    scale = 3
    W, H = w * scale, h * scale
    base = cv2.resize(src, (W, H), interpolation=cv2.INTER_CUBIC)
    work = base.copy()
    rng = np.random.default_rng(817)
    yy, xx = np.mgrid[0:H, 0:W].astype(np.float32)
    X, Y = xx / W, yy / H

    def point(p):
        return (int(round(p[0] * W)), int(round(p[1] * H)))

    def ellipse(cx, cy, rx, ry, angle=0, feather=0.00065):
        m = np.zeros((H, W), np.uint8)
        cv2.ellipse(m, point((cx, cy)),
                    (max(1, int(rx * W)), max(1, int(ry * H))),
                    angle, 0, 360, 255, -1, cv2.LINE_AA)
        m = m.astype(np.float32) / 255.0
        if feather:
            m = cv2.GaussianBlur(m, (0, 0), max(0.35, feather * min(W, H)))
        return m

    def bezier(a, b, c, d, n=40):
        t = np.linspace(0, 1, n)[:, None]
        return ((1-t)**3 * np.array(a) + 3*(1-t)**2*t*np.array(b)
                + 3*(1-t)*t*t*np.array(c) + t**3*np.array(d))

    def shape(segments, feather=0.00065):
        pts = np.concatenate([bezier(*seg) for seg in segments])
        m = np.zeros((H, W), np.uint8)
        pp = np.round(pts * np.array([W, H])).astype(np.int32)
        cv2.fillPoly(m, [pp], 255, lineType=cv2.LINE_AA)
        m = m.astype(np.float32) / 255.0
        return cv2.GaussianBlur(m, (0, 0), max(0.35, feather * min(W, H)))

    def blend(mask, color, opacity=1.0):
        nonlocal work
        a = np.clip(mask * opacity, 0, 1)[..., None]
        color = np.asarray(color, dtype=np.float32)
        work = work * (1-a) + color * a

    small = rng.normal(0, 1, (max(8, h), max(8, w))).astype(np.float32)
    grain = cv2.resize(small, (W, H), interpolation=cv2.INTER_LINEAR)
    coarse = rng.normal(0, 1, (max(8, h//7), max(8, w//7))).astype(np.float32)
    coarse = cv2.resize(coarse, (W, H), interpolation=cv2.INTER_CUBIC)

    def coat(mask, center, radii, rgb, gain=1.0):
        cx, cy = center
        rx, ry = radii
        qx = (X-cx)/rx
        qy = (Y-cy)/ry
        depth = np.sqrt(np.maximum(0, 1-np.minimum(1, qx*qx+qy*qy)))
        top = np.clip((cy-Y)/ry, -1, 1)
        light = (0.48 + 0.46*depth + 0.18*top) * gain
        texture = 3.2*grain + 2.1*coarse
        colors = light[..., None]*np.array(rgb, np.float32) + texture[..., None]
        blend(mask, np.clip(colors, 0, 255))

    def fur(mask, box, count, direction=0.08):
        layer = Image.new('RGBA', (W, H), (0, 0, 0, 0))
        draw = ImageDraw.Draw(layer)
        x0, y0, x1, y1 = box
        for _ in range(count):
            x = rng.uniform(x0, x1)
            y = rng.uniform(y0, y1)
            px, py = point((x, y))
            if not (0 <= px < W and 0 <= py < H) or mask[py, px] < 0.88:
                continue
            theta = direction + rng.normal(0, 0.40)
            length = rng.uniform(0.0013, 0.0048)
            end = (x + length*np.cos(theta), y + length*np.sin(theta))
            ex, ey = point(end)
            if not (0 <= ex < W and 0 <= ey < H) or mask[ey, ex] < 0.65:
                continue
            change = rng.normal(2, 16)
            color = np.clip(work[py, px] + change, 0, 255).astype(int)
            rgba = tuple(int(v) for v in color) + (int(rng.integers(35, 110)),)
            draw.line([point((x, y)), point(end)], fill=rgba,
                      width=max(1, int(0.00045*min(W, H))))
        arr = np.asarray(layer, dtype=np.float32)
        blend((arr[..., 3]/255.0)*mask, arr[..., :3])

    # Broad cast shadow and a narrower contact shadow follow the floor plane.
    shadow = np.exp(-(((X-0.419)/0.088)**2 + ((Y-0.783)/0.016)**2)*1.6)
    blend(shadow, work*0.53, 0.48)
    contact = np.exp(-(((X-0.420)/0.064)**2 + ((Y-0.779)/0.0065)**2)*1.7)
    blend(contact, work*0.40, 0.55)

    # The tail is curved, tapered, and rendered behind the body.
    tail = np.concatenate([
        bezier((0.482,0.760), (0.514,0.790), (0.552,0.785), (0.576,0.767), 70),
        bezier((0.576,0.767), (0.598,0.749), (0.619,0.769), (0.610,0.787), 60),
        bezier((0.610,0.787), (0.605,0.799), (0.591,0.800), (0.583,0.794), 40)
    ])
    tm = np.zeros((H, W), np.uint8)
    for i in range(len(tail)-1):
        t = i / (len(tail)-1)
        width = max(1, int(W*(0.0070*(1-t)**1.1 + 0.00065)))
        cv2.line(tm, point(tail[i]), point(tail[i+1]), 255, width, cv2.LINE_AA)
    tailmask = cv2.GaussianBlur(tm.astype(np.float32)/255, (0,0), 0.45)
    tailshadow = cv2.warpAffine(tailmask, np.float32([[1,0,0],[0,1,H*0.003]]), (W,H))
    tailshadow = cv2.GaussianBlur(tailshadow, (0,0), max(0.6,H*0.0025))
    blend(tailshadow, work*0.6, 0.32)
    tailcolor = np.empty((H,W,3), np.float32)
    tailcolor[:] = [88, 70, 59]
    tailcolor += (grain*2.6)[...,None]
    blend(tailmask, tailcolor)
    tl = Image.new('RGBA', (W,H), (0,0,0,0))
    td = ImageDraw.Draw(tl)
    for i in range(0, len(tail)-1, 2):
        p, q = tail[i], tail[i+1]
        t = i/(len(tail)-1)
        td.line([point((p[0],p[1]-0.0011*(1-t))),
                 point((q[0],q[1]-0.0011*(1-t)))],
                fill=(135,108,91,85), width=max(1,int(W*0.0011*(1-t))))
    ar = np.asarray(tl, dtype=np.float32)
    blend(ar[...,3]/255*tailmask, ar[...,:3])

    # Small paws are underneath the torso rather than floating beside it.
    rearfoot = shape([
        ((0.456,0.765),(0.470,0.765),(0.476,0.773),(0.470,0.777)),
        ((0.470,0.777),(0.476,0.780),(0.478,0.784),(0.472,0.786)),
        ((0.472,0.786),(0.461,0.787),(0.449,0.783),(0.449,0.777)),
        ((0.449,0.777),(0.450,0.771),(0.452,0.768),(0.456,0.765))
    ])
    frontfoot = shape([
        ((0.373,0.756),(0.380,0.760),(0.376,0.771),(0.369,0.777)),
        ((0.369,0.777),(0.359,0.781),(0.347,0.781),(0.346,0.777)),
        ((0.346,0.777),(0.350,0.773),(0.360,0.775),(0.360,0.767)),
        ((0.360,0.767),(0.361,0.762),(0.367,0.759),(0.373,0.756))
    ])
    coat(rearfoot, (0.463,0.777), (0.020,0.012), [105,86,71])
    coat(frontfoot, (0.365,0.772), (0.023,0.012), [102,87,74])

    body = ellipse(0.433,0.738,0.068,0.034,-7)
    coat(body, (0.433,0.734), (0.071,0.041), [113,105,90])
    fur(body, (0.362,0.699,0.505,0.779), 2600, 0.08)
    haunch = ellipse(0.473,0.747,0.026,0.026,-12)
    coat(haunch, (0.471,0.743), (0.030,0.031), [103,96,82], 0.96)
    fur(haunch, (0.445,0.716,0.503,0.777), 800, 0.65)

    # A tapered head, with the muzzle pointing left.
    head = shape([
        ((0.399,0.723),(0.385,0.714),(0.365,0.716),(0.351,0.729)),
        ((0.351,0.729),(0.340,0.739),(0.329,0.742),(0.317,0.749)),
        ((0.317,0.749),(0.315,0.754),(0.326,0.761),(0.341,0.764)),
        ((0.341,0.764),(0.361,0.770),(0.388,0.767),(0.400,0.750)),
        ((0.400,0.750),(0.405,0.740),(0.403,0.728),(0.399,0.723))
    ])
    coat(head, (0.371,0.742), (0.051,0.034), [111,103,89])
    fur(head, (0.315,0.713,0.406,0.771), 1300, 2.95)

    # Thin, softly shaded ears with darker fur at their bases.
    backear = ellipse(0.385,0.712,0.009,0.014,-25)
    coat(backear, (0.384,0.710), (0.011,0.017), [103,89,77])
    blend(ellipse(0.384,0.710,0.005,0.009,-25), [104,80,72], 0.70)
    ear = ellipse(0.367,0.712,0.012,0.016,-20)
    coat(ear, (0.365,0.707), (0.016,0.021), [126,112,99])
    inner = ellipse(0.366,0.711,0.0079,0.0107,-20)
    earshade = np.clip(0.90 - (Y-0.707)*14, 0.55, 1.05)
    blend(inner, earshade[...,None]*np.array([121,92,82]) + grain[...,None]*2)
    blend(ellipse(0.370,0.722,0.011,0.005,-10), [71,65,55], 0.48)

    muzzle = ellipse(0.330,0.754,0.012,0.0065,12)
    coat(muzzle, (0.329,0.751), (0.015,0.010), [111,101,88])
    nose = ellipse(0.3175,0.7518,0.0032,0.0028,-8,0.00035)
    blend(nose, [105,77,70])
    blend(ellipse(0.3168,0.7509,0.0011,0.00065,0,0.0002), [157,122,108], 0.65)
    blend(ellipse(0.3465,0.7381,0.0060,0.0043,-15), [58,53,45], 0.65)
    blend(ellipse(0.3460,0.7375,0.0040,0.0034,-15,0.00035), [13,12,10])
    blend(ellipse(0.3471,0.7364,0.0011,0.00085,0,0.0002), [190,177,150], 0.9)

    details = Image.new('RGBA', (W,H), (0,0,0,0))
    dd = ImageDraw.Draw(details)
    width = max(1,int(min(W,H)*0.00055))
    dd.line([point((0.319,0.757)),point((0.332,0.762)),point((0.344,0.761))],
            fill=(35,31,26,110), width=width)
    for x in [0.352,0.359,0.366]:
        dd.line([point((x,0.777)),point((x+0.002,0.780))], fill=(42,35,29,125), width=width)
    for x in [0.459,0.465,0.470]:
        dd.line([point((x,0.781)),point((x+0.002,0.785))], fill=(42,35,29,115), width=width)
    for start, control, end in [
        ((0.330,0.752),(0.313,0.742),(0.290,0.745)),
        ((0.329,0.755),(0.309,0.752),(0.286,0.757)),
        ((0.332,0.758),(0.312,0.762),(0.298,0.772)),
        ((0.332,0.751),(0.318,0.736),(0.303,0.735)),
        ((0.337,0.755),(0.354,0.758),(0.369,0.766))
    ]:
        curve = bezier(start, control, control, end, 22)
        dd.line([point(p) for p in curve], fill=(137,132,114,85), width=max(1,int(W*0.0004)))
    ar = np.asarray(details, dtype=np.float32)
    blend(ar[...,3]/255, ar[...,:3])

    # Transfer only the locally synthesized difference, leaving original pixels elsewhere intact.
    delta = cv2.resize(work-base, (w,h), interpolation=cv2.INTER_AREA)
    out = np.clip(src + delta, 0, 255).astype(np.uint8)
    return Image.fromarray(out, 'RGB')
Have the man hold a sword.
magicbrush_train_159231_1 · add / insert · execution=passed
PASSinstr 4preserve 5quality 4
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The edit adds a sword positioned in the man's raised hand, satisfying the request. The rest of the scene is essentially unchanged. The sword compositing is fairly clean, though it looks somewhat pasted on and the grip/hand interaction is not fully natural.

l1=0.0189 · gain=-0.0010 · mask_l1=0.0088 · preserve_l1=0.0225

reasoning / plan
{
 "visual_evidence": [
  "The man is dressed as Santa and has a raised black-gloved hand on the left side of the image.",
  "The raised hand is beside wrapped gifts, with open space above and to its left.",
  "His face, white beard, red coat, and the motorcycle are clearly visible."
 ],
 "target_object": "The man's raised black-gloved hand and a new sword",
 "target_region": "The raised hand left of his face, with the blade extending diagonally toward the upper-left corner",
 "editing_intent": "Make the raised glove grip a realistic sword, replacing the waving fingers with curled gripping fingers.",
 "editing_plan": [
  "Mask the existing raised glove and locally reconstruct the background behind its projecting fingers.",
  "Construct a dark, textured glove palm and wrist connected to the existing white cuff.",
  "Render a tapered steel blade, reflective crossguard, wrapped leather grip, and metal pommel.",
  "Layer curled glove fingers and a thumb over the grip to establish a convincing hold.",
  "Antialias the new objects, add local shading and fine texture, and preserve pixels outside the edited region."
 ],
 "preservation_constraints": [
  "Preserve the man's face, beard, hat, and white sleeve cuff.",
  "Preserve the motorcycle, windshield, lights, and decorations.",
  "Preserve the other visible person and the background outside the hand and sword.",
  "Do not apply global color or lighting changes."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    image = image.convert('RGB')
    w, h = image.size
    src = np.asarray(image).copy()
    rng = np.random.default_rng(27)

    # Remove only the original raised glove; the white cuff is excluded.
    outline = np.array([
        [.242,.238],[.244,.218],[.251,.207],[.260,.214],
        [.259,.204],[.270,.198],[.280,.211],[.283,.200],
        [.295,.198],[.307,.214],[.315,.241],[.327,.240],
        [.339,.236],[.347,.249],[.339,.270],[.326,.300],
        [.322,.324],[.307,.347],[.294,.372],[.272,.366],
        [.265,.337],[.250,.305],[.242,.275]
    ], np.float32)
    removal = np.zeros((h,w), np.uint8)
    cv2.fillPoly(removal, [np.round(outline*[w,h]).astype(np.int32)], 255)
    radius = max(1, int(round(min(w,h)*.002)))
    removal = cv2.dilate(removal, cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2*radius+1,2*radius+1)))
    filled = cv2.inpaint(src, removal, max(2, min(w,h)*.007), cv2.INPAINT_TELEA).astype(np.float32)
    # Restore fine photographic grain to the locally reconstructed pixels.
    grain = rng.normal(0, 1.15, (h,w,1)).astype(np.float32)
    filled += grain*(removal[...,None]/255.0)
    filled = np.clip(filled,0,255)

    scale = 3
    W,H = w*scale,h*scale
    U = float(min(W,H))
    canvas = cv2.resize(filled, (W,H), interpolation=cv2.INTER_CUBIC)
    coverage = cv2.resize(removal.astype(np.float32)/255, (W,H), interpolation=cv2.INTER_LINEAR)
    yy,xx = np.mgrid[0:H,0:W].astype(np.float32)
    noise = rng.normal(0,1,(H,W)).astype(np.float32)

    def point(x,y):
        return np.array([x*W,y*H], np.float32)

    def paint_mask(mask, color, texture=1.0, bevel=0.0):
        nonlocal canvas, coverage
        m = mask.astype(np.float32)/255
        if not np.any(m):
            return
        alpha = cv2.GaussianBlur(m,(0,0),max(.35,U*.00036))
        if np.asarray(color).ndim == 1:
            field = np.empty((H,W,3),np.float32)
            field[:] = color
        else:
            field = np.asarray(color,np.float32).copy()
        field += noise[...,None]*texture
        if bevel:
            dist = cv2.distanceTransform(mask,cv2.DIST_L2,3)
            edge = np.exp(-dist/max(1,U*.0022))
            gx = cv2.Sobel(m,cv2.CV_32F,1,0,ksize=3)
            gy = cv2.Sobel(m,cv2.CV_32F,0,1,ksize=3)
            orient = cv2.GaussianBlur(gx-gy,(0,0),max(1,U*.0016))
            field += (edge*bevel + orient*bevel*.3)[...,None]
        canvas = canvas*(1-alpha[...,None])+np.clip(field,0,255)*alpha[...,None]
        coverage = np.maximum(coverage,alpha)

    def polygon(points, color, texture=1.0, bevel=0.0):
        mask = np.zeros((H,W),np.uint8)
        cv2.fillPoly(mask,[np.round(points).astype(np.int32)],255)
        paint_mask(mask,color,texture,bevel)

    def smooth(points):
        p = np.asarray(points,np.float32)
        out=[]
        for i in range(len(p)):
            a,b,c,d=p[(i-1)%len(p)],p[i],p[(i+1)%len(p)],p[(i+2)%len(p)]
            for t in np.linspace(0,1,12,endpoint=False):
                out.append(.5*((2*b)+(-a+c)*t+(2*a-5*b+4*c-d)*t*t+(-a+3*b-3*c+d)*t*t*t))
        return np.asarray(out)

    def glove_shape(coords, rgb, shine=10):
        pts = smooth([point(*p) for p in coords])
        center = pts.mean(axis=0)
        rx=max(np.ptp(pts[:,0])*.65,1)
        ry=max(np.ptp(pts[:,1])*.65,1)
        lighting = np.exp(-((xx-center[0]-rx*.13)/rx)**2-((yy-center[1]+ry*.25)/ry)**2)
        field=np.empty((H,W,3),np.float32)
        field[:]=rgb
        field += lighting[...,None]*shine
        field += (1.0*np.sin(xx*.33+yy*.19))[...,None]
        polygon(pts,field,2.0,1.2)

    # A rounded leather palm and wrist, ending inside the existing cuff.
    glove_shape([
        [.252,.256],[.266,.244],[.281,.247],[.302,.260],
        [.323,.284],[.332,.307],[.322,.329],[.304,.350],
        [.295,.369],[.275,.365],[.267,.342],[.253,.322],
        [.244,.290]
    ],[14,18,20],11)

    C=point(.275,.232)
    tip=point(.060,.018)
    direction=C-tip
    direction/=np.linalg.norm(direction)
    normal=np.array([-direction[1],direction[0]],np.float32)
    def local(a,b):
        return C+direction*(a*U)+normal*(b*U)
    along=((xx-C[0])*direction[0]+(yy-C[1])*direction[1])/U
    across=((xx-C[0])*normal[0]+(yy-C[1])*normal[1])/U

    root=local(-.014,0)
    shoulder=local(-.040,0)
    blade=[tip,shoulder-normal*.014*U,root-normal*.017*U,
           root+normal*.017*U,shoulder+normal*.014*U]
    # Dark steel outline beneath two differently lit, tapered facets.
    polygon(blade,[82,99,105],1.5,13)
    modulation=10*np.sin(along*22)+4*np.sin(along*67)
    left=np.zeros((H,W,3),np.float32)+np.array([150,166,172],np.float32)
    left += modulation[...,None]
    left += (12*np.exp(-((across+.010)/.004)**2))[...,None]
    right=np.zeros((H,W,3),np.float32)+np.array([207,218,219],np.float32)
    right += (modulation*.7)[...,None]
    right -= (25*np.clip(across/.018,0,1))[...,None]
    polygon([tip,shoulder-normal*.013*U,root-normal*.0155*U,root],left,1.25)
    polygon([tip,root,root+normal*.0155*U,shoulder+normal*.013*U],right,1.25)
    # Narrow polished central ridge and edge highlights.
    polygon([tip,local(-.014,-.00065),local(-.014,.00065)], [235,240,237],.7)
    polygon([tip,shoulder-normal*.014*U,root-normal*.0165*U,
             root-normal*.0154*U,shoulder-normal*.013*U],[198,216,220],.8)
    polygon([local(-.044,-.0055),local(-.020,-.0055),
             local(-.020,-.0042),local(-.044,-.0042)],[104,124,130],.8)

    # The grip lies above the palm but behind the curling fingers.
    polygon([local(.006,-.0105),local(.083,-.009),
             local(.083,.009),local(.006,.0105)],[33,25,21],2,4)
    for k in range(9):
        a=.010+k*.008
        polygon([local(a,-.010),local(a+.003,-.010),
                 local(a+.007,.0095),local(a+.004,.0095)],
                [65,49,37] if k%2==0 else [50,38,30],1.3)
        polygon([local(a+.003,-.010),local(a+.004,-.010),
                 local(a+.008,.0095),local(a+.007,.0095)],[20,18,17],.8)
    polygon([local(.006,-.012),local(.013,-.012),
             local(.013,.012),local(.006,.012)],[143,151,147],1,8)

    # Slightly swept crossguard, with a bright bevel and dark lower edge.
    guard_local=[(-.006,-.049),(-.011,-.045),(-.006,-.028),
                 (-.008,-.011),(-.007,.011),(-.006,.028),
                 (-.011,.045),(-.006,.049),(.003,.047),
                 (.007,.027),(.007,.012),(.009,0),
                 (.007,-.012),(.007,-.027),(.003,-.047)]
    guard_field=np.zeros((H,W,3),np.float32)+np.array([125,139,143],np.float32)
    guard_field += (45*np.exp(-((along+.004)/.003)**2)-20*np.clip(along/.009,0,1))[...,None]
    polygon(smooth([local(a,b) for a,b in guard_local]),guard_field,1.7,9)
    polygon([local(-.007,-.039),local(-.008,-.018),local(-.007,.016),
             local(-.008,.039),local(-.005,.038),local(-.004,.014),
             local(-.005,-.018),local(-.004,-.039)],[211,222,222],.8)

    # Rounded metal pommel at the exposed end of the leather grip.
    pommel=[]
    for a in np.linspace(0,2*np.pi,52,endpoint=False):
        pommel.append(local(.089+.013*np.cos(a),.014*np.sin(a)))
    pmfield=np.zeros((H,W,3),np.float32)+np.array([110,125,129],np.float32)
    pmfield += (75*np.exp(-((along-.084)/.007)**2-((across+.004)/.012)**2))[...,None]
    polygon(pommel,pmfield,1.5,8)
    polygon([local(.078,-.012),local(.081,-.012),
             local(.081,.012),local(.078,.012)],[197,205,201],.8)

    # Four curled fingers cross the handle; rounded lobes and seams convey leather.
    fingers=[
        ([ [.267,.245],[.277,.244],[.287,.253],[.280,.265],
           [.263,.282],[.254,.277],[.254,.266] ],[26,30,32],13),
        ([ [.282,.258],[.292,.256],[.301,.266],[.293,.281],
           [.277,.295],[.267,.289],[.268,.278] ],[24,28,30],12),
        ([ [.297,.272],[.307,.272],[.315,.282],[.307,.297],
           [.292,.309],[.282,.302],[.285,.289] ],[22,26,28],12),
        ([ [.311,.286],[.321,.286],[.327,.297],[.319,.312],
           [.306,.321],[.296,.314],[.299,.302] ],[20,24,26],10)
    ]
    for coords,rgb,shine in fingers:
        glove_shape(coords,rgb,shine)
    # Thumb wraps over the near side of the fist and contacts the grip.
    glove_shape([
        [.325,.316],[.325,.299],[.316,.286],[.306,.275],
        [.296,.270],[.289,.277],[.294,.290],[.304,.300],
        [.307,.314],[.314,.327]
    ],[29,32,33],12)
    # Wrist fold: subdued, feathered, and contained within the new glove.
    polygon(smooth([point(.274,.346),point(.286,.350),point(.302,.339),
                    point(.300,.344),point(.285,.356),point(.275,.352)]),
            [11,15,17],1.2)

    edited=cv2.resize(np.clip(canvas,0,255),(w,h),interpolation=cv2.INTER_AREA)
    alpha=cv2.resize(coverage,(w,h),interpolation=cv2.INTER_AREA)
    alpha=np.clip(alpha,0,1)[...,None]
    result=src.astype(np.float32)*(1-alpha)+edited*alpha
    return Image.fromarray(np.clip(np.round(result),0,255).astype(np.uint8),'RGB')
can we make the baseball bat shorter?
magicbrush_train_231874_2 · replace / change · execution=passed
PASSinstr 4preserve 4quality 3
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The baseball bat was successfully made shorter while the cat, mouse, chair, and meme text were largely preserved. However, the edited left end of the bat has noticeable dark smearing and cut-out artifacts, making the result look somewhat unnatural.

l1=0.0094 · gain=-0.0042 · mask_l1=0.0006 · preserve_l1=0.0116

reasoning / plan
{
 "visual_evidence": [
  "A wooden baseball bat extends diagonally from the left edge toward the white cat.",
  "The cat's paws hold the narrow end of the bat on the right.",
  "The exposed bat has tan wood grain and dark printed markings.",
  "Dark background and a gray-green vertical support surround the left portion of the bat."
 ],
 "target_object": "The baseball bat",
 "target_region": "The exposed wooden bat between the left image edge and the cat's paws",
 "editing_intent": "Shorten the bat by bringing its left barrel end inward, while keeping the grip and the cat unchanged.",
 "editing_plan": [
  "Identify the exposed wooden bat with a position-constrained color mask.",
  "Remove its original silhouette and reconstruct the background using nearby source texture, inpainting, and feathered blending.",
  "Compress the original bat along its length, anchored beside the cat's paws.",
  "Shape a rounded barrel end and texture it with clean wood sampled from the original bat.",
  "Blend the shortened bat into the repaired background while preserving the cat, chair, mouse, and captions."
 ],
 "preservation_constraints": [
  "Keep the cat and both paws unchanged.",
  "Keep the handle and knob beside the cat unchanged.",
  "Preserve the mouse, chair, captions, and image borders.",
  "Retain the bat's diagonal orientation, wood appearance, and original printed markings where possible."
 ]
}
pixel code
def edit(image):
    import cv2
    import numpy as np
    from PIL import Image

    rgb = np.asarray(image.convert('RGB')).copy()
    h, w = rgb.shape[:2]
    sx, sy = w / 512.0, h / 512.0
    yy, xx = np.mgrid[0:h, 0:w].astype(np.float32)
    end = min(w - 1, int(round(0.654 * w)))

    # Locate the beige wood only inside the exposed diagonal shaft.
    r, g, b = [rgb[:, :, i].astype(np.float32) for i in range(3)]
    warm = (r > 82) & (r - g > 5) & (g - b > 7) & (r - b > 20)
    upper = np.zeros(end + 1, np.float32)
    lower = np.zeros(end + 1, np.float32)
    for x in range(end + 1):
        f = x / max(end, 1)
        top = (0.302 + 0.140 * f) * h
        bottom = (0.397 + 0.080 * f) * h
        a = max(0, int(top - 5 * sy))
        z = min(h, int(bottom + 5 * sy) + 1)
        hits = np.flatnonzero(warm[a:z, x])
        if len(hits) >= max(3, int(4 * sy)):
            upper[x] = max(top - 5 * sy, a + hits[0] - 0.7 * sy)
            lower[x] = min(bottom + 5 * sy, a + hits[-1] + 0.7 * sy)
        else:
            upper[x], lower[x] = top, bottom
    k = max(3, int(round(5 * sx)) | 1)
    upper = cv2.GaussianBlur(upper.reshape(1, -1), (k, 1), 0).ravel()
    lower = cv2.GaussianBlur(lower.reshape(1, -1), (k, 1), 0).ravel()
    object_mask = np.zeros((h, w), np.uint8)
    for x in range(end + 1):
        a = max(0, int(np.floor(upper[x])))
        z = min(h, int(np.ceil(lower[x])) + 1)
        object_mask[a:z, x] = 255

    # Repair the former bat location, including its narrow dark edge.
    radius = max(1, int(round(2 * min(sx, sy))))
    kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2 * radius + 1, 2 * radius + 1))
    removal = cv2.dilate(object_mask, kernel)
    removal[:, end + 1:] = 0  # Do not disturb the cat or its grip.
    filled = cv2.inpaint(rgb, removal, max(2, int(round(4 * min(sx, sy)))), cv2.INPAINT_TELEA)

    # Copy undisturbed texture from just above the bat. A small horizontal
    # compensation follows the slight slant of the left support.
    support_weight = np.clip((0.145 * w - xx) / (0.060 * w), 0, 1)
    donor_x = xx - 0.010 * w * support_weight
    donor_y = yy - 0.130 * h
    patch = cv2.remap(rgb, donor_x.astype(np.float32), donor_y.astype(np.float32),
                      cv2.INTER_LINEAR, borderMode=cv2.BORDER_REFLECT_101)
    replacement = 0.96 * patch.astype(np.float32) + 0.04 * filled.astype(np.float32)
    feather = cv2.GaussianBlur(removal.astype(np.float32) / 255.0, (0, 0),
                              max(0.45, 0.65 * min(sx, sy)))
    feather[:, end + 1:] = 0
    background = rgb.astype(np.float32) * (1 - feather[..., None]) + replacement * feather[..., None]

    # Shorten only along the bat's axis; preserve its width and paw-side anchor.
    anchor = np.array([float(end), 0.460 * h], np.float32)
    axis = np.array([1.0, 0.169 * h / w], np.float32)
    axis /= np.linalg.norm(axis)
    normal = np.array([-axis[1], axis[0]], np.float32)
    length_scale = 0.60
    linear = np.eye(2, dtype=np.float32) + (length_scale - 1.0) * np.outer(axis, axis)
    translation = anchor - linear @ anchor
    transform = np.column_stack((linear, translation)).astype(np.float32)

    original_alpha = object_mask.astype(np.float32) / 255.0
    original_alpha = cv2.GaussianBlur(original_alpha, (0, 0), max(0.35, 0.40 * min(sx, sy)))
    premultiplied = rgb.astype(np.float32) * original_alpha[..., None]
    warped_alpha = cv2.warpAffine(original_alpha, transform, (w, h), flags=cv2.INTER_LINEAR)
    warped_color = cv2.warpAffine(premultiplied, transform, (w, h), flags=cv2.INTER_LINEAR)
    wood = warped_color / np.maximum(warped_alpha[..., None], 1e-5)

    dx, dy = xx - anchor[0], yy - anchor[1]
    along = dx * axis[0] + dy * axis[1]
    across = dx * normal[0] + dy * normal[1]
    start = -length_scale * anchor[0] / axis[0] + 0.011 * w
    cap_length = 0.028 * w
    half_width = 0.045 * h
    q = np.clip((along - start) / max(cap_length, 1), 0, 1)
    round_width = half_width * np.sqrt(np.maximum(0, 1 - (1 - q) ** 2))
    edge_softness = max(0.6, 0.75 * min(sx, sy))
    rounded = np.clip((round_width - np.abs(across)) / edge_softness + 0.5, 0, 1)
    rounded *= np.clip((along - start) / edge_softness, 0, 1)
    rounded = np.where(along >= start + cap_length, 1.0, rounded)
    warped_alpha *= rounded

    # Synthesize the newly visible rounded end from real, unprinted wood.
    texture_x = 0.463 * w + 0.025 * w * q
    texture_y = 0.350 * h + (0.169 * h / w) * texture_x + across * 0.53
    cap_texture = cv2.remap(rgb, texture_x.astype(np.float32), texture_y.astype(np.float32),
                           cv2.INTER_LINEAR, borderMode=cv2.BORDER_REFLECT_101).astype(np.float32)
    curvature = np.clip(np.abs(across) / max(half_width, 1), 0, 1)
    cap_shading = 1.015 - 0.10 * curvature ** 2 - 0.045 * (1 - q)
    cap_texture *= cap_shading[..., None]
    # Slight longitudinal end-grain modulation, with source texture retained.
    grain = 0.7 * np.sin(across * 1.4 / max(sy, 0.1) + q * 3.0)
    cap_texture += grain[..., None]
    cap_blend = np.clip((start + cap_length + 0.007 * w - along) / (0.009 * w), 0, 1)
    wood = wood * (1 - cap_blend[..., None]) + cap_texture * cap_blend[..., None]

    # Very subtle contact shading under the shortened silhouette.
    shortened_mask = np.clip(warped_alpha, 0, 1)
    shadow_transform = np.array([[1, 0, 0], [0, 1, 1.4 * sy]], np.float32)
    shadow = cv2.warpAffine(shortened_mask, shadow_transform, (w, h), flags=cv2.INTER_LINEAR)
    shadow = cv2.GaussianBlur(shadow, (0, 0), max(0.6, 1.0 * min(sx, sy)))
    shadow *= (1 - shortened_mask) * 0.11
    shadow[:, end + 1:] = 0
    background *= 1 - shadow[..., None]
    result = background * (1 - shortened_mask[..., None]) + wood * shortened_mask[..., None]

    # Exact preservation beyond the edited shaft, including paws and handle.
    result[:, end + 1:] = rgb[:, end + 1:]
    return Image.fromarray(np.clip(result, 0, 255).astype(np.uint8), 'RGB')
Put a cup of coffee on the desk.
magicbrush_train_172595_1 · add / insert · execution=passed
PASSinstr 5preserve 5quality 4
source
GPT-6.1-Sol output
MagicBrush target (reference only)

A cup of coffee was added on the desk in an appropriate location, with unrelated scene content preserved. The cup is reasonably integrated, though its lighting/shadow and perspective are slightly imperfect.

l1=0.0228 · gain=-0.0049 · mask_l1=0.0074 · preserve_l1=0.0327

reasoning / plan
{
 "visual_evidence": [
  "A gray desk fills the foreground and right side of the image.",
  "A large monitor stands behind the open right-hand portion of the desk.",
  "The keyboard and mouse occupy the left and central desk area.",
  "There is clear desk space to the right of the mouse."
 ],
 "target_object": "A new ceramic cup filled with coffee",
 "target_region": "The open gray desktop to the right of the mouse, in front of the large monitor",
 "editing_intent": "Add a realistically shaded coffee cup resting on the desk, with a visible coffee surface, handle, and contact shadow.",
 "editing_plan": [
  "Select a localized patch of the empty desktop without covering existing equipment.",
  "Render a soft directional cast shadow and a tighter contact shadow.",
  "Construct the cup handle and tapered ceramic body with curved silhouettes and cylindrical shading.",
  "Add the elliptical rim, shaded inner wall, dark coffee surface, and subtle reflections.",
  "Match the image texture with restrained noise and feather the rendered boundaries.",
  "Apply only the synthesized pixel differences, preserving the surrounding photograph."
 ],
 "preservation_constraints": [
  "Do not alter the monitor, laptop, keyboard, or mouse.",
  "Preserve the desk edges, chair, floor, and background objects.",
  "Keep all pixels outside the localized cup and shadow area unchanged.",
  "Keep the handle opening transparent so the original desk remains visible through it."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    w, h = image.size
    source = np.asarray(image.convert('RGB'), dtype=np.uint8)
    x0, y0 = int(0.700*w), int(0.490*h)
    x1, y1 = min(w, int(0.965*w)), min(h, int(0.735*h))
    patch = source[y0:y1, x0:x1].astype(np.float32)
    ph, pw = patch.shape[:2]
    scale = 3
    W, H = pw*scale, ph*scale
    base = cv2.resize(patch, (W, H), interpolation=cv2.INTER_CUBIC)
    canvas = base.copy()
    X, Y = np.meshgrid(
        (x0 + (np.arange(W, dtype=np.float32)+0.5)/scale)/w,
        (y0 + (np.arange(H, dtype=np.float32)+0.5)/scale)/h
    )
    rng = np.random.default_rng(184)
    grain = cv2.resize(rng.normal(0, 0.85, (ph, pw)).astype(np.float32),
                       (W, H), interpolation=cv2.INTER_LINEAR)
    fine = rng.normal(0, 0.18, (H, W)).astype(np.float32)
    texture = grain + fine

    def soften(mask, radius=0.35):
        return cv2.GaussianBlur(mask.astype(np.float32), (0, 0), radius*scale)

    def ellipse(cx, cy, rx, ry):
        return ((X-cx)/rx)**2 + ((Y-cy)/ry)**2

    def paint(color, alpha, textured=False):
        nonlocal canvas
        a = np.clip(alpha, 0, 1).astype(np.float32)[..., None]
        c = np.asarray(color, dtype=np.float32)
        if textured:
            c = c + texture[..., None]
        canvas = canvas*(1-a) + c*a

    # Soft shadow falls away from the upper-left illumination.
    dx, dy = X-0.830, Y-0.662
    angle = 0.24
    u = dx*np.cos(angle) + dy*np.sin(angle)
    v = -dx*np.sin(angle) + dy*np.cos(angle)
    broad = 0.235*np.exp(-2.0*((u/0.068)**2 + (v/0.022)**2))
    broad[broad < 0.0015] = 0
    paint([35, 41, 44], broad)
    contact = 0.37*np.exp(-2.0*ellipse(0.809, 0.653, 0.044, 0.010))
    contact[contact < 0.0015] = 0
    paint([29, 34, 36], contact)

    # The handle is behind the body; its hole leaves the desktop visible.
    ho = ellipse(0.864, 0.604, 0.028, 0.032)
    hi = ellipse(0.865, 0.604, 0.0175, 0.022)
    handle_mask = soften((ho <= 1) & (hi >= 1))
    hu = (X-0.864)/0.028
    hv = (Y-0.604)/0.032
    hl = 0.90 - 0.115*hu - 0.055*hv
    handle_color = np.stack([220*hl, 225*hl, 223*hl], axis=-1)
    handle_color += (9*np.exp(-((hu+0.45)/0.23)**2))[..., None]
    paint(handle_color, handle_mask, True)
    inner_edge = soften((ho <= 1) & (hi >= 1) & (hi < 1.25))
    paint([137, 151, 154], inner_edge*0.22)

    cx, cy, yb = 0.808, 0.554, 0.646
    rt, rb = 0.052, 0.0455
    t = np.clip((Y-cy)/(yb-cy), 0, 1)
    radius = rt*(1-t) + rb*t
    sides = (Y >= cy) & (Y <= yb) & (np.abs(X-cx) <= radius)
    top = ellipse(cx, cy, rt, 0.0185) <= 1
    bottom = ellipse(cx, yb, rb, 0.0125) <= 1
    body_binary = sides | top | bottom
    body_mask = soften(body_binary)
    q = np.clip((X-cx)/radius, -1, 1)
    cylindrical = np.sqrt(np.maximum(0, 1-q*q))
    light = 0.845 + 0.175*cylindrical - 0.105*q - 0.045*t
    body_color = np.stack([221*light, 226*light, 224*light], axis=-1)
    highlight = 10*np.exp(-((q+0.42)/0.24)**2)*(1-0.25*t)
    body_color += highlight[..., None]
    paint(body_color, body_mask, True)

    # A restrained curved base band makes the cup sit on the surface.
    foot_r = ellipse(cx, yb, rb, 0.0125)
    foot = soften(body_binary & (Y > yb+0.0028) & (foot_r > 0.52) & (foot_r < 1))
    paint([158, 170, 171], foot*0.19, True)

    # Ceramic rim with cool side shading and a warm reflected highlight.
    outer = ellipse(cx, cy, rt, 0.0185)
    rim_mask = soften(outer <= 1)
    rim_light = 0.975 - 0.12*np.clip((X-cx)/rt, -1, 1)
    rim_color = np.stack([227*rim_light, 232*rim_light, 225*rim_light], axis=-1)
    paint(rim_color, rim_mask, True)

    # Inner wall and coffee are separate, so the rim has visible thickness.
    inner = ellipse(cx, cy+0.0006, 0.0445, 0.0134)
    inner_mask = soften(inner <= 1, 0.27)
    inner_y = np.clip((Y-cy)/0.014, -1, 1)
    wall_light = 0.76 + 0.20*inner_y - 0.07*(X-cx)/rt
    wall_color = np.stack([105*wall_light, 94*wall_light, 76*wall_light], axis=-1)
    paint(wall_color, inner_mask, True)

    coffee_r = ellipse(cx, cy+0.0023, 0.0418, 0.0107)
    coffee_mask = soften(coffee_r <= 1, 0.25)
    coffee_y = np.clip((Y-(cy+0.0023))/0.0107, -1, 1)
    coffee_x = (X-cx)/0.0418
    coffee_light = 0.93 + 0.13*coffee_y - 0.06*coffee_x
    coffee_color = np.stack([61*coffee_light, 35*coffee_light, 20*coffee_light], axis=-1)
    reflection = np.exp(-2.0*ellipse(cx-0.017, cy-0.0005, 0.018, 0.0034))
    coffee_color += reflection[..., None]*np.array([36, 30, 20], dtype=np.float32)
    coffee_color += texture[..., None]*0.50
    paint(coffee_color, coffee_mask)
    meniscus = soften((coffee_r < 1) & (coffee_r > 0.83), 0.22)
    paint([27, 19, 13], meniscus*0.36)
    glint = np.exp(-2.0*ellipse(cx-0.021, cy-0.0012, 0.009, 0.0012))*coffee_mask
    paint([170, 157, 125], glint*0.22)

    # Highlight the front lip without leaving a hard vector outline.
    front_lip = soften((outer <= 1) & (outer > 0.81) & (Y > cy+0.007), 0.24)
    lip_light = np.clip(1-0.22*(X-cx)/rt, 0.75, 1.12)
    lip_color = np.stack([235*lip_light, 238*lip_light, 231*lip_light], axis=-1)
    paint(lip_color, front_lip*0.65, True)

    # Downsample only the edit delta, preserving original background pixels.
    delta = cv2.resize(canvas-base, (pw, ph), interpolation=cv2.INTER_AREA)
    output = source.copy()
    output[y0:y1, x0:x1] = np.clip(np.rint(patch+delta), 0, 255).astype(np.uint8)
    return Image.fromarray(output, 'RGB')
Put a yeti near the snowboard.
magicbrush_train_562620_2 · add / insert · execution=passed
PASSinstr 5preserve 5quality 3
source
GPT-6.1-Sol output
MagicBrush target (reference only)

A yeti has been added near the snowboard as requested, and the original mountain/snowboard scene is otherwise preserved. The yeti is recognizable and placed appropriately, though it looks somewhat artificial/cartoon-like and not fully integrated with the photo lighting and texture.

l1=0.0798 · gain=0.0001 · mask_l1=0.0045 · preserve_l1=0.1048

reasoning / plan
{
 "visual_evidence": [
  "A red snowboard with dark bindings stands upright near the center-left.",
  "Open snow-covered ground lies to the right of the snowboard.",
  "The scene has blue sky, distant mountains, and cool-toned shadows on the snow."
 ],
 "target_object": "A new white-furred yeti beside the snowboard",
 "target_region": "The open snowy slope to the right of the snowboard, with the yeti's feet near the lower-right foreground",
 "editing_intent": "Add an upright, shaggy yeti with dimensional anatomy, a visible face, textured white fur, and grounded shadows.",
 "editing_plan": [
  "Construct soft, curved masks for the yeti's legs, feet, arms, hands, torso, and head.",
  "Shade the anatomy with cool shadows and pale highlights matching the snowy scene.",
  "Render directional fur strands and irregular furry edges.",
  "Add a shaded face, recessed eyes, nose, and partially fur-covered mouth.",
  "Add soft cast and contact shadows beneath the feet.",
  "Downsample only the pixel changes and preserve the snowboard and surrounding scene."
 ],
 "preservation_constraints": [
  "Keep the snowboard, its bindings, and its existing colors unchanged.",
  "Preserve the mountain ridges and sky.",
  "Keep snow texture intact outside the yeti and its shadows.",
  "Do not add clothing, equipment, or other figures."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image, ImageDraw

    w, h = image.size
    original = np.asarray(image.convert('RGB'), dtype=np.float32)
    scale = 2
    W, H = w * scale, h * scale
    base = cv2.resize(original, (W, H), interpolation=cv2.INTER_CUBIC)
    canvas = base.copy()
    rng = np.random.default_rng(23841)
    yy, xx = np.mgrid[0:H, 0:W].astype(np.float32)
    X, Y = xx / W, yy / H

    def soft_mask(points):
        p = np.asarray(points, dtype=np.float32)
        curve = []
        n = len(p)
        for i in range(n):
            p0, p1, p2, p3 = p[(i-1) % n], p[i], p[(i+1) % n], p[(i+2) % n]
            for t in np.linspace(0, 1, 18, endpoint=False):
                q = 0.5 * ((2*p1) + (-p0+p2)*t + (2*p0-5*p1+4*p2-p3)*t*t + (-p0+3*p1-3*p2+p3)*t*t*t)
                curve.append((q[0]*W, q[1]*H))
        m = np.zeros((H, W), np.uint8)
        cv2.fillPoly(m, [np.rint(curve).astype(np.int32)], 255)
        return cv2.GaussianBlur(m.astype(np.float32)/255, (0, 0), max(0.45, W*0.00048))

    def ellipse(cx, cy, rx, ry, angle=0):
        c, s = np.cos(angle), np.sin(angle)
        dx, dy = X-cx, Y-cy
        q = ((c*dx+s*dy)/rx)**2 + ((-s*dx+c*dy)/ry)**2
        edge = max(0.012, 1.2/(W*max(rx, 0.001)))
        return np.clip((1-q)/edge + 0.5, 0, 1)

    noise = rng.normal(0, 1, (H, W)).astype(np.float32)
    coarse = rng.normal(0, 1, (max(5, H//26), max(5, W//26))).astype(np.float32)
    coarse = cv2.resize(coarse, (W, H), interpolation=cv2.INTER_CUBIC)
    fine = rng.normal(0, 1, (max(8, H//5), max(8, W//5))).astype(np.float32)
    fine = cv2.resize(fine, (W, H), interpolation=cv2.INTER_CUBIC)
    labels = np.zeros((H, W), np.uint8)
    silhouette = np.zeros((H, W), np.float32)

    sample = original[int(h*0.93):int(h*0.99), int(w*0.70):int(w*0.91)]
    snow = np.median(sample.reshape(-1, 3), axis=0) if sample.size else np.array([224, 230, 235])
    fur_color = np.clip(0.32*snow + 0.68*np.array([232, 233, 227]), 205, 242)

    def paint(mask, center, radii, color, label=0, strength=1, extra_shadow=None):
        nonlocal canvas, silhouette
        cx, cy = center
        rx, ry = radii
        nx = np.clip((X-cx)/rx, -1, 1)
        ny = np.clip((Y-cy)/ry, -1, 1)
        nz = np.sqrt(np.clip(1-0.70*nx*nx-0.52*ny*ny, 0, 1))
        light = 0.67 + 0.29*nz - 0.095*nx - 0.075*ny
        light += 0.016*coarse + 0.011*fine + 0.005*noise
        if extra_shadow is not None:
            light -= extra_shadow
        light = np.clip(light, 0.52, 1.08)
        rgb = np.asarray(color, dtype=np.float32)[None, None, :]*light[:, :, None]
        rgb[:, :, 2] += (1-light)*16
        rgb[:, :, 0] -= (1-light)*5
        a = np.clip(mask*strength, 0, 1)[:, :, None]
        canvas = canvas*(1-a) + np.clip(rgb, 0, 255)*a
        if label:
            labels[mask > 0.5] = label
            silhouette = np.maximum(silhouette, mask)

    # Broad blue-gray cast shadow and tighter foot contact shadows retain snow texture.
    dx, dy = X-0.858, Y-0.909
    u, v = dx+0.10*dy, dy-0.10*dx
    shadow = 0.24*np.exp(-2*((u/0.137)**2+(v/0.017)**2))
    shadow += 0.31*np.exp(-2*(((X-0.738)/0.039)**2+((Y-0.899)/0.006)**2))
    shadow += 0.30*np.exp(-2*(((X-0.857)/0.041)**2+((Y-0.905)/0.006)**2))
    shadow = np.clip(shadow, 0, 0.48)
    tint = canvas*np.array([0.63, 0.70, 0.79], dtype=np.float32)
    canvas = canvas*(1-shadow[:, :, None]) + tint*shadow[:, :, None]

    parts = [
        (1, [(0.732,0.751),(0.783,0.757),(0.785,0.805),(0.761,0.851),(0.762,0.882),(0.719,0.887),(0.716,0.852),(0.718,0.803)], (0.750,0.818),(0.041,0.083)),
        (2, [(0.799,0.758),(0.849,0.758),(0.858,0.807),(0.849,0.847),(0.876,0.887),(0.831,0.890),(0.809,0.855),(0.794,0.810)], (0.831,0.823),(0.041,0.082)),
        (3, [(0.714,0.603),(0.742,0.635),(0.720,0.683),(0.700,0.727),(0.692,0.781),(0.666,0.793),(0.647,0.775),(0.663,0.714),(0.677,0.658)], (0.695,0.704),(0.047,0.095)),
        (4, [(0.862,0.605),(0.896,0.623),(0.916,0.672),(0.926,0.726),(0.945,0.782),(0.930,0.805),(0.905,0.792),(0.893,0.744),(0.876,0.699),(0.850,0.659)], (0.904,0.711),(0.044,0.103)),
        (5, [(0.759,0.586),(0.806,0.591),(0.859,0.603),(0.888,0.630),(0.876,0.678),(0.859,0.718),(0.858,0.766),(0.831,0.791),(0.784,0.798),(0.737,0.781),(0.716,0.745),(0.709,0.696),(0.695,0.653),(0.714,0.614)], (0.794,0.683),(0.098,0.113)),
        (6, [(0.664,0.770),(0.690,0.776),(0.697,0.794),(0.689,0.812),(0.672,0.819),(0.653,0.808),(0.648,0.788)], (0.674,0.794),(0.027,0.029)),
        (7, [(0.914,0.779),(0.936,0.779),(0.948,0.797),(0.940,0.820),(0.920,0.827),(0.903,0.811),(0.904,0.790)], (0.926,0.801),(0.026,0.028)),
        (8, [(0.724,0.872),(0.754,0.875),(0.766,0.885),(0.778,0.894),(0.767,0.903),(0.731,0.905),(0.707,0.899),(0.707,0.887)], (0.742,0.889),(0.041,0.020)),
        (9, [(0.832,0.876),(0.860,0.876),(0.878,0.886),(0.894,0.901),(0.878,0.910),(0.843,0.908),(0.826,0.897)], (0.858,0.891),(0.039,0.022)),
        (10, [(0.751,0.488),(0.773,0.468),(0.803,0.463),(0.831,0.478),(0.848,0.507),(0.855,0.544),(0.849,0.575),(0.829,0.602),(0.798,0.619),(0.769,0.604),(0.746,0.579),(0.734,0.547),(0.737,0.515)], (0.795,0.538),(0.062,0.079))
    ]
    for ident, points, center, radii in parts:
        m = soft_mask(points)
        shade = None
        if ident == 5:
            shade = 0.13*np.exp(-(((X-0.797)/0.041)**2+((Y-0.610)/0.026)**2))
            shade += 0.065*np.exp(-(((X-0.849)/0.029)**2+((Y-0.693)/0.078)**2))
        paint(m, center, radii, fur_color, ident, extra_shadow=shade)

    # Thousands of tapered, curved strands break up the surface and outline.
    fur_image = Image.fromarray(np.uint8(np.clip(canvas, 0, 255)), 'RGB')
    draw = ImageDraw.Draw(fur_image)
    visible = np.argwhere(labels > 0)
    count = max(6500, int(w*h*0.051))
    picks = visible[rng.integers(0, len(visible), count)]
    for py, px in picks:
        ident = int(labels[py, px])
        x, y = px/W, py/H
        if ident == 10:
            vx, vy = (x-0.793)*12, (y-0.537)*14
            if y > 0.556:
                vy += 0.50
            elif y < 0.515:
                vy -= 0.30
        elif ident == 3:
            vx, vy = -0.23, 1.0
        elif ident == 4:
            vx, vy = 0.24, 1.0
        elif ident in (8, 9):
            vx, vy = 0.52, 0.48
        else:
            vx, vy = (x-0.794)*3.5, 1.0
        vx += rng.normal(0, 0.19)
        vy += rng.normal(0, 0.12)
        norm = max(0.01, np.hypot(vx, vy))
        vx, vy = vx/norm, vy/norm
        length = rng.uniform(0.0026, 0.0120)*W
        if ident == 10:
            length *= 0.75
        ex, ey = px+vx*length, py+vy*length
        bend = rng.normal(0, 0.16)*length
        mid = (px+vx*length*0.52-vy*bend, py+vy*length*0.52+vx*bend)
        local = canvas[py, px].copy()
        shift = rng.normal(3, 11)
        col = np.clip(local+shift+np.array([0, 0, -1]), 0, 255)
        width = max(1, int(round(W*rng.uniform(0.00055, 0.00115))))
        draw.line([(float(px),float(py)),mid,(float(ex),float(ey))], fill=tuple(np.uint8(col)), width=width)
        if rng.random() < 0.40:
            tip = np.clip(col+9, 0, 255)
            draw.line([mid,(float(ex),float(ey))], fill=tuple(np.uint8(tip)), width=1)
    canvas = np.asarray(fur_image, dtype=np.float32).copy()

    # Small, shaded bare facial areas surrounded by heavy white fur.
    face = soft_mask([(0.779,0.518),(0.795,0.522),(0.810,0.518),(0.827,0.533),(0.827,0.554),(0.819,0.577),(0.799,0.591),(0.780,0.582),(0.766,0.562),(0.765,0.539)])
    paint(face, (0.797,0.551), (0.034,0.043), [134,140,137])
    paint(ellipse(0.778,0.542,0.013,0.010), (0.778,0.541), (0.014,0.011), [72,80,82])
    paint(ellipse(0.813,0.542,0.013,0.010), (0.813,0.541), (0.014,0.011), [69,77,78])
    paint(ellipse(0.779,0.544,0.0054,0.0037), (0.778,0.543), (0.006,0.005), [90,73,52])
    paint(ellipse(0.812,0.544,0.0054,0.0037), (0.811,0.543), (0.006,0.005), [85,69,49])
    paint(ellipse(0.780,0.544,0.0021,0.0032), (0.780,0.544), (0.003,0.004), [24,28,29])
    paint(ellipse(0.812,0.544,0.0021,0.0032), (0.812,0.544), (0.003,0.004), [22,26,27])
    paint(ellipse(0.7785,0.5426,0.0009,0.0010), (0.7785,0.5426), (0.002,0.002), [208,219,221])
    paint(ellipse(0.8105,0.5426,0.0009,0.0010), (0.8105,0.5426), (0.002,0.002), [203,215,218])
    nose = soft_mask([(0.790,0.539),(0.801,0.539),(0.806,0.553),(0.814,0.565),(0.807,0.573),(0.790,0.574),(0.779,0.566),(0.787,0.554)])
    paint(nose, (0.795,0.556), (0.018,0.023), [119,126,122])
    paint(ellipse(0.786,0.568,0.0047,0.0026,-0.22), (0.786,0.568), (0.006,0.004), [40,48,49])
    paint(ellipse(0.807,0.568,0.0047,0.0026,0.22), (0.807,0.568), (0.006,0.004), [39,46,47])
    paint(ellipse(0.797,0.583,0.0155,0.0028), (0.797,0.583), (0.018,0.005), [62,65,62], strength=0.85)
    paint(ellipse(0.797,0.588,0.012,0.003), (0.797,0.587), (0.014,0.005), [143,145,134], strength=0.65)

    # Fur over the brow, temples, cheek edges and chin integrates the face.
    fur_image = Image.fromarray(np.uint8(np.clip(canvas,0,255)), 'RGB')
    draw = ImageDraw.Draw(fur_image)
    for side in (-1, 1):
        for i in range(145):
            t = rng.random()
            px = (0.796+side*(0.007+0.022*t))*W
            py = (0.528+0.004*t+rng.normal(0,0.0018))*H
            ex = px+side*rng.uniform(0.001,0.004)*W
            ey = py+rng.uniform(0.002,0.006)*H
            col = np.clip(fur_color*rng.uniform(0.80,1.015),0,255)
            draw.line([(px,py),(ex,ey)], fill=tuple(np.uint8(col)), width=max(1,int(W*0.0008)))
        for i in range(170):
            t = rng.random()
            px = (0.796+side*(0.028-0.012*t)+rng.normal(0,0.0015))*W
            py = (0.550+0.049*t)*H
            ex = px+side*rng.uniform(-0.004,0.002)*W
            ey = py+rng.uniform(0.004,0.010)*H
            col = np.clip(fur_color*rng.uniform(0.73,0.98),0,255)
            draw.line([(px,py),(ex,ey)], fill=tuple(np.uint8(col)), width=max(1,int(W*0.0008)))
    for i in range(110):
        px = (0.777+rng.random()*0.040)*W
        py = (0.594+rng.normal(0,0.003))*H
        ex = px+rng.normal(0,0.002)*W
        ey = py+rng.uniform(0.005,0.014)*H
        col = np.clip(fur_color*rng.uniform(0.78,1.00),0,255)
        draw.line([(px,py),(ex,ey)], fill=tuple(np.uint8(col)), width=max(1,int(W*0.0008)))
    canvas = np.asarray(fur_image, dtype=np.float32)

    # Apply only the synthesized pixel differences, preserving all untouched pixels.
    delta = cv2.resize(canvas-base, (w,h), interpolation=cv2.INTER_AREA)
    result = np.clip(original+delta,0,255).astype(np.uint8)
    return Image.fromarray(result, 'RGB')
Let the man have a mohawk haircut.
magicbrush_train_194600_1 · replace / change · execution=passed
PASSinstr 4preserve 5quality 3
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The edit adds dark hair on the man's otherwise shaved head, roughly resembling a mohawk with shaved sides. The rest of the scene is preserved well, but the hair shape looks somewhat like a flat artificial patch rather than a natural mohawk.

l1=0.0060 · gain=-0.0001 · mask_l1=0.0073 · preserve_l1=0.0056

reasoning / plan
{
 "visual_evidence": [
  "The man is near the center, with his head turned toward the left.",
  "His head has very short hair and a clearly visible scalp.",
  "The top of his head is around the upper third of the image."
 ],
 "target_object": "The man's hair and scalp",
 "target_region": "The small head above the dark shirt, including the crown and rear scalp",
 "editing_intent": "Give the man a short, textured dark mohawk with shaved sides.",
 "editing_plan": [
  "Mask the scalp while excluding the face, ear, and neck.",
  "Reduce the existing buzz-cut texture on the sides and reconstruct subtly shaded, grain-matched shaved skin.",
  "Build a narrow raised mohawk along the crown using an irregular silhouette and individual hair strands.",
  "Add a subtle root shadow and feather the new hair into the original photograph."
 ],
 "preservation_constraints": [
  "Preserve the face, ear, neck, and head position.",
  "Do not change the man's clothes, body, racket, or pose.",
  "Preserve the tennis court, net, buildings, and trees.",
  "Keep all edits localized to the scalp and the immediately adjacent hair silhouette."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image, ImageDraw

    w, h = image.size
    r = float(min(w, h))
    original = np.asarray(image.convert('RGB')).astype(np.float32)
    result = original.copy()
    rng = np.random.default_rng(31)
    ss = 4

    def polygon_mask(points):
        canvas = Image.new('L', (w * ss, h * ss), 0)
        draw = ImageDraw.Draw(canvas)
        draw.polygon([(int(round(x * ss)), int(round(y * ss))) for x, y in points], fill=255)
        return np.asarray(canvas.resize((w, h), Image.Resampling.LANCZOS)).astype(np.float32) / 255.0

    def normalized_polygon(points):
        return polygon_mask([(x * w, y * h) for x, y in points])

    scalp = normalized_polygon([
        (0.422, 0.316), (0.434, 0.304), (0.448, 0.300),
        (0.461, 0.306), (0.471, 0.321), (0.476, 0.342),
        (0.470, 0.352), (0.457, 0.349), (0.444, 0.338),
        (0.430, 0.340), (0.419, 0.328)
    ])
    exclusion = Image.new('L', (w * ss, h * ss), 0)
    ed = ImageDraw.Draw(exclusion)
    ed.ellipse((0.417 * w * ss, 0.331 * h * ss,
                0.438 * w * ss, 0.355 * h * ss), fill=255)
    exclusion = np.asarray(exclusion.resize((w, h), Image.Resampling.LANCZOS)).astype(np.float32) / 255.0
    scalp *= 1.0 - exclusion
    scalp = cv2.GaussianBlur(scalp, (0, 0), max(0.35, r * 0.0013))

    # Reconstruct the shaved sides from the existing head shading and nearby skin.
    x0, x1 = int(0.450 * w), max(int(0.469 * w), int(0.450 * w) + 1)
    y0, y1 = int(0.353 * h), max(int(0.367 * h), int(0.353 * h) + 1)
    skin_sample = original[y0:y1, x0:x1].reshape(-1, 3)
    skin_color = np.median(skin_sample, axis=0)
    smooth = cv2.GaussianBlur(original, (0, 0), max(0.6, r * 0.0023))
    shaved = 0.64 * smooth + 0.36 * skin_color
    fine_noise = rng.normal(0.0, 0.85, (h, w, 1)).astype(np.float32)
    shaved += fine_noise
    a = (scalp * 0.86)[..., None]
    result = result * (1.0 - a) + np.clip(shaved, 0, 255) * a

    # The central crest follows the visible front-to-back crown curve.
    def crest(t):
        t = np.asarray(t)
        x = (0.421 + 0.054 * t) * w
        y = (0.320 - 0.031 * np.sin(np.pi * t) + 0.019 * t) * h
        dx = np.full_like(t, 0.054 * w, dtype=float)
        dy = (-0.031 * np.pi * np.cos(np.pi * t) + 0.019) * h
        length = np.sqrt(dx * dx + dy * dy)
        return np.stack([x, y], axis=-1), np.stack([dy / length, -dx / length], axis=-1)

    t = np.linspace(0.0, 1.0, 145)
    roots, normals = crest(t)
    lengths = r * (0.007 + 0.009 * np.sin(np.pi * t) ** 0.65)
    lengths *= rng.uniform(0.83, 1.12, len(t))
    outer = roots + normals * lengths[:, None]
    inner = roots - normals * (r * 0.0030)
    hair_mask = polygon_mask(np.vstack([outer, inner[::-1]]))
    hair_mask = cv2.GaussianBlur(hair_mask, (0, 0), max(0.20, r * 0.00045))

    # A soft contact shadow remains confined to the shaved scalp.
    shadow_canvas = Image.new('L', (w * ss, h * ss), 0)
    sd = ImageDraw.Draw(shadow_canvas)
    shadow_points = roots - normals * (r * 0.0036)
    sd.line([(int(x * ss), int(y * ss)) for x, y in shadow_points],
            fill=255, width=max(1, int(r * 0.004 * ss)))
    shadow = np.asarray(shadow_canvas.resize((w, h), Image.Resampling.LANCZOS)).astype(np.float32) / 255.0
    shadow = cv2.GaussianBlur(shadow, (0, 0), max(0.45, r * 0.0015))
    shadow *= scalp * 0.19
    result *= 1.0 - shadow[..., None]

    yy, xx = np.mgrid[0:h, 0:w].astype(np.float32)
    light = np.clip((0.480 * w - xx) / (0.075 * w), 0, 1)
    grain = rng.normal(0, 2.1, (h, w)).astype(np.float32)
    hair = np.empty_like(result)
    for channel, base in enumerate((42.0, 39.0, 33.0)):
        hair[..., channel] = base + 10.0 * light + grain
    a = hair_mask[..., None]
    result = result * (1.0 - a) + np.clip(hair, 0, 255) * a

    # Fine, slightly curved strands keep the crest photographic rather than flat.
    strands = Image.new('RGBA', (w * ss, h * ss), (0, 0, 0, 0))
    hd = ImageDraw.Draw(strands)
    for i in range(155):
        ti = float(rng.uniform(0.018, 0.984))
        p, n = crest(np.array([ti]))
        p, n = p[0], n[0]
        length = float(np.interp(ti, t, lengths)) * rng.uniform(0.62, 1.0)
        tangent = np.array([-n[1], n[0]])
        start = p - n * r * rng.uniform(0.0008, 0.0025)
        bend = tangent * r * rng.uniform(-0.0025, 0.0025)
        mid = p + n * length * 0.48 + bend * 0.4
        end = p + n * length + bend
        bright = rng.uniform(0, 1)
        color = (int(44 + 35 * bright), int(40 + 31 * bright),
                 int(33 + 25 * bright), int(rng.uniform(65, 145)))
        pts = [(int(round(q[0] * ss)), int(round(q[1] * ss))) for q in (start, mid, end)]
        hd.line(pts, fill=color, width=max(1, int(round(r * rng.uniform(0.00055, 0.00105) * ss))))
    strand_arr = np.asarray(strands.resize((w, h), Image.Resampling.LANCZOS)).astype(np.float32)
    strand_alpha = strand_arr[..., 3:4] / 255.0 * hair_mask[..., None]
    result = result * (1.0 - strand_alpha) + strand_arr[..., :3] * strand_alpha
    return Image.fromarray(np.clip(result, 0, 255).astype(np.uint8), 'RGB')
Make a woman stand on the chair by the desk.
magicbrush_train_172595_3 · replace / change · execution=passed
PASSinstr 5preserve 5quality 3
source
GPT-6.1-Sol output
MagicBrush target (reference only)

A woman has been added standing on the chair next to the desk, matching the requested local edit. The rest of the office scene is largely unchanged. The added figure is cartoon-like and not fully photorealistic with the source image, but placement and overall composition are acceptable.

l1=0.0873 · gain=0.0019 · mask_l1=0.0015 · preserve_l1=0.1215

reasoning / plan
{
 "visual_evidence": [
  "A purple office chair occupies the lower-left foreground.",
  "The chair has a broad visible seat beside the desk.",
  "The desk holds a laptop, a large monitor, a keyboard, a mouse, and a light-colored cup.",
  "No person is currently standing on the chair."
 ],
 "target_object": "A new woman standing on the purple chair",
 "target_region": "The left foreground, with both feet on the purple seat and her body extending upward beside the desk",
 "editing_intent": "Add a realistically shaded, clothed woman standing upright on the chair, with convincing foot contact and shadows.",
 "editing_plan": [
  "Locate the visible seat and position two feet securely within its surface.",
  "Add soft cast shadows and darker contact shadows beneath the feet.",
  "Construct the woman using smoothly curved, overlapping masks for shoes, trousers, blouse, arms, neck, face, and hair.",
  "Add directional shading, fabric texture, folds, facial details, and individual hair strands.",
  "Apply scene-matched grain and antialias the silhouette.",
  "Preserve the original scene outside the woman's silhouette and chair contact shadows."
 ],
 "preservation_constraints": [
  "Keep the original camera viewpoint and image dimensions.",
  "Preserve the desk, computer equipment, cup, floor, and background except where naturally occluded by the woman.",
  "Retain the chair's purple upholstery and structure outside the feet and shadows.",
  "Do not move or remove existing objects."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    w, h = image.size
    scale = 3
    W, H = w * scale, h * scale
    original = np.asarray(image.convert('RGB'), dtype=np.uint8)
    canvas = cv2.resize(original, (W, H), interpolation=cv2.INTER_CUBIC).astype(np.float32)
    rng = np.random.default_rng(29)
    fine = rng.normal(0, 1, (H, W)).astype(np.float32)
    coarse = rng.normal(0, 1, (max(4, h // 4), max(4, w // 4))).astype(np.float32)
    coarse = cv2.resize(coarse, (W, H), interpolation=cv2.INTER_CUBIC)
    residual = original.astype(np.float32) - cv2.GaussianBlur(original.astype(np.float32), (0, 0), 1.1)
    sample = residual[int(h * .81):int(h * .97), int(w * .03):int(w * .19)]
    grain = float(np.clip(np.std(sample) * .35, 1.0, 2.5))

    def smooth_points(points, closed=True):
        p = np.asarray(points, dtype=np.float32)
        out = []
        n = len(p)
        count = n if closed else n - 1
        for i in range(count):
            p0 = p[(i - 1) % n] if closed else p[max(0, i - 1)]
            p1 = p[i]
            p2 = p[(i + 1) % n]
            p3 = p[(i + 2) % n] if closed else p[min(n - 1, i + 2)]
            for t in np.linspace(0, 1, 14, endpoint=False):
                q = .5 * ((2 * p1) + (-p0 + p2) * t + (2*p0 - 5*p1 + 4*p2 - p3) * t*t + (-p0 + 3*p1 - 3*p2 + p3) * t*t*t)
                out.append(q)
        if not closed:
            out.append(p[-1])
        return np.round(np.asarray(out) * np.array([W, H])).astype(np.int32)

    def contour(points):
        m = np.zeros((H, W), dtype=np.uint8)
        cv2.fillPoly(m, [smooth_points(points)], 255, lineType=cv2.LINE_AA)
        return m

    def ellipse(cx, cy, rx, ry, angle=0):
        m = np.zeros((H, W), dtype=np.uint8)
        cv2.ellipse(m, (int(cx*W), int(cy*H)), (max(1, int(rx*W)), max(1, int(ry*H))), angle, 0, 360, 255, -1, cv2.LINE_AA)
        return m

    def paint(mask, color, opacity=1.0, bumps=(), texture=1.0, sculpt=True):
        nonzero = cv2.findNonZero(mask)
        if nonzero is None:
            return
        x, y, bw, bh = cv2.boundingRect(nonzero)
        pad = max(2, int(scale * 2))
        x0, y0 = max(0, x-pad), max(0, y-pad)
        x1, y1 = min(W, x+bw+pad), min(H, y+bh+pad)
        raw = mask[y0:y1, x0:x1]
        a = cv2.GaussianBlur(raw.astype(np.float32)/255, (0, 0), .28*scale)
        yy, xx = np.mgrid[y0:y1, x0:x1].astype(np.float32)
        if sculpt:
            d = cv2.distanceTransform((raw > 100).astype(np.uint8), cv2.DIST_L2, 3)
            ridge = np.clip(d / max(2., min(bw, bh)*.18), 0, 1)
            side = np.clip((xx-x)/max(1, bw), 0, 1)
            top = np.clip((yy-y)/max(1, bh), 0, 1)
            shade = .78 + .17*side + .13*ridge - .045*top
        else:
            shade = np.ones_like(xx)
        extra = np.zeros_like(xx)
        for cx, cy, rx, ry, amount in bumps:
            extra += amount * np.exp(-.5*((xx/W-cx)/rx)**2 - .5*((yy/H-cy)/ry)**2)
        noise = texture * (fine[y0:y1, x0:x1]*grain + coarse[y0:y1, x0:x1]*1.5)
        rgb = np.asarray(color, dtype=np.float32)[None, None, :] * shade[..., None]
        rgb = rgb + extra[..., None] + noise[..., None]
        a = (a * opacity)[..., None]
        canvas[y0:y1, x0:x1] = canvas[y0:y1, x0:x1]*(1-a) + np.clip(rgb, 0, 255)*a

    def shape(points, color, **kwargs):
        paint(contour(points), color, **kwargs)

    def oval(cx, cy, rx, ry, color, angle=0, **kwargs):
        paint(ellipse(cx, cy, rx, ry, angle), color, **kwargs)

    def line(points, color, width=.0012, opacity=.6):
        m = np.zeros((H, W), dtype=np.uint8)
        p = smooth_points(points, False)
        cv2.polylines(m, [p], False, 255, max(1, int(width*W)), cv2.LINE_AA)
        paint(m, color, opacity=opacity, texture=.35, sculpt=False)

    def shadow(cx, cy, rx, ry, strength, blur, angle=0):
        m = ellipse(cx, cy, rx, ry, angle).astype(np.float32)/255
        m = cv2.GaussianBlur(m, (0, 0), max(.5, blur*W))
        canvas[:] *= 1-strength*m[..., None]

    # Cast and contact shadows remain on the visible purple seat.
    shadow(.112, .663, .092, .028, .21, .011, -8)
    shadow(.106, .645, .062, .012, .24, .004, -8)
    shadow(.096, .650, .027, .006, .38, .0018)
    shadow(.169, .634, .030, .006, .35, .0018)

    # Hair behind the neck and clothing.
    shape([(.079,.163),(.087,.138),(.110,.125),(.137,.129),(.153,.146),(.158,.186),(.163,.225),(.151,.261),(.127,.272),(.091,.257),(.073,.224)], (48,32,28), bumps=[(.143,.174,.014,.04,18),(.101,.148,.014,.015,11)])

    # Far arm, with sleeve and exposed wrist.
    shape([(.160,.253),(.180,.259),(.197,.290),(.211,.323),(.217,.363),(.208,.393),(.189,.391),(.185,.359),(.174,.330),(.157,.296)], (111,54,66), bumps=[(.198,.318,.012,.055,17)])
    shape([(.190,.375),(.208,.376),(.214,.403),(.214,.419),(.207,.430),(.196,.427),(.189,.416),(.186,.403)], (184,132,105), bumps=[(.205,.403,.008,.015,18)])
    line([(.195,.405),(.197,.420),(.201,.426)], (112,75,64), .0011, .6)
    line([(.201,.405),(.204,.420),(.206,.426)], (122,82,70), .0008, .55)
    line([(.208,.402),(.211,.414),(.209,.423)], (126,87,71), .0008, .5)
    oval(.190,.404,.003,.010,(198,145,116),angle=-18,texture=.65)

    # Trouser hips and two separately shaded legs.
    shape([(.085,.397),(.117,.391),(.159,.397),(.178,.419),(.174,.449),(.151,.471),(.113,.460),(.084,.438)], (46,50,58), bumps=[(.150,.422,.016,.026,10)])
    shape([(.091,.427),(.122,.428),(.131,.467),(.119,.501),(.116,.548),(.115,.592),(.119,.623),(.111,.635),(.086,.632),(.083,.606),(.082,.559),(.081,.514),(.078,.471)], (46,51,61), bumps=[(.104,.503,.009,.06,13),(.100,.596,.013,.025,6),(.081,.476,.007,.03,-12)])
    shape([(.134,.430),(.167,.426),(.174,.462),(.173,.500),(.169,.546),(.173,.584),(.178,.611),(.168,.620),(.146,.618),(.139,.585),(.137,.547),(.135,.511),(.126,.472)], (43,48,58), bumps=[(.158,.503,.010,.069,13),(.161,.582,.013,.021,8),(.135,.472,.008,.028,-9)])
    line([(.096,.451),(.092,.506),(.096,.558),(.095,.619)], (79,83,89), .0010, .5)
    line([(.162,.449),(.165,.498),(.158,.555),(.164,.607)], (81,84,89), .0010, .46)
    line([(.090,.516),(.106,.521),(.116,.518)], (26,29,37), .0017, .65)
    line([(.139,.511),(.155,.516),(.169,.512)], (24,29,37), .0015, .58)
    line([(.086,.587),(.103,.592),(.115,.589)], (25,29,36), .0015, .62)
    line([(.141,.585),(.155,.590),(.169,.585)], (24,28,34), .0014, .56)
    line([(.086,.623),(.101,.627),(.115,.624)], (96,95,94), .0012, .52)
    line([(.146,.612),(.161,.615),(.174,.612)], (91,92,94), .0011, .48)

    # Shoes lie on the seat, rather than floating above it.
    shape([(.144,.611),(.167,.610),(.181,.615),(.192,.624),(.198,.633),(.191,.640),(.161,.641),(.140,.635)], (36,32,32), bumps=[(.177,.622,.016,.006,20)], texture=.75)
    shape([(.085,.624),(.109,.624),(.121,.635),(.128,.646),(.120,.654),(.090,.658),(.071,.653),(.071,.643)], (35,31,31), bumps=[(.102,.638,.014,.007,22)], texture=.75)
    line([(.073,.651),(.092,.655),(.113,.653),(.125,.648)], (12,13,15), .0028, .88)
    line([(.142,.635),(.161,.640),(.184,.639),(.196,.635)], (12,13,15), .0026, .85)
    line([(.087,.635),(.099,.637),(.111,.634)], (105,92,85), .0010, .6)
    line([(.151,.619),(.164,.622),(.176,.620)], (98,86,82), .0009, .6)

    # Near arm and blouse, in softly textured burgundy fabric.
    shape([(.081,.248),(.061,.255),(.049,.284),(.040,.319),(.035,.357),(.039,.393),(.054,.404),(.066,.394),(.063,.355),(.069,.322),(.088,.280)], (121,58,70), bumps=[(.050,.331,.009,.045,16),(.039,.369,.006,.02,-8)])
    shape([(.095,.241),(.112,.234),(.137,.235),(.165,.249),(.176,.280),(.163,.330),(.162,.372),(.176,.408),(.169,.425),(.141,.430),(.112,.427),(.081,.432),(.080,.405),(.083,.367),(.073,.323),(.068,.276)], (125,60,74), bumps=[(.143,.285,.025,.03,22),(.130,.350,.021,.05,12),(.080,.318,.009,.028,-18),(.159,.386,.009,.026,-13)])
    line([(.090,.269),(.105,.286),(.123,.291),(.147,.276)], (81,36,47), .0021, .6)
    line([(.087,.297),(.103,.321),(.119,.329)], (91,39,52), .0023, .5)
    line([(.150,.301),(.145,.325),(.134,.342)], (165,84,93), .0017, .52)
    line([(.089,.358),(.110,.375),(.137,.380),(.160,.369)], (79,37,47), .0020, .58)
    line([(.086,.389),(.104,.394),(.119,.407),(.146,.406)], (173,88,99), .0015, .48)
    line([(.091,.411),(.119,.416),(.144,.413),(.165,.418)], (68,32,42), .0022, .66)
    line([(.046,.338),(.056,.346),(.064,.345)], (75,35,45), .0017, .62)
    line([(.189,.339),(.199,.346),(.212,.344)], (69,32,41), .0015, .6)
    line([(.039,.387),(.050,.392),(.062,.389)], (168,79,90), .0011, .58)

    # Near hand with subtle separation of fingers.
    shape([(.040,.389),(.057,.391),(.060,.411),(.057,.431),(.049,.449),(.042,.450),(.035,.438),(.032,.418)], (190,136,110), bumps=[(.050,.415,.008,.015,20),(.035,.430,.004,.012,-10)])
    oval(.059,.412,.0045,.013,(183,126,102),angle=15,texture=.65)
    line([(.039,.423),(.040,.438),(.044,.447)], (116,77,66), .0009, .6)
    line([(.045,.425),(.046,.439),(.049,.446)], (122,80,68), .0008, .58)
    line([(.051,.426),(.052,.438),(.054,.442)], (126,83,69), .0008, .5)

    # Neck, neckline and face turned slightly toward the desk.
    shape([(.105,.213),(.132,.211),(.136,.232),(.148,.244),(.134,.259),(.115,.261),(.096,.246),(.105,.233)], (181,126,100), bumps=[(.128,.237,.009,.014,22),(.109,.224,.008,.010,-15)], texture=.7)
    line([(.094,.246),(.109,.262),(.127,.266),(.145,.249)], (75,34,45), .0025, .8)
    line([(.095,.250),(.110,.267),(.129,.269),(.147,.252)], (159,76,89), .0010, .6)
    shape([(.100,.150),(.124,.145),(.141,.156),(.148,.177),(.146,.189),(.154,.198),(.147,.205),(.144,.220),(.133,.233),(.116,.232),(.099,.218),(.091,.197),(.091,.173)], (188,139,113), bumps=[(.132,.170,.013,.018,23),(.135,.205,.010,.010,22),(.104,.199,.006,.022,-17),(.119,.227,.011,.006,-13),(.142,.185,.004,.012,13)], texture=.7)
    oval(.096,.193,.0065,.012,(173,117,94),angle=-9,bumps=[(.096,.189,.003,.006,12)],texture=.65)
    line([(.097,.187),(.094,.193),(.098,.198)], (125,77,66), .0010, .54)
    oval(.127,.210,.010,.006,(195,129,109),opacity=.25,sculpt=False,texture=.4)

    # Small, low-contrast eyes, brows, nose and lips avoid hard outlines.
    line([(.108,.181),(.115,.178),(.123,.180)], (70,46,39), .0016, .83)
    line([(.131,.179),(.138,.177),(.143,.180)], (67,44,37), .0013, .78)
    oval(.116,.187,.0067,.0025,(203,185,161),angle=-4,texture=.3,sculpt=False)
    oval(.138,.185,.0048,.0022,(207,185,159),angle=3,texture=.3,sculpt=False)
    oval(.118,.187,.0022,.0027,(64,55,45),texture=.2,sculpt=False)
    oval(.139,.185,.0018,.0024,(65,53,43),texture=.2,sculpt=False)
    oval(.1187,.1862,.0007,.0007,(229,218,197),texture=0,sculpt=False)
    line([(.109,.185),(.116,.184),(.123,.185)], (83,54,44), .0009, .78)
    line([(.133,.183),(.138,.182),(.143,.184)], (83,53,43), .0008, .74)
    line([(.133,.189),(.135,.199),(.142,.202)], (147,98,78), .0010, .54)
    oval(.143,.201,.0027,.0014,(123,76,61),opacity=.65,sculpt=False,texture=.3)
    line([(.129,.213),(.136,.211),(.143,.212)], (125,65,61), .0014, .8)
    line([(.130,.214),(.136,.216),(.141,.214)], (193,114,106), .0015, .65)
    line([(.130,.212),(.136,.213),(.142,.212)], (97,54,49), .0007, .58)
    oval(.131,.222,.007,.002,(210,161,130),opacity=.38,texture=.3,sculpt=False)

    # Swept hair frames the face, with strands following the volume.
    shape([(.077,.173),(.082,.145),(.100,.128),(.125,.127),(.146,.138),(.155,.153),(.151,.173),(.140,.164),(.125,.154),(.111,.160),(.101,.177),(.097,.204),(.091,.232),(.080,.240),(.078,.214)], (47,31,27), bumps=[(.111,.140,.022,.009,21),(.084,.181,.006,.025,11)], texture=.9)
    shape([(.140,.153),(.153,.158),(.155,.186),(.158,.213),(.151,.248),(.138,.255),(.142,.228),(.147,.205),(.145,.181)], (53,34,28), bumps=[(.151,.197,.004,.036,16)], texture=.8)
    for i in range(13):
        q = i / 12.0
        line([(.091+.012*q,.150-.009*q),(.106+.019*q,.135+.005*q),(.127+.017*q,.138+.010*q),(.144+.008*q,.154+.012*q)], (87+int(13*q),57+int(8*q),39+int(6*q)), .00065, .30)
    for i in range(10):
        q = i/9.0
        line([(.087+.010*q,.165),(.084+.010*q,.186),(.085+.009*q,.214),(.081+.009*q,.235)], (86,54,37), .00065, .27)
    for i in range(7):
        q = i/6.0
        line([(.149+.004*q,.171),(.152+.004*q,.195),(.150+.004*q,.218),(.142+.007*q,.246)], (94,60,40), .00065, .32)
    line([(.103,.158),(.113,.148),(.129,.149),(.142,.159)], (127,83,52), .0008, .32)

    # A few softly shaded blouse buttons and front stitching.
    line([(.127,.273),(.126,.319),(.129,.366),(.131,.410)], (87,41,54), .0009, .42)
    for cy in [.289,.324,.358,.394]:
        oval(.128,cy,.0018,.0019,(86,45,53),texture=.35)
        oval(.1287,cy-.0006,.0007,.0006,(170,115,118),opacity=.65,sculpt=False,texture=.15)

    result = np.clip(canvas, 0, 255).astype(np.uint8)
    result = cv2.resize(result, (w, h), interpolation=cv2.INTER_AREA)
    return Image.fromarray(result, 'RGB')
let the child have curly blonde hair
magicbrush_train_451690_3 · replace / change · execution=passed
FAILinstr 3preserve 4quality 2
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The edit targets the child's hair and makes it blonde and curly, but it appears as an artificial patterned cap rather than natural hair, with poor blending and unrealistic texture. Most unrelated scene content is preserved.

l1=0.0197 · gain=0.0008 · mask_l1=0.0018 · preserve_l1=0.0231

reasoning / plan
{
 "visual_evidence": [
  "The child is centered in the image with their head tilted downward.",
  "The visible hair is dark brown, mostly straight, and falls across the forehead.",
  "The crown and sides of the hair are clearly visible above the child's face."
 ],
 "target_object": "The child's hair",
 "target_region": "The crown, sides, and existing fringe of the child's head in the upper-center of the image",
 "editing_intent": "Replace the dark, straight hairstyle with naturally shaded curly blonde hair.",
 "editing_plan": [
  "Trace the visible hair silhouette and protect the lighter forehead along the fringe.",
  "Create a blonde foundation using the original hair's lighting and tonal variation.",
  "Synthesize overlapping, irregular curls with shaded ribbons and fine individual strands.",
  "Add small curls along the crown and side silhouette for natural volume.",
  "Feather the hair boundary, match image noise, and preserve all pixels outside the hair region."
 ],
 "preservation_constraints": [
  "Keep the child's face, skin, expression, and head position unchanged.",
  "Keep the clothing, hands, legs, toys, floor, furniture, and boxes unchanged.",
  "Retain the image dimensions and existing scene lighting."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    image = image.convert('RGB')
    w, h = image.size
    source = np.asarray(image).astype(np.float32)
    rng = np.random.default_rng(417)
    unit = min(w, h)
    yy, xx = np.mgrid[0:h, 0:w]
    xn, yn = xx / float(w), yy / float(h)
    gray = cv2.cvtColor(source.astype(np.uint8), cv2.COLOR_RGB2GRAY).astype(np.float32)

    outline = np.array([
        (.343,.349), (.333,.309), (.327,.258), (.332,.210),
        (.347,.163), (.370,.119), (.398,.086), (.437,.062),
        (.481,.049), (.523,.047), (.568,.057), (.609,.079),
        (.639,.112), (.660,.157), (.676,.205), (.679,.249),
        (.671,.290), (.653,.329), (.633,.353), (.619,.371),
        (.602,.395), (.588,.408), (.575,.405), (.582,.379),
        (.590,.355), (.578,.340), (.566,.361), (.551,.382),
        (.532,.395), (.510,.407), (.486,.415), (.463,.409),
        (.446,.403), (.423,.408), (.400,.407), (.381,.394),
        (.365,.378)
    ], dtype=np.float32)
    poly = np.rint(outline * np.array([w, h])).astype(np.int32)
    original_mask = np.zeros((h, w), np.uint8)
    cv2.fillPoly(original_mask, [poly], 255)
    original_mask = original_mask.astype(np.float32) / 255.0

    # The bright forehead must not be recolored where the fringe separates.
    dark_hair = np.clip((139.0 - gray) / 27.0, 0.0, 1.0)
    lower = np.clip((yn - .351) / .018, 0.0, 1.0)
    original_mask *= 1.0 - lower + lower * dark_hair

    silhouette = original_mask.copy()
    edge_curls = [
        (.356,.176,.017,.023), (.382,.125,.020,.023),
        (.418,.084,.022,.022), (.463,.060,.021,.018),
        (.508,.053,.023,.018), (.555,.061,.021,.019),
        (.600,.085,.020,.023), (.637,.130,.019,.025),
        (.661,.182,.017,.025), (.673,.235,.015,.024),
        (.662,.281,.014,.022), (.342,.235,.015,.024),
        (.348,.287,.014,.023)
    ]
    for cx, cy, rx, ry in edge_curls:
        bump = np.zeros((h, w), np.uint8)
        cv2.ellipse(bump, (int(cx*w), int(cy*h)),
                    (max(1,int(rx*w)), max(1,int(ry*h))),
                    0, 0, 360, 255, -1, cv2.LINE_AA)
        silhouette = np.maximum(silhouette, bump.astype(np.float32)/255.0)

    # Preserve illumination while reducing the original straight-strand pattern.
    shade = cv2.GaussianBlur(gray, (0, 0), max(.001, .007*unit))
    t = np.clip((shade - 10.0) / 165.0, 0.0, 1.0)
    value = 57.0 + 151.0 * np.power(t, .58)
    illumination = 6.0 * np.exp(-((xn-.435)**2/.020 + (yn-.145)**2/.025))
    value += illumination
    blonde = np.stack([value*1.065+9.0, value*.905+6.0, value*.575+10.0], axis=-1)
    original_detail = gray - cv2.GaussianBlur(gray, (0, 0), max(.001, .0025*unit))
    blonde += original_detail[...,None] * .15
    blonde = np.clip(blonde, 0, 255)

    # Extrapolate actual hair shading into the small added curl silhouettes.
    sigma = max(1.0, .018*unit)
    weights = cv2.GaussianBlur(original_mask, (0,0), sigma)
    extrapolated = np.empty_like(blonde)
    for ch in range(3):
        numerator = cv2.GaussianBlur(blonde[...,ch]*original_mask, (0,0), sigma)
        extrapolated[...,ch] = numerator / np.maximum(weights, 1e-5)
    extrapolated = np.clip(extrapolated, 0, 255)
    foundation = blonde*original_mask[...,None] + extrapolated*(1-original_mask[...,None])

    # Supersampled curl rendering gives soft, subpixel filaments rather than outlines.
    ss = 3
    rw, rh = w*ss, h*ss
    canvas = cv2.resize(foundation.astype(np.uint8), (rw,rh), interpolation=cv2.INTER_CUBIC)
    coverage = np.zeros((rh,rw), np.uint8)

    def stroke(points, color, thickness, destination=canvas):
        p = np.rint(points*ss).astype(np.int32).reshape(-1,1,2)
        width = max(1, int(round(thickness*ss)))
        cv2.polylines(destination, [p], False, tuple(int(v) for v in color), width, cv2.LINE_AA)

    curls = []
    spacing_x, spacing_y = .026, .026
    for row, cy in enumerate(np.arange(.065, .405, spacing_y)):
        for cx in np.arange(.337, .685, spacing_x):
            cx = cx + (row % 2)*.011 + rng.uniform(-.008,.008)
            cyj = cy + rng.uniform(-.008,.008)
            ix, iy = int(cx*w), int(cyj*h)
            if 0 <= ix < w and 0 <= iy < h and silhouette[iy,ix] > .45:
                curls.append((cx,cyj,rng.uniform(.011,.022),rng.uniform(.013,.024)))
    curls += edge_curls
    # Draw far curls first and the forehead curls last.
    curls.sort(key=lambda item: item[1] + rng.uniform(-.009,.009))

    for cx, cy, rx, ry in curls:
        center = np.array([cx*w,cy*h],dtype=np.float32)
        ix = int(np.clip(cx*w,0,w-1))
        iy = int(np.clip(cy*h,0,h-1))
        local = foundation[iy,ix].astype(np.float32)
        local = .70*local + .30*np.array([185.,153.,91.])
        angle = rng.uniform(-np.pi,np.pi)
        phase = rng.uniform(-np.pi,np.pi)
        sweep = rng.uniform(1.30,2.40)*np.pi
        steps = 94
        u = np.linspace(0,1,steps)
        theta = phase + sweep*u
        radial = 1.0 - rng.uniform(.28,.52)*u
        radial *= 1.0 + .07*np.sin(3*theta+rng.uniform(0,6.28))
        px = rx*w*radial*np.cos(theta)
        py = ry*h*radial*np.sin(theta)
        ca, sa = np.cos(angle),np.sin(angle)
        points = center + np.stack([px*ca-py*sa, px*sa+py*ca],axis=1)
        tangent = np.gradient(points,axis=0)
        length = np.maximum(np.linalg.norm(tangent,axis=1),1e-5)
        normals = np.stack([-tangent[:,1]/length,tangent[:,0]/length],axis=1)
        width = rng.uniform(.0034,.0062)*unit
        shadow_points = points + np.array([.0013*w,.0017*h])
        stroke(shadow_points, np.clip(local*np.array([.48,.45,.40]),0,255), width*1.48)
        stroke(points, np.clip(local*.79,0,255), width)
        # Several filaments form a ribbon, with continuous curved highlight variation.
        for strand in range(9):
            offset = (strand/8.0-.5)*width*.78
            wander = .00036*unit*np.sin(4*theta+strand*.71)
            filament = points + normals*(offset+wander)[:,None]
            strand_gain = rng.uniform(.85,1.13)
            for k in range(0,steps-1,3):
                end = min(k+4,steps)
                light = .81 + .27*(.5+.5*np.cos(theta[k]+angle+2.15))
                light += .07*np.exp(-((strand/8.0-.35)/.19)**2)
                col = np.clip(local*light*strand_gain + np.array([3.,2.,0.]),0,255)
                stroke(filament[k:end],col,max(.0005*unit,.22))
        # A sparse bright glint, not a complete bright outline around each curl.
        if rng.random() < .67:
            k0 = int(rng.integers(7,40))
            k1 = min(steps,k0+int(rng.integers(15,31)))
            glint = points[k0:k1] + normals[k0:k1]*(-width*.16)
            stroke(glint,np.clip(local*1.20+np.array([7.,6.,3.]),0,255),.00075*unit)
        p = np.rint(points*ss).astype(np.int32).reshape(-1,1,2)
        cv2.polylines(coverage,[p],False,255,max(1,int(width*1.8*ss)),cv2.LINE_AA)

    rendered = cv2.resize(canvas,(w,h),interpolation=cv2.INTER_AREA).astype(np.float32)
    curl_coverage = cv2.resize(coverage,(w,h),interpolation=cv2.INTER_AREA).astype(np.float32)/255.0
    # Keep the shaded foundation between the curls; avoid uniform painted patches.
    mix = .91*curl_coverage
    textured = foundation*(1-mix[...,None]) + rendered*mix[...,None]
    fine_noise = rng.normal(0,1.20,(h,w,1)).astype(np.float32)
    chroma_noise = rng.normal(0,.38,(h,w,3)).astype(np.float32)
    textured = np.clip(textured+fine_noise+chroma_noise,0,255)

    feather = cv2.GaussianBlur(silhouette,(0,0),max(.35,.00125*unit))
    # Prevent feathering from changing the protected forehead and face.
    protection = 1.0-lower+lower*dark_hair
    feather *= np.where(yn>.351,protection,1.0).astype(np.float32)
    feather = np.clip(feather,0,1)
    result = source*(1-feather[...,None]) + textured*feather[...,None]
    return Image.fromarray(np.clip(result,0,255).astype(np.uint8), 'RGB')
let the child play with lego blocks
magicbrush_train_451690_1 · replace / change · execution=passed
PASSinstr 4preserve 4quality 3
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The child is now shown with LEGO-like blocks in their hands and additional blocks nearby, matching the requested edit. Most unrelated background and the child are preserved, though the original controllers are replaced/covered. The added blocks look somewhat artificial with imperfect perspective, lighting, and hand occlusion, but the edit is understandable.

l1=0.0266 · gain=0.0007 · mask_l1=0.0106 · preserve_l1=0.0300

reasoning / plan
{
 "visual_evidence": [
  "The child is seated on a carpet.",
  "The child holds a light-colored remote control in each hand.",
  "The child's fingers overlap the controls.",
  "There is exposed carpet beside the child's jeans."
 ],
 "target_object": "The two remote controls and a small area of adjacent carpet",
 "target_region": "Under the child's hands at the lower left and center right, with additional blocks on the lower-right carpet",
 "editing_intent": "Replace the remote controls with colorful, studded LEGO-style brick assemblies so the child appears to be playing with building blocks.",
 "editing_plan": [
  "Mask the remote controls while protecting the child's visible fingers.",
  "Inpaint the exposed portions of the controls and restore subtle image texture.",
  "Construct shaded, perspective-matched bricks with raised cylindrical studs in both hands.",
  "Add a few small loose bricks on the carpet, with soft contact shadows.",
  "Restore the original hands over the bricks and blend the rendered edges and grain."
 ],
 "preservation_constraints": [
  "Preserve the child's face, hair, expression, clothing, and seated pose.",
  "Preserve the original hands and fingers, allowing them to overlap the new bricks.",
  "Leave the furniture, boxes, and surrounding room unchanged.",
  "Retain the source image dimensions and photographic lighting."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    source = np.asarray(image.convert('RGB')).copy()
    w, h = image.size
    rng = np.random.default_rng(19)

    def original_mask(points):
        m = np.zeros((h, w), np.uint8)
        p = np.rint(np.asarray(points) * [w, h]).astype(np.int32)
        cv2.fillPoly(m, [p], 255)
        return m

    left_hand_region = original_mask([(0.071,0.823),(0.105,0.792),(0.143,0.802),(0.211,0.844),(0.194,0.872),(0.148,0.881),(0.126,0.897),(0.096,0.881),(0.073,0.858)])
    right_hand_region = original_mask([(0.683,0.648),(0.720,0.632),(0.752,0.641),(0.776,0.668),(0.787,0.714),(0.768,0.725),(0.744,0.704),(0.694,0.690)])
    hsv = cv2.cvtColor(source, cv2.COLOR_RGB2HSV)
    s = source.astype(np.int16)
    skin_test = ((hsv[:,:,0] < 27) & (hsv[:,:,1] > 31) & (hsv[:,:,2] > 65) & (s[:,:,0] > s[:,:,1] + 9) & (s[:,:,1] > s[:,:,2] + 5))
    hand_mask = ((skin_test & ((left_hand_region > 0) | (right_hand_region > 0))).astype(np.uint8) * 255)
    hand_mask = cv2.morphologyEx(hand_mask, cv2.MORPH_CLOSE, np.ones((3,3), np.uint8))

    left_remote = original_mask([(0.0,0.805),(0.026,0.809),(0.104,0.841),(0.150,0.854),(0.235,0.888),(0.246,0.906),(0.248,0.950),(0.235,0.968),(0.208,0.965),(0.0,0.892)])
    right_remote = original_mask([(0.598,0.669),(0.690,0.680),(0.761,0.685),(0.866,0.696),(0.879,0.709),(0.875,0.743),(0.867,0.758),(0.595,0.735),(0.591,0.712)])
    removal = cv2.bitwise_or(left_remote, right_remote)
    removal[hand_mask > 0] = 0
    base = cv2.inpaint(source, removal, max(3, int(min(w,h)*0.012)), cv2.INPAINT_TELEA).astype(np.float32)
    detail = source.astype(np.float32) - cv2.GaussianBlur(source.astype(np.float32), (0,0), max(0.7,min(w,h)*0.002))
    detail = np.roll(detail, (int(h*0.13), int(w*0.17)), axis=(0,1))
    detail = np.clip(detail, -5, 5)
    base += detail * (removal.astype(np.float32)/255.0)[:,:,None] * 0.55
    base = np.clip(base, 0, 255)

    scale = 3
    W, H = w*scale, h*scale
    canvas = cv2.resize(base, (W,H), interpolation=cv2.INTER_CUBIC)
    coverage = np.zeros((H,W), np.float32)
    solids = np.zeros((H,W), np.float32)

    def pixels(points):
        return np.rint(np.asarray(points, dtype=np.float32)*[W,H]).astype(np.int32)

    def paint(points, color, opacity=1.0, shade=1.0, textured=True):
        pts = pixels(points)
        x0 = max(0, int(pts[:,0].min())-2)
        y0 = max(0, int(pts[:,1].min())-2)
        x1 = min(W, int(pts[:,0].max())+3)
        y1 = min(H, int(pts[:,1].max())+3)
        if x1 <= x0 or y1 <= y0:
            return
        mask = np.zeros((y1-y0,x1-x0), np.uint8)
        cv2.fillPoly(mask, [pts-[x0,y0]], 255, lineType=cv2.LINE_AA)
        a = mask.astype(np.float32)/255.0*opacity
        yy,xx = np.mgrid[0:y1-y0,0:x1-x0].astype(np.float32)
        illumination = shade * (1.045 - 0.115*yy/max(1,y1-y0) - 0.022*xx/max(1,x1-x0))
        col = np.asarray(color,dtype=np.float32)[None,None,:]*illumination[:,:,None]
        if textured:
            noise = rng.normal(0,0.65,(y1-y0,x1-x0)).astype(np.float32)
            col = col + noise[:,:,None]
        col = np.clip(col,0,255)
        patch = canvas[y0:y1,x0:x1]
        patch[:] = patch*(1-a[:,:,None])+col*a[:,:,None]
        coverage[y0:y1,x0:x1] = np.maximum(coverage[y0:y1,x0:x1],a)
        solids[y0:y1,x0:x1] = np.maximum(solids[y0:y1,x0:x1],a)

    def shadow(poly, strength=0.25, offset=(0.007,0.010), blur=0.006):
        p = np.asarray(poly)+np.asarray(offset)
        m = np.zeros((H,W),np.uint8)
        cv2.fillPoly(m,[pixels(p)],255,lineType=cv2.LINE_AA)
        a = cv2.GaussianBlur(m.astype(np.float32)/255.0,(0,0),max(0.8,min(W,H)*blur))*strength
        canvas[:] *= (1-a[:,:,None])
        coverage[:] = np.maximum(coverage,np.clip(a*4,0,1))

    angles = np.linspace(0,2*np.pi,60,endpoint=False)

    def ellipse(center, axis_a, axis_b, color, opacity=1.0, shade=1.0):
        center = np.asarray(center)
        points = center + np.cos(angles)[:,None]*np.asarray(axis_a) + np.sin(angles)[:,None]*np.asarray(axis_b)
        paint(points,color,opacity,shade)
        return points

    def stud(center, a, b, dz, color):
        center = np.asarray(center)
        a,b,dz = np.asarray(a),np.asarray(b),np.asarray(dz)
        lower = center + np.cos(angles)[:,None]*a + np.sin(angles)[:,None]*b
        upper = lower-dz
        hull = cv2.convexHull(np.concatenate([lower,upper]).astype(np.float32)).reshape(-1,2)
        paint(hull, np.asarray(color)*0.76, shade=0.97)
        paint(lower, np.asarray(color)*0.72, opacity=0.30)
        paint(upper, color, shade=1.07)
        rim_center = center-dz
        inner = rim_center + np.cos(angles)[:,None]*a*0.87 + np.sin(angles)[:,None]*b*0.87
        paint(inner, color, opacity=0.72, shade=1.03)
        ellipse(rim_center-a*0.20-b*0.22, a*0.46,b*0.24,[255,247,225],opacity=0.13,shade=1.0)
        # A narrow curved reflection makes each stud read as molded plastic.
        t = np.linspace(np.pi*1.07,np.pi*1.80,22)
        outer = rim_center+np.cos(t)[:,None]*a*0.94+np.sin(t)[:,None]*b*0.94
        inner_arc = rim_center+np.cos(t[::-1])[:,None]*a*0.83+np.sin(t[::-1])[:,None]*b*0.83
        paint(np.concatenate([outer,inner_arc]),[255,250,234],opacity=0.24,textured=False)

    def brick(p,u,v,height,color,cols=2,rows=2,cast=True):
        p,u,v = np.asarray(p,dtype=float),np.asarray(u,dtype=float),np.asarray(v,dtype=float)
        z = np.array([0.0,height])
        top = np.array([p,p+u,p+u+v,p+v])
        bottom = top+z
        if cast:
            shadow(bottom,strength=0.26,offset=(0.006,0.007),blur=0.004)
            shadow(bottom,strength=0.18,offset=(0.001,0.003),blur=0.0014)
        c = np.asarray(color,dtype=float)
        # Rear-to-front order of the visible molded faces.
        paint([p+u,p+u+v,p+u+v+z,p+u+z],c*0.69,shade=1.0)
        paint([p+v,p+u+v,p+u+v+z,p+v+z],c*0.83,shade=1.0)
        paint(top,c,shade=1.03)
        edge = z*0.11
        paint([p+v,p+u+v,p+u+v+edge,p+v+edge],c*1.07,opacity=0.50)
        paint([p+v+z*0.88,p+u+v+z*0.88,p+u+v+z,p+v+z],c*0.60,opacity=0.35)
        # Studs are circular in the brick's plane and elliptical in the image.
        dz = np.array([0.0,max(0.003,height*0.27)])
        for j in range(rows):
            for i in range(cols):
                center = p+u*((i+0.5)/cols)+v*((j+0.5)/rows)
                stud(center,u/cols*0.285,v/rows*0.285,dz,c)

    # Loose pieces on the exposed carpet, clear of the child and the strap.
    brick((0.865,0.859),(0.063,0.018),(-0.015,0.030),0.017,(204,47,34),2,2)
    brick((0.943,0.924),(0.045,-0.008),(0.006,0.023),0.014,(238,182,29),2,1)
    brick((0.822,0.947),(0.068,0.016),(-0.012,0.021),0.016,(31,110,176),3,1)

    # Long assemblies follow the orientations of the original held controls.
    pr = np.array([0.610,0.672])
    ur = np.array([0.258,0.035])
    vr = np.array([-0.014,0.028])
    brick(pr,ur,vr,0.025,(29,102,183),6,2)
    brick(pr-np.array([0.0,0.026]),ur*(2.0/6.0),vr,0.026,(210,48,33),2,2,cast=False)

    pl = np.array([0.002,0.811])
    ul = np.array([0.246,0.081])
    vl = np.array([-0.008,0.055])
    brick(pl,ul,vl,0.021,(235,186,35),6,2)
    brick(pl+ul*(4.0/6.0)-np.array([0.0,0.023]),ul*(2.0/6.0),vl,0.023,(39,139, seventy:=70),2,2,cast=False)

    rendered = cv2.resize(canvas,(w,h),interpolation=cv2.INTER_AREA)
    cov = cv2.resize(coverage,(w,h),interpolation=cv2.INTER_AREA)
    cov = cv2.GaussianBlur(cov,(0,0),max(0.25,min(w,h)*0.00055))
    out = base*(1-cov[:,:,None])+rendered*cov[:,:,None]
    object_mask = cv2.resize(solids,(w,h),interpolation=cv2.INTER_AREA)
    grain = rng.normal(0,0.75,(h,w,1)).astype(np.float32)
    out += grain*object_mask[:,:,None]

    # The real skin is composited last so the child visibly grips the bricks.
    hand_alpha = cv2.GaussianBlur(hand_mask.astype(np.float32)/255.0,(0,0),max(0.35,min(w,h)*0.0008))
    hand_alpha[hand_mask > 0] = 1.0
    out = out*(1-hand_alpha[:,:,None])+source.astype(np.float32)*hand_alpha[:,:,None]
    return Image.fromarray(np.clip(out,0,255).astype(np.uint8), 'RGB')
Remove the pilots.
magicbrush_train_229415_1 · remove · execution=passed
PASSinstr 4preserve 5quality 4
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The pilots/occupants in the cockpit appear to have been removed while the aircraft, background, and overall scene remain essentially unchanged. The canopy area looks slightly smoothed/blurred from the edit, but it is not very noticeable and the image remains visually coherent.

l1=0.0051 · gain=0.0000 · mask_l1=0.0037 · preserve_l1=0.0069

reasoning / plan
{
 "visual_evidence": [
  "Small human figures are visible through the aircraft's long cockpit canopy.",
  "The canopy has narrow structural frames and gray-blue glazing.",
  "The aircraft's markings, landing gear, and blurred airfield surroundings are outside the removal area."
 ],
 "target_object": "The pilots visible inside the cockpit",
 "target_region": "The glazed cockpit above the aircraft's fuselage, near the middle-left of the image",
 "editing_intent": "Remove the visible pilots and reconstruct an unoccupied, shaded cockpit behind the existing canopy.",
 "editing_plan": [
  "Mask the cockpit glazing containing the pilots while protecting the canopy outline and structural frames.",
  "Inpaint the masked interiors using nearby canopy pixels.",
  "Synthesize additional glass texture from an unoccupied rear section of the canopy and background reflections.",
  "Restore subtle shading and grain, then feather the edits within the glazing."
 ],
 "preservation_constraints": [
  "Preserve the canopy framework and outer silhouette.",
  "Do not alter the fuselage, aircraft markings, propeller area, or landing gear.",
  "Keep the original airfield background, motion blur, lighting, and image dimensions."
 ]
}
pixel code
def edit(image):
    import cv2
    import numpy as np
    from PIL import Image

    rgb = np.asarray(image.convert('RGB')).copy()
    w, h = image.size
    scale = max(w, h) / 512.0

    def point(x, y):
        return (int(round(x * w)), int(round(y * h)))

    # Work with an antialiased mask so the narrow canopy edges survive.
    ss = 4
    glass_hi = np.zeros((h * ss, w * ss), np.uint8)
    opening = [(0.247, 0.496), (0.257, 0.488),
               (0.277, 0.484), (0.350, 0.484),
               (0.367, 0.490), (0.378, 0.502),
               (0.376, 0.515), (0.250, 0.518)]
    poly = np.array([(round(x*w*ss), round(y*h*ss)) for x, y in opening], np.int32)
    cv2.fillPoly(glass_hi, [poly], 255)

    # These slender strips belong to the original canopy, not the occupants.
    frame_hi = np.zeros_like(glass_hi)
    ribs = [((0.256, 0.488), (0.261, 0.520)),
            ((0.274, 0.484), (0.279, 0.519)),
            ((0.295, 0.483), (0.302, 0.518)),
            ((0.316, 0.483), (0.325, 0.518)),
            ((0.339, 0.484), (0.349, 0.517)),
            ((0.361, 0.487), (0.374, 0.516))]
    line_width = max(1, int(round(0.0025 * w * ss)))
    for a, b in ribs:
        pa = (round(a[0]*w*ss), round(a[1]*h*ss))
        pb = (round(b[0]*w*ss), round(b[1]*h*ss))
        cv2.line(frame_hi, pa, pb, 255, line_width, cv2.LINE_AA)
    cv2.polylines(frame_hi, [poly], True, 255,
                  max(1, int(round(0.0016*w*ss))), cv2.LINE_AA)
    glass = cv2.resize(glass_hi, (w, h), interpolation=cv2.INTER_AREA)
    frames = cv2.resize(frame_hi, (w, h), interpolation=cv2.INTER_AREA)
    alpha = glass.astype(np.float32) / 255.0
    alpha *= 1.0 - frames.astype(np.float32) / 255.0
    mask = (alpha > 0.28).astype(np.uint8) * 255

    # Remove all occupant pixels within the panes, leaving the metalwork intact.
    filled = cv2.inpaint(rgb, mask, max(1.5, 2.0*scale), cv2.INPAINT_TELEA)
    ys, xs = np.nonzero(mask)
    if len(xs) == 0:
        return Image.fromarray(rgb)
    x0, x1 = int(xs.min()), int(xs.max()) + 1
    y0, y1 = int(ys.min()), int(ys.max()) + 1
    bw, bh = x1-x0, y1-y0

    # The rear tip of the glazing supplies real glass color and texture.
    dx0, dy0 = point(0.239, 0.500)
    dx1, dy1 = point(0.249, 0.514)
    dx1 = min(w, max(dx0+2, dx1))
    dy1 = min(h, max(dy0+2, dy1))
    donor = rgb[dy0:dy1, dx0:dx1].astype(np.float32)
    donor_soft = cv2.GaussianBlur(donor, (0, 0), max(0.45, 0.55*scale))
    row_colors = np.median(donor_soft, axis=1, keepdims=True)
    profile = cv2.resize(row_colors, (bw, bh), interpolation=cv2.INTER_LINEAR)

    # Reuse nearby reflected background variation without introducing new objects.
    rx0, ry0 = point(0.250, 0.450)
    rx1, ry1 = point(0.376, 0.479)
    reflected = rgb[ry0:max(ry0+1, ry1), rx0:max(rx0+1, rx1)].astype(np.float32)
    reflected = cv2.resize(reflected, (bw, bh), interpolation=cv2.INTER_LINEAR)
    reflected = cv2.GaussianBlur(reflected, (0, 0), max(0.6, 0.8*scale))
    variation = reflected - cv2.GaussianBlur(reflected, (0, 0), max(1.2, 3.0*scale))
    variation = np.clip(variation, -24, 24)

    base = filled[y0:y1, x0:x1].astype(np.float32)
    # Inpaint retains local illumination; the donor prevents a featureless smear.
    rebuilt = 0.60*base + 0.40*profile + 0.20*variation
    donor_detail = donor - donor_soft
    rng = np.random.default_rng(19)
    yy = np.arange(bh)[:, None] % donor.shape[0]
    xx = (np.arange(bw)[None, :] + rng.integers(0, donor.shape[1], (bh, 1))) % donor.shape[1]
    detail = donor_detail[yy, xx]
    detail = np.clip(detail, -8, 8)
    noise_level = float(np.clip(np.std(donor_detail)*0.25, 0.45, 1.25))
    rebuilt += 0.65*detail + rng.normal(0, noise_level, rebuilt.shape)

    # Feather only inward so the aircraft and background remain unchanged.
    distance = cv2.distanceTransform(mask, cv2.DIST_L2, 3)
    inward = np.clip(distance / max(0.8, 0.9*scale), 0, 1)
    blend = (alpha * inward)[y0:y1, x0:x1, None]
    original = rgb[y0:y1, x0:x1].astype(np.float32)
    rgb[y0:y1, x0:x1] = np.clip(original*(1-blend) + rebuilt*blend, 0, 255).astype(np.uint8)
    return Image.fromarray(rgb)
put a sword in place of the snowboard
magicbrush_train_218113_1 · add / insert · execution=passed
FAILinstr 4preserve 3quality 3
source
GPT-6.1-Sol output
MagicBrush target (reference only)

A sword has been placed where the snowboard was, and the main target object is largely replaced. However, the edit leaves noticeable ghosting/transparent remnants and smudged artifacts where the snowboard and bindings were, while the sword appears pasted in and not fully integrated with the snow scene.

l1=0.0450 · gain=0.0348 · mask_l1=0.0046 · preserve_l1=0.0804

reasoning / plan
{
 "visual_evidence": [
  "A tall blue-and-gray snowboard stands upright near the center, leaning slightly left at the top.",
  "Two black bindings protrude from the snowboard.",
  "Snow surrounds its lower end.",
  "Trees, distant snowy mountains, cloudy sky, and a wooden slat fence form the background."
 ],
 "target_object": "The snowboard and both bindings",
 "target_region": "The central upright object, extending from near the top edge to the bottom edge, including the protruding black bindings",
 "editing_intent": "Replace the snowboard with a realistic upright steel sword, with its blade pointing down into the snow.",
 "editing_plan": [
  "Mask the snowboard silhouette and both bindings.",
  "Remove them using inpainting supplemented by region-specific texture patches sampled from the same image.",
  "Restore the exposed sky, mountains, fence, and snow with feathered transitions.",
  "Construct a narrow metallic blade, dimensional crossguard, wrapped dark grip, and metal pommel in the snowboard's former position.",
  "Add directional metallic reflections, fine texture, soft ground shading, and snow occlusion at the blade tip."
 ],
 "preservation_constraints": [
  "Preserve the original image dimensions and framing.",
  "Keep all visible trees and branches outside the replacement mask unchanged.",
  "Preserve the fence, mountains, and sky outside the removed object's silhouette.",
  "Retain the surrounding snow texture except where reconstruction or the sword's subtle shadow is necessary.",
  "Do not add people, text, or unrelated objects."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    w, h = image.size
    original = np.asarray(image.convert('RGB')).copy()
    rng = np.random.default_rng(27)
    yy, xx = np.mgrid[0:h, 0:w].astype(np.float32)
    X, Y = xx / w, yy / h
    mask = np.zeros((h, w), np.uint8)

    def mask_polygon(points):
        p = np.array([(round(x*w), round(y*h)) for x, y in points], np.int32)
        cv2.fillPoly(mask, [p], 255)

    mask_polygon([
        (.423,.155),(.424,.119),(.431,.097),(.442,.078),
        (.461,.065),(.487,.058),(.513,.059),(.540,.065),
        (.565,.079),(.586,.101),(.606,.134),(.618,.184),
        (.634,.287),(.654,.438),(.673,.617),(.690,.815),
        (.701,1.01),(.515,1.01),(.509,.916),(.495,.744),
        (.478,.553),(.458,.357),(.436,.227)
    ])
    mask_polygon([
        (.477,.320),(.536,.295),(.579,.275),(.631,.265),
        (.659,.284),(.674,.318),(.670,.351),(.687,.379),
        (.690,.413),(.680,.449),(.654,.472),(.563,.459),
        (.513,.439),(.477,.403),(.461,.361),(.465,.331)
    ])
    mask_polygon([
        (.529,.721),(.567,.713),(.600,.726),(.653,.733),
        (.691,.745),(.711,.768),(.713,.784),(.735,.795),
        (.750,.839),(.748,.885),(.730,.927),(.702,.940),
        (.687,.930),(.697,.914),(.707,.893),(.708,.854),
        (.682,.895),(.641,.910),(.577,.882),(.529,.871),
        (.503,.827),(.499,.781),(.514,.744)
    ])
    dilation = max(1, int(round(.006*w)))
    kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2*dilation+1, 2*dilation+1))
    mask = cv2.dilate(mask, kernel)
    preliminary = cv2.inpaint(original, mask, max(2, int(.012*w)), cv2.INPAINT_TELEA).astype(np.float32)

    def sample(sx, sy):
        return cv2.remap(original, np.clip(sx*w, 0, w-1).astype(np.float32),
                         np.clip(sy*h, 0, h-1).astype(np.float32),
                         cv2.INTER_CUBIC, borderMode=cv2.BORDER_REFLECT_101).astype(np.float32)

    sky = sample(X + .245, Y - .029)
    mountains = sample(.268 + (X-.420)*.445, Y)
    horizon = .174 + .004*np.sin((X-.42)*30)
    mix = np.clip((Y-horizon)/.012, 0, 1)
    mix = mix*mix*(3-2*mix)
    texture = sky*(1-mix[...,None]) + mountains*mix[...,None]

    fence_top = .253 - .110*X
    fence_bottom = .351 + .050*X
    donor_x = X + .125
    donor_top = .253 - .110*donor_x
    donor_bottom = .351 + .050*donor_x
    vertical_fraction = (Y-fence_top)/np.maximum(fence_bottom-fence_top, .01)
    fence_y = donor_top + vertical_fraction*(donor_bottom-donor_top)
    fence_patch = sample(donor_x, fence_y)
    fence_weight = np.clip((X-.610)/.012, 0, 1)
    fence_weight *= np.clip((Y-fence_top)/.005, 0, 1)
    fence_weight *= np.clip((fence_bottom-Y)/.006, 0, 1)
    texture = texture*(1-fence_weight[...,None]) + fence_patch*fence_weight[...,None]

    snow_y = Y + .085*np.exp(-((Y-.395)/.095)**2)
    snow = sample(X-.290, snow_y)
    snowline = .423 - .070*(X-.430) + .002*np.sin(X*42)
    snow_weight = np.clip((Y-snowline)/.009, 0, 1)
    snow_weight = snow_weight*snow_weight*(3-2*snow_weight)
    texture = texture*(1-snow_weight[...,None]) + snow*snow_weight[...,None]

    distance = cv2.distanceTransform(mask, cv2.DIST_L2, 5)
    interior = np.clip(distance/max(1.0, .005*w), 0, 1)
    reconstructed = preliminary*(1-interior[...,None]) + texture*interior[...,None]
    edge_noise = rng.normal(0, .65, (h, w, 1)).astype(np.float32)
    reconstructed += edge_noise*(1-interior[...,None])
    result = original.astype(np.float32)
    result[mask>0] = reconstructed[mask>0]
    result = np.clip(result, 0, 255)

    # A low-contrast, soft contact shadow on the snow.
    shadow_axis = (X-.729) + .10*(Y-.984)
    shadow_cross = (Y-.984) - .045*(X-.729)
    shadow = np.exp(-((shadow_axis/.095)**2 + (shadow_cross/.010)**2)*2)
    shadow *= np.clip((Y-.938)/.025, 0, 1)*.14
    result *= 1-shadow[...,None]
    snow_background = result.copy()

    # Render the sword at double resolution for clean subpixel edges.
    scale = 2
    W, H = w*scale, h*scale
    gy, gx = np.mgrid[0:H, 0:W].astype(np.float32)
    px, py = (gx+.5)/scale, (gy+.5)/scale
    origin = np.array([.550*w, .310*h], np.float32)
    endpoint = np.array([.650*w, .979*h], np.float32)
    direction = endpoint-origin
    blade_length = float(np.linalg.norm(direction))
    direction /= blade_length
    normal = np.array([direction[1], -direction[0]], np.float32)
    dx, dy = px-origin[0], py-origin[1]
    u = dx*normal[0] + dy*normal[1]
    t = dx*direction[0] + dy*direction[1]
    grain = rng.normal(0, 1.1, (H, W)).astype(np.float32)

    def add_layer(a, color, softness=.38):
        nonlocal result
        a = np.asarray(a, np.float32)
        if softness > 0:
            a = cv2.GaussianBlur(a, (0, 0), softness)
        a = np.clip(a, 0, 1)
        color = np.asarray(color, np.float32)
        if color.ndim == 2:
            color = np.repeat(color[...,None], 3, axis=2)
        premultiplied = color*a[...,None]
        small_color = cv2.resize(premultiplied, (w,h), interpolation=cv2.INTER_AREA)
        small_alpha = cv2.resize(a, (w,h), interpolation=cv2.INTER_AREA)
        result = result*(1-small_alpha[...,None]) + small_color

    def local_polygon(points):
        coords = []
        for uu, tt in points:
            p = origin + normal*(uu*w) + direction*(tt*h)
            coords.append(p*scale)
        a = np.zeros((H,W), np.uint8)
        cv2.fillPoly(a, [np.round(coords).astype(np.int32)], 255, lineType=cv2.LINE_AA)
        return a.astype(np.float32)/255

    fraction = np.clip(t/blade_length, 0, 1)
    width = w*(.030-.014*np.minimum(fraction/.83, 1))
    width *= np.where(fraction>.83, (1-fraction)/.17, 1)
    blade_mask = (t>=0)&(t<=blade_length)&(np.abs(u)<=width)
    add_layer(blade_mask, [42,49,57])
    inner = blade_mask & (np.abs(u)<np.maximum(width-.0015*w, 0))
    r = u/np.maximum(width, .0001*w)
    brightness = np.where(r<-.10, 112+48*(r+1)/.90, 211-68*(r+.10)/1.10)
    brightness += 29*np.exp(-((r+.10)/.045)**2)
    brightness += 9*np.sin(t/(.088*h)) + 3*np.sin(u/(.0024*w))
    brightness += grain
    bevel = np.clip((np.abs(r)-.79)/.16, 0, 1)
    bevel_brightness = np.where(r>0, 237, 171) + 7*np.sin(t/(.071*h))
    brightness = brightness*(1-bevel) + bevel_brightness*bevel
    steel = np.stack([brightness*.91, brightness*.97, brightness*1.025], axis=2)
    add_layer(inner, np.clip(steel,0,255))

    # Restrained lengthwise surface scratches, not decorative markings.
    scratches = np.zeros((H,W), np.float32)
    for i in range(13):
        uu = float(rng.uniform(-.018,.018))*w
        start = float(rng.uniform(.045,.42))*h
        end = min(start+float(rng.uniform(.018,.095))*h, blade_length*.85)
        p1 = (origin+normal*uu+direction*start)*scale
        p2 = (origin+normal*uu+direction*end)*scale
        cv2.line(scratches, tuple(np.round(p1).astype(int)), tuple(np.round(p2).astype(int)),
                 float(rng.uniform(.06,.15)), 1, cv2.LINE_AA)
    add_layer(scratches*inner, [208,218,226], .3)

    # Cylindrical dark leather grip with fine diagonal wrapping seams.
    grip_width = .0175*w*(1+.10*np.cos((t+.11*h)/(.11*h)))
    grip_mask = (t>-.214*h)&(t<-.022*h)&(np.abs(u)<grip_width)
    grip_r = u/np.maximum(grip_width,1)
    cylindrical_light = np.sqrt(np.clip(1-grip_r**2,0,1))
    leather_light = 24 + 28*cylindrical_light + 9*np.exp(-((grip_r-.28)/.32)**2)
    phase = (t/(.0165*h) + u/(.080*w)) % 1
    seam = np.exp(-((phase-.10)/.067)**2)
    seam_highlight = np.exp(-((phase-.21)/.052)**2)
    leather_light += -13*seam + 5*seam_highlight + grain*1.1
    leather = np.stack([leather_light*.94,leather_light*.98,leather_light],axis=2)
    add_layer(grip_mask, np.clip(leather,0,255))

    # Steel ferrules connect the leather to the pommel and crossguard.
    for center, half_height in [(-.208,.006),(-.023,.007)]:
        collar = (np.abs(t-center*h)<half_height*h)&(np.abs(u)<.022*w)
        b = 77+103*np.sqrt(np.clip(1-(u/(.023*w))**2,0,1))
        b += 12*np.cos((t-center*h)/(half_height*h)*2)+grain
        add_layer(collar, np.stack([b*.88,b*.94,b],axis=2))

    guard = local_polygon([
        (-.112,-.015),(-.108,-.028),(-.089,-.025),(-.045,-.016),
        (-.021,-.019),(.021,-.019),(.052,-.024),(.095,-.040),
        (.113,-.036),(.116,-.019),(.098,-.019),(.053,-.004),
        (.024,.009),(-.023,.009),(-.053,-.002),(-.094,-.010)
    ])
    guard_light = 79+61*np.exp(-((t+.015*h)/(.009*h))**2)
    guard_light += 24*(u/(.12*w)) + 7*np.sin(u/(.026*w)) + grain
    guard_light = np.clip(guard_light,48,205)
    add_layer(guard, np.stack([guard_light*.90,guard_light*.96,guard_light],axis=2))
    guard_edge = local_polygon([
        (-.106,-.026),(-.088,-.024),(-.044,-.015),(-.022,-.018),
        (.020,-.018),(.052,-.023),(.094,-.038),(.108,-.035),
        (.107,-.033),(.094,-.035),(.053,-.020),(.022,-.015),
        (-.022,-.015),(-.044,-.012),(-.089,-.021),(-.106,-.023)
    ])
    add_layer(guard_edge*.65, [187,197,205])

    # Rounded, faceted metal pommel.
    pu = u/(.025*w)
    pt = (t+.238*h)/(.025*h)
    radius2 = pu*pu+pt*pt
    pommel = radius2<1
    z = np.sqrt(np.clip(1-radius2,0,1))
    pommel_light = 61+105*z+33*pu-26*pt
    pommel_light += 10*np.cos(np.arctan2(pt,pu)*6)*z+grain
    rim = np.clip((radius2-.75)/.23,0,1)
    pommel_light = pommel_light*(1-rim)+(49+24*z)*rim
    add_layer(pommel, np.stack([pommel_light*.88,pommel_light*.95,pommel_light],axis=2))

    # The very end disappears behind the existing granular snow surface.
    lip_y = .974+.0015*np.sin((X-.650)*350)+.0008*np.cos(X*517)
    lip = (Y>lip_y)&(np.abs(X-.650)<.020)
    lip_alpha = np.clip((Y-lip_y)/.002,0,1)*lip
    result = result*(1-lip_alpha[...,None])+snow_background*lip_alpha[...,None]
    return Image.fromarray(np.clip(result,0,255).astype(np.uint8), 'RGB')
move the plant
magicbrush_train_472364_2 · other · execution=passed
PASSinstr 4preserve 4quality 3
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The plant has been moved to a new position near the lower center of the image, satisfying the requested local edit. Most unrelated scene content is preserved, but there are noticeable artifacts/blurred remnants and an unnatural shadow around the moved plant, reducing visual quality.

l1=0.0764 · gain=-0.0002 · mask_l1=0.0016 · preserve_l1=0.0838

reasoning / plan
{
 "visual_evidence": [
  "A slender green plant rises from the bottom edge near the lower center-right.",
  "Its leafy top is in front of the beige wall.",
  "The television is on the left, and a person stands on the right.",
  "The plant's container is not visible."
 ],
 "target_object": "The green plant, including its leaves and visible stalks",
 "target_region": "The lower center-right, between the television stand and the person",
 "editing_intent": "Move the plant left by approximately one tenth of the image width, keeping its height and orientation unchanged.",
 "editing_plan": [
  "Identify the plant using a constrained silhouette mask, green-color seeds, and foreground extraction.",
  "Save the original plant pixels with softly feathered edges.",
  "Remove the original plant and its nearby wall shadow using inpainting.",
  "Restore subtle texture and noise in the repaired background.",
  "Translate the plant left and add a restrained, soft wall shadow.",
  "Composite the relocated plant while preserving the rest of the scene."
 ],
 "preservation_constraints": [
  "Keep the person, television, lamp, framed pictures, and furniture unchanged.",
  "Keep the plant's original appearance, size, and orientation.",
  "Do not add a pot or extend the plant beyond the visible image.",
  "Preserve the wall and floor shading outside the repaired region.",
  "Allow only natural occlusion by the relocated plant at its destination."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    w, h = image.size
    src = np.array(image.convert('RGB'))
    scale = min(w, h)

    def point(x, y):
        return (int(round(x * (w - 1))), int(round(y * (h - 1))))

    def polygon(mask, coords, value=255):
        pts = np.array([point(x, y) for x, y in coords], np.int32)
        cv2.fillPoly(mask, [pts], value)

    def line(mask, coords, thickness, value=255):
        pts = np.array([point(x, y) for x, y in coords], np.int32)
        cv2.polylines(mask, [pts], False, value, max(1, int(round(thickness * scale))), cv2.LINE_8)

    # Narrow geometric envelopes prevent foreground extraction from reaching
    # the television, lamp, cables, or the person.
    envelope = np.zeros((h, w), np.uint8)
    polygon(envelope, [(.555,.762),(.558,.708),(.575,.683),(.612,.664),
                       (.653,.655),(.675,.657),(.688,.680),(.687,.711),
                       (.663,.719),(.644,.697),(.612,.723),(.581,.765)])
    line(envelope, [(.660,.661),(.680,.684),(.694,.716),
                    (.704,.762),(.704,.814)], .020)
    line(envelope, [(.690,.680),(.703,.709),(.715,.759),
                    (.722,.810),(.718,.875),(.715,1.0)], .016)
    polygon(envelope, [(.686,.784),(.708,.783),(.706,.858),
                       (.701,.926),(.700,1.0),(.676,1.0),
                       (.681,.922),(.686,.855)])

    pad = max(1, int(round(.004 * scale)))
    kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2*pad+1, 2*pad+1))
    expanded = cv2.dilate(envelope, kernel)
    # Keep the extraction away from the person's dark silhouette.
    expanded[:, int(round(.730*w)):] = 0
    envelope[:, int(round(.730*w)):] = 0

    hsv = cv2.cvtColor(src, cv2.COLOR_RGB2HSV)
    r, g, b = [src[:, :, i].astype(np.float32) for i in range(3)]
    green = ((hsv[:,:,0] >= 30) & (hsv[:,:,0] <= 99) &
             (hsv[:,:,1] >= 38) & (g > r + 2) & (g > b + 8) &
             (envelope > 0))
    labels = np.full((h, w), cv2.GC_BGD, np.uint8)
    labels[expanded > 0] = cv2.GC_PR_BGD
    labels[envelope > 0] = cv2.GC_PR_FGD
    labels[green] = cv2.GC_FGD

    stalk_seed = np.zeros((h, w), np.uint8)
    line(stalk_seed, [(.699,.808),(.696,.854),(.694,.889),
                      (.691,.938),(.689,1.0)], .002)
    labels[(stalk_seed > 0) & (envelope > 0)] = cv2.GC_FGD
    bg_model = np.zeros((1,65), np.float64)
    fg_model = np.zeros((1,65), np.float64)
    try:
        cv2.grabCut(src, labels, None, bg_model, fg_model, 5,
                    cv2.GC_INIT_WITH_MASK)
        plant = np.where((labels == cv2.GC_FGD) |
                         (labels == cv2.GC_PR_FGD), 255, 0).astype(np.uint8)
    except cv2.error:
        plant = np.where(green | (stalk_seed > 0), 255, 0).astype(np.uint8)
    plant[expanded == 0] = 0

    # Discard isolated segmentation flecks, but retain thin plant parts.
    count, components, stats, _ = cv2.connectedComponentsWithStats(plant, 8)
    filtered = np.zeros_like(plant)
    min_area = max(2, int(.000012 * w * h))
    for i in range(1, count):
        if stats[i, cv2.CC_STAT_AREA] >= min_area:
            filtered[components == i] = 255
    plant = filtered

    alpha = plant.astype(np.float32) / 255.0
    alpha = cv2.GaussianBlur(alpha, (0,0), max(.35, .00085*scale))

    # Remove both the object and the small soft leaf shadow on the wall.
    removal = cv2.dilate(plant, kernel)
    old_shadow = np.zeros_like(plant)
    cv2.ellipse(old_shadow, point(.588,.735),
                (max(1,int(.020*w)), max(1,int(.043*h))),
                18, 0, 360, 255, -1)
    cv2.ellipse(old_shadow, point(.634,.714),
                (max(1,int(.024*w)), max(1,int(.019*h))),
                25, 0, 360, 255, -1)
    removal = cv2.bitwise_or(removal, old_shadow)
    removal[:, int(round(.730*w)):] = 0
    repaired = cv2.inpaint(src, removal, max(2, .009*scale), cv2.INPAINT_TELEA)

    # Estimate the scene's fine noise from a clear section of beige wall.
    wall = src[int(.35*h):int(.48*h), int(.48*w):int(.63*w)].astype(np.float32)
    residual = wall - cv2.GaussianBlur(wall, (0,0), max(.65,.002*scale))
    noise_std = float(np.clip(np.median(np.abs(residual)) / .6745, .45, 1.35))
    rng = np.random.default_rng(17)
    noise = rng.normal(0, noise_std, (h,w,1)).astype(np.float32)
    repair_float = repaired.astype(np.float32)
    repair_float += noise * (removal.astype(np.float32)/255.0)[:,:,None]
    base = np.clip(repair_float, 0, 255)
    base[removal == 0] = src[removal == 0]

    dx = -int(round(.10*w))
    transform = np.float32([[1,0,dx],[0,1,0]])
    moved_alpha = cv2.warpAffine(alpha, transform, (w,h),
                                 flags=cv2.INTER_LINEAR,
                                 borderMode=cv2.BORDER_CONSTANT, borderValue=0)
    # Warp premultiplied colors so feathering never creates a dark rim.
    premultiplied = src.astype(np.float32) * alpha[:,:,None]
    moved_color = cv2.warpAffine(premultiplied, transform, (w,h),
                                 flags=cv2.INTER_LINEAR,
                                 borderMode=cv2.BORDER_CONSTANT, borderValue=0)

    shadow_transform = np.float32([[1,0,dx+.005*w],[0,1,.008*h]])
    shadow = cv2.warpAffine(alpha, shadow_transform, (w,h),
                            flags=cv2.INTER_LINEAR,
                            borderMode=cv2.BORDER_CONSTANT, borderValue=0)
    shadow = cv2.GaussianBlur(shadow, (0,0), max(1,.0045*scale))
    # The wall receives a faint cast shadow; retain the floor's existing light.
    yy = np.arange(h, dtype=np.float32)[:,None] / max(1,h-1)
    wall_weight = np.clip((.949-yy)/.025, 0, 1)
    shadow *= wall_weight
    shadow *= 1.0-moved_alpha
    base *= (1.0-.13*shadow[:,:,None])
    result = base * (1.0-moved_alpha[:,:,None]) + moved_color
    return Image.fromarray(np.clip(np.rint(result),0,255).astype(np.uint8), 'RGB')
Have the man be wearing a baseball cap
magicbrush_train_520701_3 · add / insert · execution=passed
PASSinstr 5preserve 5quality 4
source
GPT-6.1-Sol output
MagicBrush target (reference only)

A baseball cap has been added to the man's head in the correct target region, and the rest of the room and scene are preserved. The cap is slightly oversized and its lighting/edges are not perfectly integrated, but it is visually recognizable and acceptable.

l1=0.0075 · gain=-0.0012 · mask_l1=0.0017 · preserve_l1=0.0127

reasoning / plan
{
 "visual_evidence": [
  "The seated man is shown in left-facing profile.",
  "His uncovered dark hair is visible above his sunglasses.",
  "Strong window light comes from behind and to his left."
 ],
 "target_object": "The man's uncovered head",
 "target_region": "The hair and upper forehead near the center of the image",
 "editing_intent": "Add a realistic dark charcoal baseball cap, with its visor pointing left.",
 "editing_plan": [
  "Construct smooth masks for a fitted crown, lower band, visor, and visor underside.",
  "Render the cap with curved fabric shading, fine textile texture, panel seams, and a small top button.",
  "Add a restrained visor shadow to the upper forehead.",
  "Composite the cap with antialiased, feathered boundaries while preserving the rest of the photograph."
 ],
 "preservation_constraints": [
  "Keep the man's sunglasses, facial features, ears, clothing, and posture unchanged.",
  "Preserve the sofa, cushions, windows, outdoor view, curtains, and room.",
  "Do not alter pixels outside the cap and its small forehead shadow."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image, ImageDraw

    w, h = image.size
    source = np.asarray(image.convert('RGB'), dtype=np.float32)
    result = source.copy()
    scale = float(min(w, h))
    ss = 3
    rng = np.random.default_rng(174)
    yy, xx = np.mgrid[0:h, 0:w].astype(np.float32)
    x = xx / float(w)
    y = yy / float(h)

    def curve(start, segments):
        points = [start]
        p = np.asarray(start, dtype=float)
        for a, b, c in segments:
            a, b, c = map(lambda q: np.asarray(q, dtype=float), (a, b, c))
            for t in np.linspace(0.0, 1.0, 35)[1:]:
                q = (1-t)**3*p + 3*(1-t)**2*t*a + 3*(1-t)*t*t*b + t**3*c
                points.append(tuple(q))
            p = c
        return points

    def polygon_mask(points, feather=0.00065):
        canvas = Image.new('L', (w*ss, h*ss), 0)
        d = ImageDraw.Draw(canvas)
        d.polygon([(round(a*w*ss), round(b*h*ss)) for a, b in points], fill=255)
        canvas = canvas.resize((w, h), Image.Resampling.LANCZOS)
        mask = np.asarray(canvas, dtype=np.float32) / 255.0
        if feather:
            mask = cv2.GaussianBlur(mask, (0, 0), max(0.15, scale*feather))
        return np.clip(mask, 0, 1)

    def stroke_mask(points, width):
        canvas = Image.new('L', (w*ss, h*ss), 0)
        d = ImageDraw.Draw(canvas)
        d.line([(round(a*w*ss), round(b*h*ss)) for a, b in points],
               fill=255, width=max(1, round(width*scale*ss)), joint='curve')
        return np.asarray(canvas.resize((w, h), Image.Resampling.LANCZOS), dtype=np.float32)/255.0

    def blend(layer, mask):
        nonlocal result
        alpha = np.clip(mask, 0, 1)[..., None]
        result = result*(1-alpha) + np.clip(layer, 0, 255)*alpha

    coarse = rng.normal(0, 1, (max(3, int(h*0.11)), max(3, int(w*0.11)))).astype(np.float32)
    coarse = cv2.resize(coarse, (w, h), interpolation=cv2.INTER_CUBIC)
    fine = rng.normal(0, 1, (h, w)).astype(np.float32)
    weave = 0.45*np.sin(xx*2.15 + yy*0.32) + 0.35*np.sin(yy*2.35 - xx*0.2)
    textile = 1.15*fine + 0.85*coarse + weave

    crown_pts = curve((0.474, 0.470), [
        ((0.471, 0.444), (0.484, 0.423), (0.507, 0.415)),
        ((0.525, 0.406), (0.550, 0.409), (0.570, 0.420)),
        ((0.590, 0.431), (0.601, 0.458), (0.601, 0.491)),
        ((0.603, 0.497), (0.593, 0.498), (0.580, 0.493)),
        ((0.548, 0.484), (0.508, 0.472), (0.474, 0.470))
    ])
    crown = polygon_mask(crown_pts)

    bill_pts = curve((0.498, 0.470), [
        ((0.476, 0.458), (0.443, 0.456), (0.423, 0.466)),
        ((0.411, 0.472), (0.407, 0.478), (0.416, 0.482)),
        ((0.437, 0.486), (0.475, 0.482), (0.507, 0.478)),
        ((0.510, 0.475), (0.505, 0.472), (0.498, 0.470))
    ])
    bill = polygon_mask(bill_pts)
    underside = polygon_mask([(a, b+0.0038) for a, b in bill_pts])

    shadow_pts = curve((0.479, 0.474), [
        ((0.491, 0.475), (0.516, 0.479), (0.526, 0.483)),
        ((0.531, 0.489), (0.526, 0.495), (0.521, 0.498)),
        ((0.504, 0.490), (0.489, 0.489), (0.478, 0.488)),
        ((0.475, 0.483), (0.477, 0.479), (0.479, 0.474))
    ])
    shadow = polygon_mask(shadow_pts, 0.0020)
    skin = ((source[..., 0] > source[..., 1]*0.98) &
            (source[..., 0] > source[..., 2]*1.025) &
            (source.mean(axis=2) > 33)).astype(np.float32)
    shadow *= skin*0.24
    blend(source*np.array([0.78, 0.80, 0.83], dtype=np.float32), shadow)

    under_color = np.empty_like(source)
    under_color[:] = [16, 19, 21]
    under_color += (textile*0.65)[..., None]
    blend(under_color, underside)

    # Rounded illumination: bright upper-left cloth, darker rear and lower panels.
    highlight = np.exp(-(((x-0.510)/0.063)**2 + ((y-0.427)/0.037)**2))
    left_rim = np.exp(-(((x-0.478)/0.012)**2 + ((y-0.450)/0.043)**2))
    rear_shade = np.clip((x-0.541)/0.064, 0, 1)
    lower_shade = np.clip((y-0.461)/0.039, 0, 1)
    light = 15.0*highlight + 7.0*left_rim - 9.0*rear_shade - 5.0*lower_shade
    crown_rgb = np.empty_like(source)
    crown_rgb[:] = [33, 38, 41]
    crown_rgb += light[..., None] + textile[..., None]
    crown_rgb[..., 0] += highlight*2.0
    crown_rgb[..., 2] -= highlight*1.0
    blend(crown_rgb, crown)

    # Subtle curved panel seams, with adjacent raised-thread highlights.
    seams = [
        curve((0.532, 0.416), [((0.503, 0.421), (0.486, 0.441), (0.480, 0.467))]),
        curve((0.532, 0.416), [((0.535, 0.437), (0.535, 0.459), (0.541, 0.482))]),
        curve((0.534, 0.416), [((0.568, 0.430), (0.590, 0.458), (0.592, 0.491))])
    ]
    for seam in seams:
        sm = stroke_mask(seam, 0.00125)*crown
        blend(crown_rgb-7.0, sm*0.43)
        raised = stroke_mask([(a-0.0014, b-0.0002) for a, b in seam], 0.0011)*crown
        blend(crown_rgb+9.0, raised*0.38)
        stitch_canvas = Image.new('L', (w*ss, h*ss), 0)
        sd = ImageDraw.Draw(stitch_canvas)
        for i in range(2, len(seam)-1, 5):
            a, b = seam[i], seam[i+1]
            sd.line([((a[0]+0.0020)*w*ss, a[1]*h*ss),
                     ((b[0]+0.0020)*w*ss, b[1]*h*ss)],
                    fill=180, width=max(1, round(scale*ss*0.0008)))
        st = np.asarray(stitch_canvas.resize((w, h), Image.Resampling.LANCZOS), dtype=np.float32)/255
        blend(crown_rgb+13, st*crown*0.23)

    band_pts = curve((0.474, 0.468), [
        ((0.512, 0.469), (0.557, 0.482), (0.601, 0.490)),
        ((0.602, 0.493), (0.602, 0.497), (0.598, 0.498)),
        ((0.556, 0.489), (0.511, 0.477), (0.475, 0.476)),
        ((0.473, 0.473), (0.473, 0.470), (0.474, 0.468))
    ])
    band = polygon_mask(band_pts)*crown
    band_rgb = crown_rgb - np.array([5, 6, 6], dtype=np.float32)
    blend(band_rgb, band*0.86)
    band_seam = curve((0.482, 0.473), [((0.518, 0.475), (0.559, 0.488), (0.596, 0.494))])
    blend(band_rgb+7, stroke_mask(band_seam, 0.0010)*band*0.35)

    visor_light = 7*np.exp(-(((x-0.443)/0.035)**2 + ((y-0.468)/0.014)**2))
    visor_light -= 7*np.clip((y-0.474)/0.014, 0, 1)
    visor_rgb = np.empty_like(source)
    visor_rgb[:] = [34, 39, 42]
    visor_rgb += (visor_light + 0.90*textile)[..., None]
    blend(visor_rgb, bill)
    visor_edge = curve((0.416, 0.480), [((0.435, 0.484), (0.473, 0.480), (0.501, 0.477))])
    blend(visor_rgb+11, stroke_mask(visor_edge, 0.0012)*bill*0.45)
    visor_stitch = curve((0.426, 0.476), [((0.447, 0.479), (0.471, 0.477), (0.491, 0.476))])
    blend(visor_rgb+8, stroke_mask(visor_stitch, 0.0009)*bill*0.24)

    # Small fabric-covered crown button with rounded light and its own tiny shadow.
    button_canvas = Image.new('L', (w*ss, h*ss), 0)
    bd = ImageDraw.Draw(button_canvas)
    bd.ellipse((0.527*w*ss, 0.409*h*ss, 0.537*w*ss, 0.417*h*ss), fill=255)
    button = np.asarray(button_canvas.resize((w, h), Image.Resampling.LANCZOS), dtype=np.float32)/255
    button = cv2.GaussianBlur(button, (0, 0), max(0.15, scale*0.00045))
    button_light = 9*np.exp(-(((x-0.530)/0.004)**2 + ((y-0.412)/0.003)**2))
    button_rgb = np.empty_like(source)
    button_rgb[:] = [38, 43, 45]
    button_rgb += (button_light + textile*0.55)[..., None]
    blend(button_rgb, button)

    return Image.fromarray(np.clip(np.rint(result), 0, 255).astype(np.uint8), 'RGB')
Remove the tin pans.
magicbrush_train_124157_1 · remove · execution=passed
FAILinstr 3preserve 4quality 3
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The tin pans are mostly covered/removed, but visible metallic pan edges remain along the bottom, and the replacement area looks like an unnatural dark red smear with a jagged boundary. The bananas and background are mostly preserved.

l1=0.0385 · gain=-0.0080 · mask_l1=0.0051 · preserve_l1=0.0648

reasoning / plan
{
 "visual_evidence": [
  "Dark pan fronts and thin reflective rims are visible beneath the bananas along the bottom edge.",
  "A red reflective section separates the foreground pans near the lower center.",
  "Partial shallow pans are visible along the top border above the red shelf.",
  "The bananas overlap the foreground pan rims."
 ],
 "target_object": "The visible foreground tin pans and the cropped pans along the top edge.",
 "target_region": "Below the bananas, following the sloping metal rims, and the exposed pan silhouettes at the top border.",
 "editing_intent": "Remove the pans and reconstruct unobtrusive, textured display surfaces while retaining the bananas and surrounding scene.",
 "editing_plan": [
  "Mask the foreground pan fronts, reflective divider, and metal rims without covering the bananas.",
  "Mask the partial pans at the top while preserving the red shelf.",
  "Inpaint the masked regions as an initial boundary repair.",
  "Reconstruct the lower display surface using texture sampled from the existing red wooden shelf, with additional grain and contact shading.",
  "Fill the upper pan silhouettes with sampled dark background texture.",
  "Feather the repairs narrowly and preserve pixels outside the edit masks."
 ],
 "preservation_constraints": [
  "Preserve the bananas, including their stems, blemishes, and overlapping contours.",
  "Preserve the printed cartons behind the fruit.",
  "Preserve the red shelf fascia and visible structural supports.",
  "Keep the original image size and overall lighting."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    original = np.asarray(image.convert('RGB')).copy()
    w, h = image.size
    s = float(min(w, h))
    rng = np.random.default_rng(27)

    def polygon_mask(polygons):
        mask = np.zeros((h, w), np.uint8)
        for polygon in polygons:
            points = np.array([[int(round(x * (w - 1))), int(round(y * (h - 1)))] for x, y in polygon], np.int32)
            cv2.fillPoly(mask, [points], 255)
        return mask

    lower = polygon_mask([[
        (0.143, 1.0), (0.194, 0.985), (0.262, 0.966),
        (0.335, 0.949), (0.398, 0.940), (0.448, 0.929),
        (0.503, 0.914), (0.558, 0.902), (0.603, 0.887),
        (0.634, 0.878), (0.645, 0.865), (0.655, 0.857),
        (0.673, 0.860), (0.712, 0.851), (0.754, 0.839),
        (0.803, 0.824), (0.851, 0.814), (0.899, 0.804),
        (0.943, 0.794), (0.978, 0.787), (1.0, 0.779),
        (1.0, 1.0)
    ]])
    upper = polygon_mask([
        [(0.0, 0.0), (0.265, 0.0), (0.300, 0.030),
         (0.310, 0.043), (0.275, 0.051), (0.060, 0.062),
         (0.0, 0.057)],
        [(0.322, 0.0), (0.723, 0.0), (0.762, 0.017),
         (0.733, 0.029), (0.383, 0.047), (0.347, 0.034)],
        [(0.738, 0.0), (1.0, 0.0), (1.0, 0.021),
         (0.803, 0.035), (0.776, 0.019)]
    ])
    union = cv2.bitwise_or(lower, upper)
    repaired = cv2.inpaint(original, union, max(2, int(round(s * 0.012))), cv2.INPAINT_TELEA).astype(np.float32)
    yy, xx = np.mgrid[0:h, 0:w].astype(np.float32)
    xn = xx / max(w - 1, 1)
    yn = yy / max(h - 1, 1)

    # Sample the uninterrupted sloping red shelf fascia rather than the fruit.
    sx = (0.035 + 0.91 * xn) * (w - 1)
    depth = np.clip((yn - 0.775) / 0.225, 0.0, 1.0)
    sy = (0.094 - 0.052 * (sx / max(w - 1, 1)) + (depth - 0.5) * 0.017) * (h - 1)
    wood = cv2.remap(original, sx.astype(np.float32), sy.astype(np.float32), cv2.INTER_CUBIC, borderMode=cv2.BORDER_REFLECT_101).astype(np.float32)

    # Preserve sampled color variation while avoiding enlarged, smooth grain.
    fine = rng.normal(0.0, 1.25, (h, w)).astype(np.float32)
    grain = rng.normal(0.0, 1.0, (h, w)).astype(np.float32)
    grain = cv2.GaussianBlur(grain, (0, 0), sigmaX=max(1.0, s * 0.025), sigmaY=max(0.35, s * 0.0008))
    grain /= max(float(grain.std()), 1e-6)
    broad = rng.normal(0.0, 1.0, (h, w)).astype(np.float32)
    broad = cv2.GaussianBlur(broad, (0, 0), sigmaX=max(1.0, s * 0.065), sigmaY=max(1.0, s * 0.012))
    broad /= max(float(broad.std()), 1e-6)
    wood *= (0.80 + 0.10 * xn + 0.04 * depth)[..., None]
    wood += (fine + 1.6 * grain + 1.3 * broad)[..., None]

    # A soft contact shadow follows the original fruit/pan boundary.
    top = np.full(w, h, np.float32)
    for x in range(w):
        rows = np.flatnonzero(lower[:, x])
        if rows.size:
            top[x] = float(rows[0])
    distance_below = np.maximum(0.0, yy - top[None, :])
    contact = 1.0 - 0.34 * np.exp(-distance_below / max(1.0, h * 0.012))
    wood *= contact[..., None]

    # Sample a genuinely dark gap behind the display for the upper repairs.
    x0, x1 = int(w * 0.193), max(int(w * 0.240), int(w * 0.193) + 2)
    y0, y1 = int(h * 0.125), max(int(h * 0.172), int(h * 0.125) + 2)
    patch = original[y0:y1, x0:x1]
    if patch.size == 0:
        patch = original[:max(1, h // 20), :max(1, w // 20)]
    ph, pw = patch.shape[:2]
    tx = np.mod(xx * 0.47, max(1, 2 * (pw - 1)))
    ty = np.mod(yy * 0.65 + xn * ph * 0.3, max(1, 2 * (ph - 1)))
    tx = np.where(tx > pw - 1, 2 * (pw - 1) - tx, tx).astype(np.float32)
    ty = np.where(ty > ph - 1, 2 * (ph - 1) - ty, ty).astype(np.float32)
    background = cv2.remap(patch, tx, ty, cv2.INTER_LINEAR, borderMode=cv2.BORDER_REFLECT_101).astype(np.float32)
    background = cv2.GaussianBlur(background, (0, 0), max(0.4, s * 0.0015))
    background *= (0.79 + 0.12 * yn + 0.06 * xn)[..., None]
    background += rng.normal(0.0, 1.2, (h, w, 1)).astype(np.float32)

    def apply_texture(canvas, texture, mask):
        inside = mask.astype(np.float32) / 255.0
        distance = cv2.distanceTransform(mask, cv2.DIST_L2, 3)
        feather = max(0.7, s * 0.0017)
        alpha = np.clip(distance / feather, 0.0, 1.0) * inside
        # The inpainted edge beneath this narrow feather removes rim glints.
        return canvas * (1.0 - alpha[..., None]) + np.clip(texture, 0, 255) * alpha[..., None]

    repaired = apply_texture(repaired, wood, lower)
    repaired = apply_texture(repaired, background, upper)
    result = original.copy()
    selected = union > 0
    result[selected] = np.clip(repaired[selected], 0, 255).astype(np.uint8)
    return Image.fromarray(result, 'RGB')
give him a long beard
magicbrush_train_109190_2 · add / insert · execution=passed
FAILinstr 4preserve 4quality 2
source
GPT-6.1-Sol output
MagicBrush target (reference only)

A long beard was added to the man's face, matching the requested target. Unrelated background and clothing are mostly preserved, but the beard looks overly dark, flat, and pasted on, with an unnatural triangular shape and poor blending over the neck/shirt area.

l1=0.0156 · gain=-0.0102 · mask_l1=0.0257 · preserve_l1=0.0097

reasoning / plan
{
 "visual_evidence": [
  "The man has short dark facial hair along his jaw and chin.",
  "His face is turned toward the right, with his mouth and eyes visible.",
  "His chin is above the neckline of a white T-shirt.",
  "He has a light-colored mohawk, and a chain-link fence is visible behind him."
 ],
 "target_object": "The man's beard",
 "target_region": "The existing facial hair along the lower cheeks and chin, extending downward over the upper chest",
 "editing_intent": "Give him a long, tapered dark beard with realistic individual hairs while keeping his facial features visible.",
 "editing_plan": [
  "Build a curved beard mask anchored to the existing sideburns, jaw, and chin.",
  "Protect the mouth and retain the original face above the beard.",
  "Add a subtle shadow beneath the beard on the neck and shirt.",
  "Synthesize shaded dark-brown beard texture with curved, layered hair strands.",
  "Add irregular tips and fine loose hairs, feather the edges, and composite onto the original pixels."
 ],
 "preservation_constraints": [
  "Preserve the eyes, nose, lips, smile, and recognizable face.",
  "Do not change the mohawk or ears.",
  "Preserve the pose, white shirt outside the beard overlap, and background.",
  "Match the existing warm lighting and dark facial-hair color."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    original = np.asarray(image.convert('RGB'), dtype=np.float32)
    w, h = image.size
    scale = 3
    W, H = w * scale, h * scale
    rng = np.random.default_rng(1287)

    def pixels(points):
        p = np.asarray(points, dtype=np.float32).copy()
        p[:, 0] *= W
        p[:, 1] *= H
        return np.rint(p).astype(np.int32)

    def bezier(p0, p1, p2, p3, count=35):
        t = np.linspace(0.0, 1.0, count)[:, None]
        a, b, c, d = [np.asarray(p, dtype=np.float32) for p in (p0, p1, p2, p3)]
        return (1-t)**3*a + 3*(1-t)**2*t*b + 3*(1-t)*t*t*c + t**3*d

    start = (0.491, 0.402)
    segments = [
        ((0.495, 0.425), (0.500, 0.456), (0.518, 0.471)),
        ((0.539, 0.489), (0.575, 0.500), (0.601, 0.504)),
        ((0.621, 0.521), (0.650, 0.515), (0.668, 0.491)),
        ((0.674, 0.520), (0.662, 0.554), (0.657, 0.582)),
        ((0.658, 0.620), (0.638, 0.693), (0.610, 0.730)),
        ((0.604, 0.741), (0.590, 0.756), (0.581, 0.750)),
        ((0.564, 0.743), (0.535, 0.704), (0.520, 0.670)),
        ((0.498, 0.628), (0.479, 0.571), (0.480, 0.529)),
        ((0.477, 0.485), (0.483, 0.433), (0.491, 0.402))
    ]
    outline = []
    p0 = start
    for p1, p2, p3 in segments:
        outline.extend(bezier(p0, p1, p2, p3).tolist())
        p0 = p3
    mask = np.zeros((H, W), np.uint8)
    cv2.fillPoly(mask, [pixels(outline)], 255)

    mouth = np.zeros_like(mask)
    mouth_points = [(0.592, 0.457), (0.676, 0.451), (0.684, 0.482),
                    (0.654, 0.507), (0.614, 0.503), (0.586, 0.484)]
    cv2.fillPoly(mouth, [pixels(mouth_points)], 255)
    mask[mouth > 0] = 0
    edge_sigma = max(0.5, W * 0.0011)
    alpha = cv2.GaussianBlur(mask.astype(np.float32) / 255.0, (0, 0), edge_sigma)
    mouth_soft = cv2.GaussianBlur(mouth.astype(np.float32) / 255.0, (0, 0), max(0.5, W * 0.0007))
    alpha *= 1.0 - mouth_soft

    yy, xx = np.mgrid[0:H, 0:W].astype(np.float32)
    xx /= W
    yy /= H
    coarse = rng.normal(0, 1, (max(3, H // 35), max(3, W // 35))).astype(np.float32)
    coarse = cv2.resize(coarse, (W, H), interpolation=cv2.INTER_CUBIC)
    fine = rng.normal(0, 1, (H, W)).astype(np.float32)
    soft_noise = cv2.GaussianBlur(fine, (0, 0), max(0.6, W * 0.0009))
    right_light = np.clip((xx - 0.49) / 0.18, 0, 1)
    center_shadow = np.exp(-((xx - 0.555) / 0.036)**2)
    light = 0.79 + 0.29 * right_light - 0.11 * center_shadow
    light += 0.05 * np.cos((yy - 0.50) * 17.0)
    base_color = np.array([46.0, 33.5, 25.5], dtype=np.float32)
    texture = coarse * 3.0 + soft_noise * 5.0 + fine * 1.4
    beard = np.clip(base_color[None, None, :] * light[..., None] + texture[..., None], 0, 255).astype(np.uint8)

    root_u = np.array([0.0, 0.16, 0.35, 0.55, 0.75, 1.0])
    root_y = np.array([0.410, 0.469, 0.493, 0.508, 0.516, 0.498])
    palette = np.array([[17, 14, 11], [26, 20, 15], [38, 28, 20],
                        [50, 36, 26], [66, 47, 32], [88, 64, 43]], dtype=np.float32)
    probabilities = [0.14, 0.23, 0.28, 0.23, 0.10, 0.02]

    def hair_curve(u, drift=0.0):
        rx = 0.489 + 0.181 * u
        ry = float(np.interp(u, root_u, root_y))
        tx = 0.580 + (u - 0.5) * 0.074 + drift
        ty = 0.748 - 0.090 * abs(2*u - 1)**1.55
        return ((rx, ry), (rx + (tx-rx)*0.17, ry + (ty-ry)*0.34),
                (tx + (rx-tx)*0.28, ty - (ty-ry)*0.23), (tx, ty))

    def strand_color(u):
        c = palette[rng.choice(len(palette), p=probabilities)].copy()
        c *= 0.80 + 0.31 * u
        c += rng.normal(0, 2.0)
        return tuple(int(v) for v in np.clip(c, 5, 130))

    # Long fibers follow the shape from the jaw toward the tapered tip.
    for i in range(4400):
        u = float(rng.random())
        controls = hair_curve(u, float(rng.normal(0, 0.005)))
        t0 = float(rng.uniform(0, 0.89))
        t1 = min(1.025, t0 + float(rng.uniform(0.13, 0.56)))
        t = np.linspace(t0, t1, 22)[:, None]
        a, b, c, d = [np.array(p, dtype=np.float32) for p in controls]
        path = (1-t)**3*a + 3*(1-t)**2*t*b + 3*(1-t)*t*t*c + t**3*d
        waviness = rng.uniform(0.00025, 0.0011)
        path[:, 0] += waviness * np.sin(np.linspace(0, rng.uniform(2.0, 5.0), len(path)) + rng.uniform(0, 6.28))
        width = max(1, int(round(rng.uniform(0.22, 0.58) * W / 512.0)))
        cv2.polylines(beard, [pixels(path)], False, strand_color(u), width, cv2.LINE_AA)

    # Short surface fibers provide detail along the sides and between the long locks.
    occupied_y, occupied_x = np.where(mask > 200)
    for i in range(2600):
        k = int(rng.integers(0, len(occupied_x)))
        x = occupied_x[k] / W
        y = occupied_y[k] / H
        length = float(rng.uniform(0.009, 0.050))
        remaining = max(0.035, 0.76-y)
        dx = (0.582-x) * min(0.58, length/remaining) * 0.73
        bend = float(rng.normal(0, 0.0014))
        path = bezier((x, y), (x+dx*0.2+bend, y+length*0.35),
                      (x+dx*0.7-bend, y+length*0.75), (x+dx, y+length), 12)
        u = float(np.clip((x-0.489)/0.181, 0, 1))
        cv2.polylines(beard, [pixels(path)], False, strand_color(u),
                      max(1, int(round(W * rng.uniform(0.00043, 0.00085)))), cv2.LINE_AA)

    # Uneven, translucent hair tips avoid a smooth cut-out silhouette.
    loose_alpha = np.zeros((H, W), np.uint8)
    loose_color = np.zeros((H, W, 3), np.uint8)
    for i in range(250):
        u = float(rng.uniform(0.12, 0.94))
        a, b, c, d = [np.array(p, dtype=np.float32) for p in hair_curve(u, float(rng.normal(0, 0.006)))]
        d[1] += float(rng.uniform(0.001, 0.012))
        t = np.linspace(rng.uniform(0.76, 0.90), 1.0, 14)[:, None]
        path = (1-t)**3*a + 3*(1-t)**2*t*b + 3*(1-t)*t*t*c + t**3*d
        p = pixels(path)
        cv2.polylines(loose_alpha, [p], False, int(rng.uniform(80, 185)), 1, cv2.LINE_AA)
        cv2.polylines(loose_color, [p], False, strand_color(u), 1, cv2.LINE_AA)
    loose_a = loose_alpha.astype(np.float32) / 255.0
    loose_a *= (yy > 0.565).astype(np.float32)
    loose_a *= 1.0 - alpha
    final_alpha = alpha + loose_a * (1.0-alpha)
    premultiplied = beard.astype(np.float32) * alpha[..., None]
    premultiplied = premultiplied * (1.0-loose_a[..., None]) + loose_color.astype(np.float32) * loose_a[..., None]

    # Soft cast shadow on the neck and shirt immediately behind the new beard.
    transform = np.float32([[1, 0, -0.0035*W], [0, 1, 0.008*H]])
    shifted = cv2.warpAffine(alpha, transform, (W, H), flags=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT)
    shadow = cv2.GaussianBlur(shifted, (0, 0), max(1.0, W * 0.005))
    shadow *= np.clip((yy-0.527)/0.020, 0, 1)
    shadow = cv2.resize(shadow, (w, h), interpolation=cv2.INTER_AREA)
    background = original * (1.0 - 0.21 * shadow[..., None])
    a_small = cv2.resize(final_alpha, (w, h), interpolation=cv2.INTER_AREA)
    rgb_small = cv2.resize(premultiplied, (w, h), interpolation=cv2.INTER_AREA)
    result = background * (1.0-a_small[..., None]) + rgb_small
    grain = rng.normal(0, 0.65, (h, w, 1)).astype(np.float32)
    result += grain * a_small[..., None]
    return Image.fromarray(np.clip(result, 0, 255).astype(np.uint8), 'RGB')
change the carrots for a bear
magicbrush_train_82041_2 · replace / change · execution=passed
FAILinstr 4preserve 3quality 3
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The carrots have been largely replaced by a bear, matching the requested edit. However, the bear is oversized, covers some surrounding background and slightly intrudes on nearby objects, with small remnants of the carrots/greens still visible behind it. The pasted bear looks reasonably clear but not fully integrated with the original scene.

l1=0.0657 · gain=0.0127 · mask_l1=0.0072 · preserve_l1=0.1075

reasoning / plan
{
 "visual_evidence": [
  "Three orange felt carrots with dark green leafy tops lie diagonally on a wooden surface.",
  "A yellow fabric banana is visible on the right.",
  "A small white fabric rabbit with pink ears is near the bottom.",
  "The objects have soft textile surfaces and subtle shadows."
 ],
 "target_object": "The three felt carrots and their green tops",
 "target_region": "The upper-left and central portion of the image, stopping before the banana and rabbit",
 "editing_intent": "Replace the three carrots with one brown plush teddy bear that matches the handmade textile appearance of the other objects.",
 "editing_plan": [
  "Mask the orange carrots and their green tops while protecting the banana and rabbit.",
  "Remove the carrots and reconstruct exposed wood using inpainting and texture sampled from clean wood in the source.",
  "Construct a seated teddy bear with overlapping, shaded plush body parts, ears, paws, muzzle, eyes, and nose.",
  "Add textile grain, short fibers, subtle seams, and soft contact shadows.",
  "Feather the replacement edges and preserve the surrounding objects."
 ],
 "preservation_constraints": [
  "Keep the yellow banana unchanged.",
  "Keep the white rabbit and its pink details unchanged.",
  "Preserve the wooden background outside the replacement and its shadow.",
  "Maintain the source image dimensions and soft overhead lighting."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    rgb = np.asarray(image.convert('RGB')).copy()
    w, h = image.size
    scale = min(w, h)
    rng = np.random.default_rng(23)
    yy, xx = np.mgrid[0:h, 0:w].astype(np.float32)
    X, Y = xx / w, yy / h

    def polygon(points):
        m = np.zeros((h, w), np.uint8)
        p = np.array([(round(x*w), round(y*h)) for x, y in points], np.int32)
        cv2.fillPoly(m, [p], 255)
        return m

    outlines = [
        [(0.025,0.267),(0.116,0.263),(0.115,0.238),(0.141,0.201),(0.148,0.184),(0.184,0.174),(0.208,0.195),(0.229,0.228),(0.250,0.268),(0.258,0.308),(0.238,0.354),(0.194,0.373),(0.118,0.375),(0.082,0.378),(0.060,0.343),(0.030,0.318)],
        [(0.193,0.349),(0.226,0.322),(0.264,0.307),(0.296,0.306),(0.330,0.324),(0.379,0.365),(0.436,0.426),(0.501,0.510),(0.559,0.587),(0.612,0.661),(0.647,0.710),(0.650,0.730),(0.629,0.746),(0.610,0.743),(0.568,0.706),(0.494,0.656),(0.413,0.599),(0.344,0.547),(0.282,0.503),(0.231,0.464),(0.211,0.415)],
        [(0.251,0.206),(0.251,0.185),(0.271,0.181),(0.263,0.158),(0.276,0.146),(0.282,0.127),(0.306,0.109),(0.331,0.106),(0.330,0.088),(0.371,0.074),(0.391,0.099),(0.420,0.161),(0.442,0.210),(0.434,0.249),(0.412,0.273),(0.357,0.266),(0.302,0.244),(0.269,0.227)],
        [(0.366,0.314),(0.375,0.269),(0.401,0.236),(0.436,0.224),(0.473,0.226),(0.501,0.248),(0.523,0.283),(0.547,0.353),(0.582,0.444),(0.617,0.534),(0.647,0.605),(0.679,0.651),(0.678,0.667),(0.662,0.678),(0.642,0.674),(0.610,0.652),(0.568,0.596),(0.519,0.529),(0.465,0.454),(0.413,0.392),(0.385,0.351)],
        [(0.449,0.064),(0.464,0.040),(0.489,0.026),(0.515,0.034),(0.532,0.053),(0.531,0.030),(0.545,0.008),(0.574,0.006),(0.589,0.018),(0.588,0.035),(0.605,0.035),(0.598,0.066),(0.589,0.123),(0.575,0.183),(0.549,0.199),(0.517,0.180),(0.481,0.142),(0.458,0.099)],
        [(0.518,0.204),(0.533,0.180),(0.566,0.174),(0.591,0.194),(0.624,0.222),(0.658,0.268),(0.682,0.315),(0.710,0.404),(0.734,0.500),(0.747,0.588),(0.758,0.654),(0.752,0.677),(0.734,0.687),(0.714,0.679),(0.693,0.641),(0.669,0.592),(0.641,0.525),(0.613,0.456),(0.582,0.387),(0.550,0.318),(0.530,0.260)]
    ]
    removal = np.zeros((h, w), np.uint8)
    for points in outlines:
        removal = cv2.bitwise_or(removal, polygon(points))
    k = max(3, int(scale * 0.009) | 1)
    removal = cv2.dilate(removal, cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (k,k)))

    protected = polygon([(0.714,0.163),(0.754,0.158),(0.789,0.188),(0.854,0.285),(0.981,0.137),(1.0,0.137),(1.0,0.931),(0.802,0.932),(0.773,0.895),(0.778,0.567),(0.743,0.508),(0.710,0.421),(0.691,0.351),(0.666,0.271),(0.684,0.270),(0.720,0.323),(0.742,0.327),(0.722,0.253),(0.713,0.205)])
    protected[Y >= 0.756] = 255
    ear = (((X-0.425)/0.041)**2 + ((Y-0.719)/0.060)**2) <= 1
    protected[ear] = 255
    removal[protected > 0] = 0

    filled = cv2.inpaint(rgb, removal, max(3, int(scale*0.012)), cv2.INPAINT_TELEA).astype(np.float32)
    # A clean strip of real wood supplies grain to the reconstructed surface.
    phase = np.mod(X / 0.235, 2.0)
    triangular = 1.0 - np.abs(phase - 1.0)
    mapx = ((0.012 + 0.111*triangular)*w).astype(np.float32)
    mapy = ((0.411 + 0.511*Y)*h).astype(np.float32)
    wood = cv2.remap(rgb, mapx, mapy, cv2.INTER_LINEAR, borderMode=cv2.BORDER_REFLECT_101).astype(np.float32)
    low = cv2.GaussianBlur(filled, (0,0), max(1.0,scale*0.033))
    woodlow = cv2.GaussianBlur(wood, (0,0), max(1.0,scale*0.024))
    rebuilt = 0.64*woodlow + 0.36*low + (wood-woodlow)
    rebuilt += rng.normal(0, 0.65, (h,w,1)).astype(np.float32)
    a = cv2.GaussianBlur(removal.astype(np.float32)/255, (0,0), max(0.45, scale*0.0014))
    a[protected > 0] = 0
    canvas = rgb.astype(np.float32)*(1-a[...,None]) + np.clip(rebuilt,0,255)*a[...,None]

    # Reuse the source felt's fine structure, without retaining its orange color.
    patch = rgb[int(h*.325):int(h*.423), int(w*.426):int(w*.482)].astype(np.float32)
    gray = patch.mean(axis=2)
    gray -= cv2.GaussianBlur(gray, (0,0), max(0.6,scale*.002))
    gy = np.arange(h) % gray.shape[0]
    gx = np.arange(w) % gray.shape[1]
    cloth = gray[gy[:,None],gx[None,:]]
    fine = rng.normal(0,1,(h,w)).astype(np.float32)
    coarse = cv2.resize(rng.normal(0,1,(max(3,int(h*.06)),max(3,int(w*.06)))).astype(np.float32),(w,h),interpolation=cv2.INTER_CUBIC)
    mid = cv2.GaussianBlur(fine,(0,0),max(.5,scale*.002))
    texture = 1.8*cloth + 2.6*fine + 3.0*mid + 2.4*coarse
    fibers = np.zeros((h,w),np.float32)
    for _ in range(int(w*h*.105)):
        px = int(rng.integers(0,w)); py = int(rng.integers(0,h))
        length = rng.uniform(.0013,.0045)*scale
        ang = rng.normal(-1.05,.6)
        qx = int(np.clip(px+np.cos(ang)*length,0,w-1))
        qy = int(np.clip(py+np.sin(ang)*length,0,h-1))
        cv2.line(fibers,(px,py),(qx,qy),float(rng.uniform(-5.5,6.0)),1,cv2.LINE_AA)
    texture += fibers

    def geometry(cx,cy,rx,ry,angle=0):
        t = np.deg2rad(angle)
        u = ((X-cx)*np.cos(t)+(Y-cy)*np.sin(t))/rx
        v = (-(X-cx)*np.sin(t)+(Y-cy)*np.cos(t))/ry
        d = np.sqrt(u*u+v*v)
        soft = max(.004,1.05/(scale*min(rx,ry)))
        alpha = np.clip((1-d)/soft+.5,0,1)
        fringe = np.clip(1-d,0,soft*2)/(soft*2)
        alpha *= np.clip(.96 + .055*mid + .04*fine + .04*fringe,0,1)
        return u,v,d,alpha

    def layer(cx,cy,rx,ry,color,angle=0,shadow=True,plush=True):
        nonlocal canvas
        u,v,d,alpha = geometry(cx,cy,rx,ry,angle)
        if shadow:
            shifted = cv2.warpAffine(alpha,np.float32([[1,0,w*.006],[0,1,h*.011]]),(w,h))
            sh = cv2.GaussianBlur(shifted,(0,0),max(.6,scale*.008))*.23
            canvas *= 1-sh[...,None]
        relief = np.sqrt(np.clip(1-d*d,0,1))
        lighting = .70 + .31*relief - .12*u - .10*v
        lighting -= .08*np.exp(-((d-.91)/.07)**2)
        tex = texture if plush else texture*.22
        colored = np.array(color,np.float32)[None,None,:]*lighting[...,None]+tex[...,None]
        alpha[protected>0] = 0
        canvas = canvas*(1-alpha[...,None])+np.clip(colored,0,255)*alpha[...,None]
        return alpha

    # Back-to-front plush construction. Overlap shadows separate the limbs.
    layer(.298,.078,.064,.066,(134,86,49),-14)
    layer(.570,.078,.064,.066,(137,88,51),14)
    layer(.299,.080,.039,.041,(181,127,83),-14,False)
    layer(.570,.080,.039,.041,(181,127,83),14,False)
    layer(.247,.453,.075,.135,(143,91,53),-26)
    layer(.628,.449,.073,.131,(142,90,52),26)
    layer(.437,.484,.154,.174,(150,97,58),-2)
    layer(.437,.513,.109,.120,(175,119,76),-2,False)
    layer(.293,.670,.082,.081,(144,92,53),-16)
    layer(.576,.670,.080,.081,(144,92,53),16)
    layer(.287,.682,.051,.045,(179,126,84),-16,False)
    layer(.583,.682,.050,.045,(179,126,84),16,False)
    layer(.224,.490,.044,.048,(169,113,70),-26,False)
    layer(.650,.487,.043,.048,(169,113,70),26,False)
    layer(.436,.230,.172,.162,(152,99,60),-3)
    layer(.433,.288,.095,.066,(195,149,102),-2,True)

    def line(points,color,width,opacity=1):
        nonlocal canvas
        m = np.zeros((h,w),np.uint8)
        pts = np.array([(int(x*w),int(y*h)) for x,y in points],np.int32)
        cv2.polylines(m,[pts],False,255,max(1,int(width*scale)),cv2.LINE_AA)
        af = cv2.GaussianBlur(m.astype(np.float32)/255,(0,0),max(.25,scale*.0005))*opacity
        af[protected>0] = 0
        canvas = canvas*(1-af[...,None])+np.array(color,np.float32)*af[...,None]

    # Small, inset button eyes, with soft rim shading and reflected light.
    for ex,ey in [(.373,.229),(.500,.225)]:
        layer(ex,ey,.019,.022,(105,66,40),0,False)
        layer(ex,ey,.012,.015,(35,25,21),0,False,False)
        layer(ex-.0035,ey-.005,.0037,.0044,(215,201,176),0,False,False)
        layer(ex+.003,ey+.004,.0022,.0025,(89,66,47),0,False,False)
    layer(.434,.279,.025,.017,(55,34,25),-3,False,False)
    layer(.427,.273,.007,.0037,(133,95,66),-3,False,False)
    line([(.434,.294),(.434,.313)],(75,48,31),.0035,.85)
    line([(.434,.313),(.425,.321),(.413,.322),(.404,.316)],(80,52,34),.0028,.8)
    line([(.434,.313),(.444,.321),(.455,.321),(.464,.314)],(80,52,34),.0028,.8)

    # Fine recessed seams and tiny thread dashes, rather than drawn outlines.
    for cx,cy,rx,ry,start,end in [(.437,.513,.103,.114,35,145),(.287,.682,.047,.040,5,175),(.583,.682,.046,.040,5,175)]:
        angles = np.linspace(start,end,42)
        path = [(cx+rx*np.cos(np.deg2rad(t)),cy+ry*np.sin(np.deg2rad(t))) for t in angles]
        line(path,(113,75,48),.0015,.25)
        for j in range(0,len(path)-1,3):
            p,q=path[j],path[j+1]
            line([p,q],(207,156,109),.0014,.43)
    line([(.437,.392),(.437,.405),(.436,.414)],(101,64,40),.0018,.25)

    out = np.clip(canvas,0,255).astype(np.uint8)
    out[protected>0] = rgb[protected>0]
    return Image.fromarray(out)
replace the banana with a cat
magicbrush_train_82041_3 · replace / change · execution=passed
PASSinstr 4preserve 4quality 3
source
GPT-6.1-Sol output
MagicBrush target (reference only)

The banana was mostly replaced by a cat in the correct area, but parts of the banana/peel remain visible behind and around the cat. The unrelated toys and wooden background are largely preserved. The cat is recognizable but has a cartoon style and some blending/artifact issues, so visual quality is moderate.

l1=0.0590 · gain=0.0009 · mask_l1=0.0016 · preserve_l1=0.0938

reasoning / plan
{
 "visual_evidence": [
  "A peeled yellow-and-white plush banana occupies the right side.",
  "The background is warm-colored wood with predominantly vertical grain.",
  "A brown bear toy is at the upper left.",
  "A small white rabbit toy is near the bottom center.",
  "The toys have soft fabric surfaces and shadows falling toward the lower right."
 ],
 "target_object": "The peeled banana plush toy",
 "target_region": "The right side, including the white fruit, yellow peel flaps, and banana-shaped shadow",
 "editing_intent": "Replace the banana with a shaded, textured gray tabby cat plush while preserving the other toys and wooden background.",
 "editing_plan": [
  "Mask the banana using its visible outline, including the thin left peel flap.",
  "Remove it with inpainting and restore wood grain using pixels sampled from unobstructed wood in the same image.",
  "Construct a cat with rounded ears, a head, torso, paws, and curved tail.",
  "Shade its fabric surfaces and add tabby markings, an ivory belly, short fur fibers, and facial features.",
  "Add soft contact and cast shadows consistent with the existing lighting.",
  "Feather the replacement boundaries and preserve pixels outside the edited area."
 ],
 "preservation_constraints": [
  "Do not alter the bear.",
  "Do not alter the rabbit.",
  "Preserve the original image dimensions.",
  "Preserve the surrounding wood wherever it is not covered by the banana or replacement cat.",
  "Use only source-image pixels and procedurally synthesized pixels."
 ]
}
pixel code
def edit(image):
    import numpy as np
    import cv2
    from PIL import Image

    w, h = image.size
    s = float(min(w, h))
    original = np.asarray(image.convert('RGB')).copy()
    rng = np.random.default_rng(28)
    yy, xx = np.mgrid[0:h, 0:w].astype(np.float32)
    X, Y = xx / w, yy / h

    def polygon(points):
        m = np.zeros((h, w), np.uint8)
        p = np.asarray([(int(round(x * w)), int(round(y * h))) for x, y in points], np.int32)
        cv2.fillPoly(m, [p], 255, lineType=cv2.LINE_AA)
        return m

    # Follow both the narrow peeled flap and the large fruit/peel silhouette.
    removal = polygon([
        (.556, .177), (.572, .179), (.581, .213), (.607, .237),
        (.649, .271), (.690, .311), (.710, .359), (.746, .420),
        (.785, .467), (.815, .492), (.787, .414), (.752, .327),
        (.722, .247), (.713, .205), (.718, .179), (.733, .164),
        (.758, .161), (.788, .181), (.828, .232), (.874, .309),
        (.884, .340), (.884, .291), (.914, .241), (.953, .189),
        (.986, .137), (1.0, .159), (1.0, .594), (.971, .678),
        (.945, .770), (.918, .841), (.888, .903), (.875, .914),
        (.842, .921), (.809, .915), (.790, .898), (.778, .861),
        (.777, .784), (.789, .675), (.806, .583), (.821, .529),
        (.785, .500), (.748, .462), (.722, .421), (.705, .383),
        (.689, .342), (.667, .306), (.626, .274), (.588, .246),
        (.567, .218), (.557, .193)
    ])
    small_r = max(1, int(round(.004 * s)))
    removal = cv2.dilate(removal, cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2 * small_r + 1, 2 * small_r + 1)))
    # Include the diffuse banana shadow without widening the mask near the bear.
    shadow_r = max(1, int(round(.012 * s)))
    extended = cv2.dilate(removal, cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2 * shadow_r + 1, 2 * shadow_r + 1)))
    lower = Y > .245
    removal[lower] = extended[lower]
    filled = cv2.inpaint(original, removal, max(2, int(.014 * s)), cv2.INPAINT_TELEA).astype(np.float32)

    # Reintroduce real vertical wood detail into the broad inpainted region.
    x0, x1 = int(.592 * w), int(.706 * w)
    y0, y1 = int(.435 * h), int(.760 * h)
    patch = original[y0:max(y0 + 2, y1), x0:max(x0 + 2, x1)].astype(np.float32)
    ph, pw = patch.shape[:2]
    def reflected(v, length):
        limit = max(1, length - 1)
        t = np.mod(v, 2 * limit)
        return np.where(t <= limit, t, 2 * limit - t).astype(np.float32)
    mx = reflected(xx - .73 * w, pw)
    my = reflected(yy - .43 * h, ph)
    wood = cv2.remap(patch, mx, my, cv2.INTER_LINEAR, borderMode=cv2.BORDER_REFLECT_101)
    wood_detail = wood - cv2.GaussianBlur(wood, (0, 0), max(.5, .022 * s))
    illumination = cv2.GaussianBlur(filled, (0, 0), max(.5, .026 * s))
    distance = cv2.distanceTransform(removal, cv2.DIST_L2, 5)
    broad = np.clip((distance - .006 * s) / max(1.0, .020 * s), 0, 1)[..., None]
    restored = filled * (1 - broad) + np.clip(illumination + 1.12 * wood_detail, 0, 255) * broad
    restored += rng.normal(0, .65, (h, w, 1)).astype(np.float32)
    remove_alpha = cv2.GaussianBlur(removal.astype(np.float32) / 255, (0, 0), max(.4, .0013 * s))[..., None]
    canvas = original.astype(np.float32) * (1 - remove_alpha) + restored * remove_alpha

    # Correlated noise models the nap and slight unevenness of plush fabric.
    raw = rng.normal(0, 1, (h, w)).astype(np.float32)
    def normalized_blur(a, sx, sy=None):
        b = cv2.GaussianBlur(a, (0, 0), max(.25, sx), sigmaY=max(.25, sx if sy is None else sy))
        return b / max(float(b.std()), .0001)
    fine = normalized_blur(raw, .0007 * s)
    nap = normalized_blur(raw, .00065 * s, .0034 * s)
    mottling = normalized_blur(raw, .008 * s)
    fabric = 3.0 * fine + 2.5 * nap + 1.8 * mottling
    edge_noise = normalized_blur(raw, .002 * s)
    layers = []

    def ellipse_data(cx, cy, rx, ry, angle=0):
        ca, sa = np.cos(angle), np.sin(angle)
        dx, dy = X - cx, Y - cy
        u = (ca * dx + sa * dy) / rx
        v = (-sa * dx + ca * dy) / ry
        rr = np.sqrt(u * u + v * v)
        edge = (1 - rr) * min(rx * w, ry * h) + .16 * edge_noise
        a = np.clip(edge / max(.65, .0015 * s) + .5, 0, 1)
        z = np.sqrt(np.maximum(0, 1 - np.minimum(rr, 1) ** 2))
        lighting = np.clip(.70 + .29 * z - .13 * u - .17 * v, .40, 1.16)
        return a, lighting, u, v

    def add_ellipse(cx, cy, rx, ry, color, angle=0, markings=None, strength=.18):
        a, light, u, v = ellipse_data(cx, cy, rx, ry, angle)
        stripe = np.zeros_like(a)
        if markings == 'body':
            stripe = np.exp(-(np.sin(15 * v + 2.0 * u * u + .45 * mottling) / .32) ** 2)
        elif markings == 'head':
            forehead = np.exp(-(np.sin(11 * u + 1.8 * v) / .30) ** 2)
            forehead *= np.clip((-v - .12) * 2.5, 0, 1)
            cheeks = np.exp(-(np.sin(15 * v + 3 * np.abs(u)) / .30) ** 2)
            cheeks *= np.clip((np.abs(u) - .50) * 3.5, 0, 1)
            stripe = np.maximum(forehead, cheeks)
        layers.append((a, light, np.asarray(color, np.float32), stripe * strength))
        return a

    def rounded_polygon(points, color, markings=False):
        m = polygon(points).astype(np.float32) / 255
        m = cv2.GaussianBlur(m, (0, 0), max(.5, .0020 * s))
        d = cv2.distanceTransform((m > .48).astype(np.uint8), cv2.DIST_L2, 5)
        z = np.sqrt(np.clip(d / max(float(d.max()), 1), 0, 1))
        gx = cv2.Sobel(d, cv2.CV_32F, 1, 0, ksize=3) / 8
        gy = cv2.Sobel(d, cv2.CV_32F, 0, 1, ksize=3) / 8
        light = np.clip(.73 + .27 * z + .11 * gx + .15 * gy, .45, 1.16)
        stripe = np.exp(-(np.sin(Y * 100 + X * 7) / .30) ** 2) * .16 if markings else np.zeros_like(m)
        layers.append((m, light, np.asarray(color, np.float32), stripe))
        return m

    def cubic(p0, p1, p2, p3, count=70):
        t = np.linspace(0, 1, count, dtype=np.float32)[:, None]
        return (1-t)**3*np.asarray(p0) + 3*(1-t)**2*t*np.asarray(p1) + 3*(1-t)*t*t*np.asarray(p2) + t**3*np.asarray(p3)

    # Tail: rounded, curved, shaded, and striped rather than a flat polygon.
    tail = np.zeros((h, w), np.uint8)
    path = cubic((.900, .762), (.990, .793), (.990, .655), (.955, .533))
    ipath = np.round(path * np.array([w, h])).astype(np.int32)
    tail_width = max(2, int(.050 * s))
    cv2.polylines(tail, [ipath], False, 255, tail_width, cv2.LINE_AA)
    cv2.circle(tail, tuple(ipath[-1]), max(1, tail_width // 2), 255, -1, cv2.LINE_AA)
    tm = cv2.GaussianBlur(tail.astype(np.float32) / 255, (0, 0), max(.4, .0014 * s))
    td = cv2.distanceTransform((tm > .45).astype(np.uint8), cv2.DIST_L2, 5)
    tl = .65 + .40 * np.sqrt(np.clip(td / max(1, float(td.max())), 0, 1))
    ts = .22 * np.exp(-(np.sin(Y * 109 + X * 12) / .34) ** 2)
    layers.append((tm, tl, np.array([146, 140, 132], np.float32), ts))

    add_ellipse(.768, .813, .067, .052, (151, 145, 136), -.10, 'body', .12)
    add_ellipse(.902, .813, .067, .052, (151, 145, 136), .10, 'body', .12)
    add_ellipse(.836, .592, .109, .203, (147, 141, 133), .015, 'body', .20)
    rounded_polygon([(.710, .272), (.713, .209), (.719, .182), (.728, .176), (.742, .186), (.780, .235), (.793, .267)], (148, 142, 134), True)
    rounded_polygon([(.863, .265), (.883, .224), (.907, .182), (.917, .176), (.928, .190), (.942, .255), (.935, .287)], (139, 133, 126), True)
    rounded_polygon([(.728, .246), (.728, .201), (.737, .204), (.763, .244), (.758, .264)], (185, 138, 137))
    rounded_polygon([(.889, .253), (.913, .201), (.921, .217), (.926, .260), (.912, .273)], (177, 130, 130))
    add_ellipse(.742, .568, .042, .123, (153, 147, 139), .17, 'body', .19)
    add_ellipse(.925, .565, .041, .122, (141, 135, 127), -.14, 'body', .19)
    add_ellipse(.833, .604, .076, .151, (213, 207, 193), .02)
    add_ellipse(.825, .323, .130, .117, (159, 153, 144), -.015, 'head', .25)
    add_ellipse(.823, .391, .039, .027, (215, 208, 195))
    add_ellipse(.792, .366, .041, .030, (224, 216, 201), -.07)
    add_ellipse(.855, .367, .041, .030, (215, 207, 193), .07)

    silhouette = np.zeros((h, w), np.float32)
    for a, light, color, stripe in layers:
        silhouette = np.maximum(silhouette, a)

    # Shadows are displaced down-right, with a tighter contact component.
    transform = np.float32([[1, 0, .014 * w], [0, 1, .017 * h]])
    cast = cv2.warpAffine(silhouette, transform, (w, h), flags=cv2.INTER_LINEAR)
    cast = cv2.GaussianBlur(cast, (0, 0), max(.7, .014 * s))
    contact_transform = np.float32([[1, 0, .004 * w], [0, 1, .005 * h]])
    contact = cv2.warpAffine(silhouette, contact_transform, (w, h), flags=cv2.INTER_LINEAR)
    contact = cv2.GaussianBlur(contact, (0, 0), max(.5, .004 * s))
    shadow = np.clip(.24 * cast + .19 * contact, 0, .45)[..., None]
    canvas *= 1 - shadow * np.array([.72, .79, .88], np.float32)

    for a, light, color, stripe in layers:
        shade = light * (1 - stripe)
        pixels = color[None, None, :] * shade[..., None]
        pixels += fabric[..., None] + np.maximum(light - .90, 0)[..., None] * np.array([8, 7, 5], np.float32)
        alpha = a[..., None]
        canvas = canvas * (1 - alpha) + np.clip(pixels, 0, 255) * alpha

    # Individual low-contrast fibers supplement the multiscale fabric noise.
    fiber_image = canvas.copy()
    count = int(min(32000, max(2500, w * h * .050)))
    xs = rng.integers(0, w, count)
    ys = rng.integers(0, h, count)
    for px, py in zip(xs, ys):
        if silhouette[py, px] < .90:
            continue
        if Y[py, px] < .44:
            dx, dy = (X[py, px] - .825) / .130, (Y[py, px] - .323) / .117
        else:
            dx, dy = (X[py, px] - .836) / .109, (Y[py, px] - .592) / .203
        theta = np.arctan2(dy, dx) + rng.normal(0, .48)
        length = rng.uniform(.0017, .0050) * s
        qx = int(round(px + np.cos(theta) * length))
        qy = int(round(py + np.sin(theta) * length))
        color = np.clip(canvas[py, px] + rng.uniform(-17, 20), 0, 255)
        cv2.line(fiber_image, (int(px), int(py)), (qx, qy), tuple(float(v) for v in color), 1, cv2.LINE_AA)
    fa = (.30 * silhouette)[..., None]
    canvas = canvas * (1 - fa) + fiber_image * fa

    def feature_ellipse(cx, cy, rx, ry, color, angle=0, textured=False):
        nonlocal canvas
        a, light, u, v = ellipse_data(cx, cy, rx, ry, angle)
        c = np.asarray(color, np.float32)[None, None, :] * light[..., None]
        if textured:
            c = c + fabric[..., None] * .45
        canvas = canvas * (1 - a[..., None]) + np.clip(c, 0, 255) * a[..., None]

    # Glass-like eyes with warm irises, narrow pupils and upper-left highlights.
    for ex in (.779, .866):
        feature_ellipse(ex, .314, .019, .025, (48, 42, 35))
        feature_ellipse(ex, .314, .0130, .0185, (167, 131, 72))
        feature_ellipse(ex, .315, .0073, .0190, (14, 13, 12))
        feature_ellipse(ex - .005, .306, .0043, .0057, (245, 243, 229))
        feature_ellipse(ex + .004, .322, .0018, .0025, (165, 175, 171))

    nose = polygon([(.807, .350), (.816, .344), (.833, .345), (.843, .351), (.836, .360), (.825, .368), (.815, .359)]).astype(np.float32) / 255
    nose = cv2.GaussianBlur(nose, (0, 0), max(.35, .0011 * s))
    nc = np.empty((h, w, 3), np.float32)
    nc[:] = (173, 113, 115)
    nc += (fabric * .40 + 9 * np.clip((.367 - Y) / .023, 0, 1))[..., None]
    canvas = canvas * (1 - nose[..., None]) + nc * nose[..., None]

    def thread(points, color, width=.0016, opacity=.8):
        nonlocal canvas
        m = np.zeros((h, w), np.uint8)
        p = np.round(np.asarray(points) * np.array([w, h])).astype(np.int32)
        cv2.polylines(m, [p], False, 255, max(1, int(round(width * s))), cv2.LINE_AA)
        a = cv2.GaussianBlur(m.astype(np.float32) / 255, (0, 0), max(.25, .0006 * s))
        a = a[..., None] * opacity
        canvas = canvas * (1 - a) + np.asarray(color, np.float32)[None, None, :] * a

    thread(cubic((.825, .365), (.824, .374), (.825, .378), (.825, .382)), (77, 63, 60), .0016, .88)
    thread(cubic((.825, .380), (.814, .393), (.799, .392), (.793, .384)), (84, 71, 65), .0015, .83)
    thread(cubic((.825, .380), (.836, .393), (.851, .392), (.857, .384)), (84, 71, 65), .0015, .83)
    for direction in (-1, 1):
        for offset in (-.011, .001, .013):
            start = (.825 + direction * .047, .369 + offset)
            end = (.825 + direction * .115, .370 + offset * 1.7)
            points = cubic(start, (.825 + direction * .074, .366 + offset), (.825 + direction * .097, .365 + offset * 1.5), end)
            thread(points, (202, 196, 180), .00125, .72)
    for px in (.768, .902):
        for off in (-.019, .008):
            points = cubic((px + off, .822), (px + off - .004, .831), (px + off - .003, .839), (px + off + .002, .844))
            thread(points, (100, 93, 84), .0013, .40)
    # A restrained sewn edge on the belly reinforces the fabric construction.
    seam = cubic((.787, .523), (.753, .621), (.781, .713), (.812, .742))
    thread(seam, (166, 158, 142), .0011, .22)

    return Image.fromarray(np.uint8(np.clip(canvas, 0, 255)), 'RGB')