质量筛选后的候选:1. In the main overview’s central ‘Single-Concept Customized Models’ column, add a horizontally-oriented light-yellow rectangle with a light-orange solid border containing the single-line black text “DreamBooth”; this new box is placed directly below the light-green “LoRA” block, and the existing black rightward connector now enters its left edge and exits its right edge toward the light-blue “MC²” block.
{
"visual_evidence": [
- "The central column contains a peach “Textual Inversion” box above a light-green “LoRA” box.",
- "A blank lower slot sits beneath LoRA, aligned with the arrow from the cat reference images.",
- "A curved black connector leads from this lower slot toward the light-blue “MC²” box.",
- "The diagram uses pale rectangular fills, thin colored borders, and black text."
- ],
- "target_object": "The empty model slot directly below LoRA.",
- "target_region": "The lower part of the central Single-Concept Customized Models column, between the cat-reference arrow and the curved connector to MC².",
- "editing_intent": "Add a light-yellow, light-orange-bordered rectangle labeled “DreamBooth” and connect its left and right edges to the existing lower-row connectors.",
- "editing_plan": [
- "Locate the lower model slot using coordinates proportional to the image dimensions.",
- "Clear only the existing lower incoming arrowhead on the white diagram background and redraw it so it meets the new box.",
- "Extend the existing outgoing connector to the box’s right edge.",
- "Draw a rectangle matching the dimensions and flat diagram styling of the other model boxes.",
- "Center the single-line black DreamBooth label inside the rectangle.",
- "Antialias the edited shapes and composite only the local overlay, preserving the surrounding image."
- ],
- "preservation_constraints": [
- "Keep all reference and generated photographs unchanged.",
- "Keep Textual Inversion, LoRA, MC², and their labels unchanged.",
- "Preserve both column captions and the handwritten prompt.",
- "Preserve the existing curved connector toward MC² apart from its short extension to the new box.",
- "Do not add shadows or photographic texture to the flat diagram."
+ "The large foreground figure wears a green jacket with cream zipper trim, orange accents, and dark gloves.",
+ "The smaller airborne figure wears a blurred blue top, red pants, and yellow mittens.",
+ "The panda and both welcome captions are separate from the two figures."
+ ],
+ "target_object": "The upper-body garments of the two human figures",
+ "target_region": "The foreground figure’s green jacket at the bottom center and the airborne figure’s blue torso and sleeves in the upper right.",
+ "editing_intent": "Recolor both tops red while retaining their existing garment shapes, fabric shading, and level of focus.",
+ "editing_plan": [
+ "Draw separate garment guides using relative coordinates.",
+ "Refine the guides using the source fabric colors to exclude skin, trim, gloves, pants, and snow.",
+ "Shift the selected fabric chroma toward red in Lab color space while retaining its lightness.",
+ "Blend with a narrow edge on the foreground jacket and a softer edge on the blurred distant top."
+ ],
+ "preservation_constraints": [
+ "Keep the figures’ faces, hats, goggles, gloves, and pants unchanged.",
+ "Retain the foreground jacket’s zipper trim, dark opening, orange accents, and fabric folds.",
+ "Leave the snowboard, panda, snow, background, border, and both captions unchanged."
]
}
def edit(image):
import cv2
import numpy as np
- from PIL import Image, ImageDraw
+ from PIL import Image
w, h = image.size
- ss = 4
- x0 = int(np.floor(0.320 * w))
- y0 = int(np.floor(0.590 * h))
- x1 = int(np.ceil(0.502 * w))
- y1 = int(np.ceil(0.766 * h))
- pw, ph = x1 - x0, y1 - y0
- overlay = Image.new('RGBA', (pw * ss, ph * ss), (0, 0, 0, 0))
- draw = ImageDraw.Draw(overlay)
+ pixels = np.array(image.convert('RGB'), dtype=np.uint8)
+ rgb = pixels.astype(np.float32) / 255.0
+ lab = cv2.cvtColor(rgb, cv2.COLOR_RGB2LAB)
+ light, a, b = cv2.split(lab)
+ r, g, blue = [channel.astype(np.float32) for channel in cv2.split(pixels)]
+
+ def smooth(lo, hi, x):
+ t = np.clip((x - lo) / (hi - lo), 0.0, 1.0)
+ return t * t * (3.0 - 2.0 * t)
+
+ def guide(polygons, feather):
+ canvas = np.zeros((h, w), dtype=np.uint8)
+ scale = np.array([w - 1, h - 1], dtype=np.float32)
+ for poly in polygons:
+ points = np.rint(np.array(poly, dtype=np.float32) * scale).astype(np.int32)
+ cv2.fillPoly(canvas, [points], 255)
+ return cv2.GaussianBlur(canvas.astype(np.float32) / 255.0, (0, 0),
+ sigmaX=max(0.4, feather * w),
+ sigmaY=max(0.4, feather * h))
+
+ foreground = guide([[
+ (.212,.987),(.219,.964),(.232,.927),(.251,.895),(.276,.865),
+ (.302,.836),(.310,.804),(.341,.806),(.369,.818),(.412,.830),
+ (.429,.791),(.450,.780),(.471,.794),(.479,.815),(.475,.836),
+ (.497,.854),(.522,.880),(.547,.907),(.558,.913),(.556,.925),
+ (.542,.938),(.528,.958),(.518,.973),(.505,.970),(.482,.954),
+ (.458,.932),(.462,.966),(.476,1.015),(.239,1.015)
+ ]], .0015)
+ green_evidence = smooth(2.5, 15.0, -a) * smooth(3.0, 23.0, g - r)
+ fg = foreground * green_evidence
+
+ distant = guide([
+ [(.690,.263),(.709,.257),(.738,.262),(.758,.262),(.761,.277),
+ (.750,.297),(.730,.304),(.704,.295),(.691,.286)],
+ [(.710,.296),(.729,.278),(.751,.277),(.756,.299),(.768,.313),
+ (.783,.322),(.799,.312),(.812,.325),(.820,.349),(.807,.372),
+ (.788,.377),(.771,.365),(.750,.359),(.729,.346),(.708,.336)],
+ [(.784,.327),(.804,.316),(.817,.334),(.829,.358),(.831,.387),
+ (.827,.415),(.818,.433),(.803,.440),(.784,.433),(.779,.415),
+ (.781,.385),(.773,.359)]
+ ], .0045)
+ cool_evidence = np.minimum(blue - r, 1.65 * (g - r))
+ bg = (distant * smooth(4.0, 32.0, cool_evidence)
+ * smooth(-13.0, 1.0, blue - g) * (1.0 - smooth(59.0, 79.0, light)))
+
+ fg_red = np.clip(29.0 + .48 * np.maximum(-a, 0.0), 29.0, 54.0)
+ fg_red *= np.clip((light - 4.0) / 23.0, .40, 1.0)
+ bg_red = np.clip(23.0 + .33 * cool_evidence, 23.0, 42.0)
+ edited = lab.copy()
+ edited[:, :, 1] = a + fg * (fg_red - a) + bg * (bg_red - a)
+ edited[:, :, 2] = b + fg * (.56 * fg_red + 2.0 - b) + bg * (.55 * bg_red - b)
+
+ converted = cv2.cvtColor(edited, cv2.COLOR_LAB2RGB)
+ converted = np.rint(np.clip(converted, 0.0, 1.0) * 255.0).astype(np.uint8)
+ changed = (fg + bg) > 1e-4
+ pixels[changed] = converted[changed]
+ result = Image.fromarray(pixels)
+ if 'A' in image.getbands():
+ result.putalpha(image.getchannel('A'))
+ return result
质量筛选后的候选:1. At the bottom node ‘x_H[3]’ in the final h = H column, append a solid red triangular arrow-head to the existing horizontal red dashed line so that it becomes a complete right-pointing dashed red arrow leaving the diagram.
- def point(rx, ry):
- return (int(round((rx * w - x0) * ss)),
- int(round((ry * h - y0) * ss)))
-
- def bounds(left, top, right, bottom):
- return (*point(left, top), *point(right, bottom))
-
- stroke = max(1, int(round(0.00125 * w * ss)))
- border_width = max(1, int(round(0.001875 * w * ss)))
- black = (0, 0, 0, 255)
- orange = (248, 204, 173, 255)
- yellow = (255, 248, 211, 255)
-
- # Copy the clean white diagram background over only the old arrowhead.
- sample = np.asarray(image.convert('RGB'))[
- max(0, int(0.570 * h)):max(1, int(0.580 * h)),
- max(0, int(0.322 * w)):max(1, int(0.336 * w))
- ]
- if sample.size:
- bg = tuple(int(v) for v in np.median(sample.reshape(-1, 3), axis=0))
- else:
- bg = (255, 255, 255)
- draw.rectangle(bounds(0.326875, 0.668750, 0.339375, 0.693750),
- fill=bg + (255,))
-
- # Extend the incoming shaft and place its arrowhead at the new left edge.
- draw.line([point(0.325000, 0.681250),
- point(0.339375, 0.681250)], fill=black, width=stroke)
- draw.polygon([
- point(0.339375, 0.681250),
- point(0.331875, 0.671875),
- point(0.333125, 0.681250),
- point(0.331875, 0.690625)
- ], fill=black)
-
- # Retain the original outgoing curve and bridge its small gap to the box.
- draw.line([point(0.494375, 0.659375),
- point(0.498750, 0.659375)], fill=black, width=stroke)
-
- left, top, right, bottom = 0.339375, 0.596875, 0.494375, 0.756250
- draw.rectangle(bounds(left, top, right, bottom),
- fill=yellow, outline=orange, width=border_width)
-
- # Render a serif-like label with OpenCV's built-in font; no font files needed.
- text = 'DreamBooth'
- font = cv2.FONT_HERSHEY_TRIPLEX
- font_scale = float(ss)
- font_thickness = ss
- (raw_w, raw_h), baseline = cv2.getTextSize(
- text, font, font_scale, font_thickness)
- padding = 3 * ss
- glyphs = np.zeros((raw_h + baseline + 2 * padding,
- raw_w + 2 * padding), dtype=np.uint8)
- cv2.putText(glyphs, text, (padding, padding + raw_h), font,
- font_scale, 255, font_thickness, cv2.LINE_AA)
- ys, xs = np.nonzero(glyphs)
- glyphs = glyphs[ys.min():ys.max() + 1, xs.min():xs.max() + 1]
- label_w = max(1, int(round(0.1325 * w * ss)))
- label_h = max(1, int(round(0.0500 * h * ss)))
- glyphs = cv2.resize(glyphs, (label_w, label_h), interpolation=cv2.INTER_AREA)
- mask = Image.fromarray(glyphs, mode='L')
- center_x = ((left + right) * 0.5 * w - x0) * ss
- center_y = ((top + bottom) * 0.5 * h - y0) * ss
- label_x = int(round(center_x - label_w * 0.5))
- label_y = int(round(center_y - label_h * 0.5))
- overlay.paste(black, (label_x, label_y), mask)
-
- # Supersampling softens only the added edges, not the source photographs.
- resampling = getattr(Image, 'Resampling', Image)
- overlay = overlay.resize((pw, ph), resampling.LANCZOS)
- result = image.convert('RGBA')
- result.alpha_composite(overlay, dest=(x0, y0))
- return result if image.mode == 'RGBA' else result.convert('RGB')
质量筛选后的候选:1. Inside the “Multi Modal Rationales Generation” column, at the very top of the prompt area, add a light-yellow rectangle with a thin DASHED golden-yellow border; it contains centred black text reading “Triggering Prompts” and serves as a header above the list of sub-prompts.
-2. Add a medium-grey dashed arrow that starts at the right edge of the dark-grey “Multi Modal Model” rectangle and points up-and-to-the-right toward the light-blue rounded rectangle labelled “Rationale 1”, visually indicating the generation flow.
-3. Insert two medium-grey dashed arrows: one leaving the centre-right of the dark-grey “Multi Modal Model” rectangle and angling slightly upward toward the middle light-blue rectangle “Rationale 2”, and another leaving the lower-right of the model and angling slightly downward toward the bottom light-blue rectangle “Rationale N”, thereby completing the visual connections to all rationale outputs.
{
+2. At the upper node ‘x₃[1]’ in the h = 3 rectangle, add a solid red triangular arrow-head so that the existing horizontal red dashed line becomes a complete right-pointing dashed red arrow exiting the circle toward the next layer.
+
+3. In the h = 2 column of the main diagram, insert a white vertical rectangle with a black solid outline that houses two medium-grey circles labelled ‘x₂[1]’ (top) and ‘x₂[2]’ (bottom). Two red dashed horizontal arrows, each annotated ‘1/2’, run through the centres of these circles from the left and exit the rectangle on the right with solid red triangular arrow-heads, while two solid blue diagonal arrows enter the circles from the h = 1 column. Place the caption ‘ϕ₂[1]’ beneath this rectangle.
{
"visual_evidence": [
- "The left column is titled “Multi Modal Rationales Generation”.",
- "The prompt list contains “Counting,”, “Position,” and “Contextual”, with blank space above it.",
- "A tall dark-grey “Multi Modal Model” rectangle sits between the prompts and three blue rationale boxes.",
- "“Rationale 1”, “Rationale 2”, and “Rationale N” are vertically stacked to the model’s right.",
- "A faint diagonal dashed connector already extends toward the bottom rationale."
- ],
- "target_object": "The prompt header area and the outgoing connectors from the Multi Modal Model.",
- "target_region": "The upper-left prompt area and the narrow white corridor between the model and the three rationale boxes.",
- "editing_intent": "Add the yellow “Triggering Prompts” header and three clearly positioned grey dashed generation arrows, replacing the faint bottom connector with the requested lower-right connection.",
- "editing_plan": [
- "Mask and inpaint only the faint existing bottom connector in the white outgoing-arrow corridor.",
- "Draw a light-yellow rectangular header above the sub-prompts with a thin dashed golden-yellow outline.",
- "Center black “Triggering Prompts” text inside the header using an embedded font.",
- "Draw three medium-grey dashed arrows from the model’s right edge toward the corresponding rationale boxes.",
- "Antialias the new graphics and preserve all other diagram content."
- ],
- "preservation_constraints": [
- "Keep all existing column frames, titles, labels, and rationale boxes unchanged.",
- "Preserve the prompt list, plus sign, and Image(s) rectangle.",
- "Do not alter the model rectangle or its text.",
- "Keep the entire encoding, retrieval, fusion, and answer sections unchanged.",
- "Match the source’s clean, flat diagram style without adding photographic texture or shadows."
+ "The h = 2 heading sits above an incomplete upper column containing damaged node labels and no enclosing rectangle.",
+ "The neighboring upper columns contain white, black-outlined rectangles with grey circular nodes.",
+ "Red dashed connections and 1/2 annotations are already visible on both sides of the missing h = 2 nodes.",
+ "The upper h = 3 node has a rightward red dashed segment without a terminal arrow-head.",
+ "The bottom h = H node needs a completed rightward red dashed output arrow.",
+ "The caption ϕ₂[1] is already visible beneath the missing upper rectangle."
+ ],
+ "target_object": "The missing upper h = 2 node container and the two specified red output arrows.",
+ "target_region": "The upper-middle h = 2 column, the right side of x₃[1], and the right side of the bottom x_H[3] node.",
+ "editing_intent": "Restore the h = 2 rectangle and its two labelled grey nodes, complete their annotated red dashed connections and blue incoming arrows, and add the two requested red terminal arrow-heads.",
+ "editing_plan": [
+ "Sample the existing diagram's grey, red, blue, and outline colours.",
+ "Extract clean node lettering and a subscript 2 from existing nodes in the same image.",
+ "Cover the damaged h = 2 area with a white, black-outlined rectangle.",
+ "Restore the connections through this rectangle, add two blue diagonal incoming arrows, and draw the grey nodes with corrected labels.",
+ "Preserve the existing 1/2 annotations and ϕ₂[1] caption.",
+ "Extend the specified red dashed output segments and finish them with solid triangular arrow-heads.",
+ "Render new geometry with antialiased edges and composite only the edited pixels."
+ ],
+ "preservation_constraints": [
+ "Keep all headings, fraction annotations, and existing captions unchanged.",
+ "Preserve the h = 1, h = 3, and h = H node circles and labels.",
+ "Preserve the lower h = 2 node and its rectangle.",
+ "Keep existing connections outside the small edited regions.",
+ "Match the original flat mathematical-diagram styling rather than adding photographic shadows or texture."
]
}
@@ -148,224 +126,290 @@ def edit(image):
import math
import numpy as np
import cv2
- from PIL import Image, ImageDraw, ImageFont
+ from PIL import Image, ImageDraw
+ original = image.convert('RGB')
w, h = image.size
- original_mode = image.mode
- base = image.convert('RGB')
- arr = np.array(base)
+ a = np.asarray(original)
+ scale = 3
+ overlay = Image.new('RGBA', (w * scale, h * scale), (0, 0, 0, 0))
+ draw = ImageDraw.Draw(overlay)
+
+ def colour_median(condition, fallback):
+ values = a[condition]
+ if len(values) == 0:
+ return fallback
+ return tuple(int(v) for v in np.median(values, axis=0))
+
+ red = colour_median((a[:, :, 0] > 190) & (a[:, :, 1] < 110) & (a[:, :, 2] < 110), (239, 49, 41))
+ blue = colour_median((a[:, :, 2] > 145) & (a[:, :, 0] < 130) & (a[:, :, 1] > 65) & (a[:, :, 1] < 155), (78, 111, 193))
+ yy, xx = np.mgrid[0:h, 0:w]
+ source_radius = w * 0.025
+ source_disk = ((xx - w * 0.128125) ** 2 + (yy - h * 0.2390625) ** 2) < (source_radius * 0.9) ** 2
+ neutral = (np.max(a, axis=2).astype(float) - np.min(a, axis=2).astype(float)) < 8
+ grey = colour_median(source_disk & neutral & (a[:, :, 0] > 160) & (a[:, :, 0] < 235), (204, 204, 204))
+ black = (22, 22, 22)
- # Remove only the old faint diagonal connector, not the model edge.
- corridor = np.zeros((h, w), dtype=np.uint8)
def p(x, y):
- return (int(round(x * w)), int(round(y * h)))
- cv2.line(corridor, p(0.2446, 0.445), p(0.2625, 0.638), 255,
- max(3, int(round(h * 0.008))))
- tip = np.array([p(0.2585, 0.620), p(0.2655, 0.620),
- p(0.2625, 0.644)], dtype=np.int32)
- cv2.fillPoly(corridor, [tip], 255)
- channels = arr.astype(np.int16)
- neutral = channels.max(axis=2) - channels.min(axis=2) < 28
- visible = channels.mean(axis=2) < 253
- mask = np.where((corridor > 0) & neutral & visible, 255, 0).astype(np.uint8)
- radius = max(1, int(round(h * 0.0016)))
- kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,
- (radius * 2 + 1, radius * 2 + 1))
- mask = cv2.dilate(mask, kernel)
- allowed = np.zeros_like(mask)
- x0, y0 = p(0.245, 0.445)
- x1, y1 = p(0.269, 0.647)
- allowed[y0:y1, x0:x1] = 255
- mask = cv2.bitwise_and(mask, allowed)
- if np.any(mask):
- arr = cv2.inpaint(arr, mask, max(2, int(round(h * 0.0047))),
- cv2.INPAINT_TELEA)
- base = Image.fromarray(arr)
-
- # Supersampled transparent graphics retain the original pixels elsewhere.
- supersample = 3
- W, H = w * supersample, h * supersample
- layer = Image.new('RGBA', (W, H), (0, 0, 0, 0))
- draw = ImageDraw.Draw(layer)
- def q(x, y):
- return (x * W, y * H)
- def dashed_segment(a, b, color, width, dash, gap):
- dx, dy = b[0] - a[0], b[1] - a[1]
- length = math.hypot(dx, dy)
- if length == 0:
+ return (x * w * scale, y * h * scale)
+
+ def line(start, end, colour, width):
+ draw.line([p(*start), p(*end)], fill=colour + (255,), width=max(1, round(width * w * scale)))
+
+ def head(tip, direction, colour, length=0.0125, breadth=0.013):
+ tx, ty = p(*tip)
+ dx, dy = direction
+ norm = math.hypot(dx, dy)
+ if norm == 0:
return
- ux, uy = dx / length, dy / length
- distance = 0.0
- while distance < length:
- end = min(distance + dash, length)
- draw.line([(a[0] + ux * distance, a[1] + uy * distance),
- (a[0] + ux * end, a[1] + uy * end)],
- fill=color, width=width)
- distance += dash + gap
-
- left, top = q(0.012, 0.208)
- right, bottom = q(0.1768, 0.299)
- fill = (255, 248, 211, 255)
- gold = (219, 177, 39, 255)
- draw.rectangle((left, top, right, bottom), fill=fill)
- border_width = max(1, int(round(H * 0.0018)))
- dash = W * 0.0035
- gap = W * 0.0022
- corners = [(left, top), (right, top), (right, bottom), (left, bottom)]
- for index in range(4):
- dashed_segment(corners[index], corners[(index + 1) % 4],
- gold, border_width, dash, gap)
-
- label = 'Triggering Prompts'
- try:
- font = ImageFont.load_default(size=max(12, int(round(H * 0.035))))
- except TypeError:
- font = ImageFont.load_default()
- bbox = font.getbbox(label)
- tw, th = bbox[2] - bbox[0], bbox[3] - bbox[1]
- text_mask = Image.new('L', (max(1, tw), max(1, th)), 0)
- ImageDraw.Draw(text_mask).text((-bbox[0], -bbox[1]), label,
- font=font, fill=255)
- desired_height = H * 0.0295
- ratio = min(desired_height / max(1, th),
- (right - left) * 0.89 / max(1, tw))
- text_mask = text_mask.resize((max(1, int(round(tw * ratio))),
- max(1, int(round(th * ratio)))),
- Image.Resampling.LANCZOS)
- tx = int(round((left + right - text_mask.width) / 2))
- ty = int(round((top + bottom - text_mask.height) / 2))
- layer.paste((0, 0, 0, 255), (tx, ty), text_mask)
- draw = ImageDraw.Draw(layer)
-
- grey = (133, 133, 133, 255)
- line_width = max(1, int(round(H * 0.0022)))
- def arrow(start, end):
- a, b = q(*start), q(*end)
- dx, dy = b[0] - a[0], b[1] - a[1]
+ dx, dy = dx / norm, dy / norm
+ length_px = length * w * scale
+ half_width = breadth * w * scale / 2
+ bx, by = tx - dx * length_px, ty - dy * length_px
+ draw.polygon([(tx, ty), (bx - dy * half_width, by + dx * half_width), (bx + dy * half_width, by - dx * half_width)], fill=colour + (255,))
+
+ def dashed(start, end, colour=red, width=0.0025):
+ x0, y0 = start[0] * w, start[1] * h
+ x1, y1 = end[0] * w, end[1] * h
+ dx, dy = x1 - x0, y1 - y0
length = math.hypot(dx, dy)
- ux, uy = dx / length, dy / length
- head_length = H * 0.0125
- head_half_width = H * 0.0053
- neck = (b[0] - ux * head_length, b[1] - uy * head_length)
- dashed_segment(a, neck, grey, line_width,
- W * 0.0038, W * 0.0024)
- draw.polygon([b,
- (neck[0] - uy * head_half_width,
- neck[1] + ux * head_half_width),
- (neck[0] + uy * head_half_width,
- neck[1] - ux * head_half_width)], fill=grey)
-
- arrow((0.2448, 0.321), (0.2683, 0.256))
- arrow((0.2448, 0.447), (0.2680, 0.422))
- arrow((0.2448, 0.599), (0.2683, 0.630))
-
- layer = layer.resize((w, h), Image.Resampling.LANCZOS)
- result = Image.alpha_composite(base.convert('RGBA'), layer)
- if original_mode == 'RGBA':
- result.putalpha(image.getchannel('A'))
- return result
- return result.convert('RGB')
质量筛选后的候选:1. On the bottom timeline, just to the right of the orange circled event marker “iii”, add a light-beige (cream-colored) horizontally oriented rounded rectangle outlined with a solid black border and containing the single uppercase word “PRE” in black text.
-
-2. On the bottom timeline, immediately to the right of the first bold-dashed vertical separator – i.e., between the two downward dashed “<3 ns” arrows that link “ACT RREF” (on the left) and “ACT RCOM” (on the right) – insert one light-beige horizontally oriented rounded rectangle with a solid black border containing the uppercase text “PRE” in black.
{
"visual_evidence": [
- "The bottom timeline contains cream-colored ACT RREF and ACT RCOM command boxes.",
- "An empty command-sized gap lies between those boxes, aligned with the intermediate timeline tick and the two dashed '<3 ns' intervals.",
- "The orange circled 'iii' marker is near the right end of the timeline, with empty space immediately to its right.",
- "The diagram uses flat fills, crisp outlines, and black command text."
- ],
- "target_object": "Two new PRE command labels on the bottom timeline",
- "target_region": "The empty slot between ACT RREF and ACT RCOM, and the empty slot immediately right of the orange circled iii marker",
- "editing_intent": "Add two horizontally oriented cream rounded rectangles, each with a solid black border and centered uppercase PRE text.",
- "editing_plan": [
- "Preserve the source image and identify the two empty command-label positions using relative coordinates.",
- "Render both cream rounded rectangles with antialiased solid black borders.",
- "Render centered black PRE text using a bundled Pillow font without reading external files.",
- "Composite only the new label pixels over the source, leaving the timeline and all existing annotations unchanged."
- ],
- "preservation_constraints": [
- "Do not alter the orange circled event markers.",
- "Preserve ACT RREF, ACT RCOM, both '<3 ns' annotations, and the tRAS annotation.",
- "Preserve the timeline, its ticks, and all vertical separators.",
- "Do not change any circuit diagrams, formulas, or headings.",
- "Keep the clean, flat infographic style; do not add photographic shading or shadows."
+ "A long-haired dark cat is lying across the lower and middle part of the image.",
+ "The cat has a visible head on the left and a large furry body extending to the right.",
+ "The background includes a laptop and couch that should remain unchanged.",
+ "The cat fur is mostly dark brown/black with lighter gray-brown highlights."
+ ],
+ "target_object": "cat",
+ "target_region": "the furry animal spanning the lower half of the image, with the head on the left and body across the center-right",
+ "editing_intent": "Change the cat fur color to purple while preserving fur texture, shadows, highlights, and the surrounding laptop/background.",
+ "editing_plan": [
+ "Convert the input PIL image to an RGB NumPy array.",
+ "Build a foreground mask for the cat using relative elliptical and polygonal regions matching the visible head, body, and lower fur.",
+ "Refine the mask using color and brightness constraints to avoid recoloring blue labels, screen highlights, and background regions.",
+ "Clean the mask with morphological closing/opening and feather its edges for natural blending.",
+ "Recolor only masked pixels by shifting them toward a purple hue while preserving luminance and fur texture.",
+ "Composite the recolored pixels back over the original image using the feathered mask.",
+ "Return the edited result as a PIL Image."
+ ],
+ "preservation_constraints": [
+ "Do not change the laptop screen, keyboard/base, stickers, couch, or background.",
+ "Preserve the cat's fur texture, fine strands, shadows, and highlights.",
+ "Do not create flat cartoon-like color fills.",
+ "Do not alter the image size or crop the image."
]
}
def edit(image):
- from PIL import Image, ImageDraw, ImageFont
+ from PIL import Image
+ import numpy as np
+ import cv2
- w, h = image.size
- original_mode = image.mode
- result = image.convert('RGBA').copy()
- supersample = 4
-
- # The first box occupies the intermediate command slot shared by
- # the two <3 ns intervals. The second is immediately right of iii.
- boxes = [
- (0.139375, 0.859375, 0.181875, 0.9234375),
- (0.750625, 0.859375, 0.794375, 0.9234375),
- ]
-
- for normalized_box in boxes:
- left = round(normalized_box[0] * w)
- top = round(normalized_box[1] * h)
- right = round(normalized_box[2] * w)
- bottom = round(normalized_box[3] * h)
- bw = max(1, right - left)
- bh = max(1, bottom - top)
- padding = max(2, round(0.0046875 * h))
- pw = bw + 2 * padding
- ph = bh + 2 * padding
- patch = Image.new('RGBA', (pw * supersample, ph * supersample), (0, 0, 0, 0))
- draw = ImageDraw.Draw(patch)
-
- x0 = padding * supersample
- y0 = padding * supersample
- x1 = (padding + bw) * supersample - 1
- y1 = (padding + bh) * supersample - 1
- border = max(1, round(0.003125 * h * supersample))
- radius = max(border, round(0.009375 * h * supersample))
- draw.rounded_rectangle(
- (x0, y0, x1, y1),
- radius=radius,
- fill=(255, 239, 218, 255),
- outline=(0, 0, 0, 255),
- width=border
- )
-
- # load_default uses Pillow's bundled font, not an external file.
- font_size = max(1, round(0.046875 * h * supersample))
- try:
- font = ImageFont.load_default(size=font_size)
- except TypeError:
- font = ImageFont.load_default()
- bbox = font.getbbox('PRE')
- tw = max(1, bbox[2] - bbox[0])
- th = max(1, bbox[3] - bbox[1])
- text_mask = Image.new('L', (tw + 4, th + 4), 0)
- td = ImageDraw.Draw(text_mask)
- td.text((2 - bbox[0], 2 - bbox[1]), 'PRE', font=font, fill=255)
- ink_bounds = text_mask.getbbox()
- if ink_bounds:
- text_mask = text_mask.crop(ink_bounds)
-
- desired_height = max(1, round(0.034375 * h * supersample))
- max_width = max(1, round((bw - 0.01375 * w) * supersample))
- factor = min(desired_height / text_mask.height, max_width / text_mask.width)
- text_mask = text_mask.resize(
- (max(1, round(text_mask.width * factor)), max(1, round(text_mask.height * factor))),
- Image.Resampling.LANCZOS
- )
- tx = x0 + (bw * supersample - text_mask.width) // 2
- ty = y0 + (bh * supersample - text_mask.height) // 2
- patch.paste((0, 0, 0, 255), (tx, ty), text_mask)
- patch = patch.resize((pw, ph), Image.Resampling.LANCZOS)
- result.alpha_composite(patch, (left - padding, top - padding))
-
- if original_mode == 'RGBA':
- return result
- return result.convert('RGB')
-
The visible pizza has been fully replaced with a rectangular frosted cake-like object, covering the full target area. The surrounding person, table, fruit, and other objects are essentially preserved. The result is visually coherent, though the cake surface is somewhat simple and flat.
{
+ # Work in RGB
+ image = image.convert('RGB')
+ arr = np.array(image).astype(np.uint8)
+ h, w = arr.shape[:2]
+
+ # Coordinate grids
+ yy, xx = np.mgrid[0:h, 0:w]
+ xf = xx.astype(np.float32) / float(w)
+ yf = yy.astype(np.float32) / float(h)
+
+ # --- Build a cat-shaped mask using relative geometry ---
+ # Head on left
+ head = (((xf - 0.115) / 0.23) ** 2 + ((yf - 0.505) / 0.23) ** 2) <= 1.0
+ # Main body across center/right
+ body = (((xf - 0.610) / 0.48) ** 2 + ((yf - 0.565) / 0.30) ** 2) <= 1.0
+ # Lower long fur/belly visible above laptop base
+ belly = (((xf - 0.500) / 0.34) ** 2 + ((yf - 0.755) / 0.145) ** 2) <= 1.0
+ # Left shoulder/neck bridge
+ shoulder = (((xf - 0.285) / 0.25) ** 2 + ((yf - 0.575) / 0.23) ** 2) <= 1.0
+ # Far-right tail/body continuation
+ right_body = (((xf - 0.875) / 0.24) ** 2 + ((yf - 0.565) / 0.235) ** 2) <= 1.0
+
+ shape_mask = head | body | belly | shoulder | right_body
+
+ # Limit to the visible cat band so the top background and bottom laptop edge are protected.
+ shape_mask &= (yf > 0.245) & (yf < 0.895)
+
+ # Protect the very bottom laptop base except where lower fur is expected.
+ lower_fur_zone = belly | (((xf - 0.660) / 0.27) ** 2 + ((yf - 0.785) / 0.11) ** 2 <= 1.0)
+ shape_mask &= ~((yf > 0.820) & (~lower_fur_zone))
+
+ # --- Color/brightness refinement ---
+ rgb = arr.astype(np.float32)
+ r, g, b = rgb[..., 0], rgb[..., 1], rgb[..., 2]
+ gray = 0.299 * r + 0.587 * g + 0.114 * b
+
+ hsv = cv2.cvtColor(arr, cv2.COLOR_RGB2HSV)
+ H = hsv[..., 0]
+ S = hsv[..., 1]
+ V = hsv[..., 2]
+
+ # Cat fur is mostly dark/medium, brown/neutral, not bright cyan/blue sticker or display.
+ not_blue_label = ~(((b > r + 25) & (b > g + 10) & (S > 60)) | ((H > 85) & (H < 115) & (S > 45)))
+ plausible_fur = (V < 178) & (gray < 165) & not_blue_label
+
+ # Include slightly lighter gray/tan fur in lower belly, but still avoid vivid blue/cyan.
+ lighter_belly_fur = lower_fur_zone & (V < 205) & (S < 95) & not_blue_label
+
+ mask = shape_mask & (plausible_fur | lighter_belly_fur)
+
+ # Keep the face/head dark region even if saturation is low.
+ mask |= head & (V < 155) & not_blue_label
+
+ # Morphological cleanup while keeping fur boundary soft later.
+ mask_u8 = (mask.astype(np.uint8) * 255)
+ k3 = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3))
+ k5 = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5))
+ mask_u8 = cv2.morphologyEx(mask_u8, cv2.MORPH_CLOSE, k5, iterations=2)
+ mask_u8 = cv2.morphologyEx(mask_u8, cv2.MORPH_OPEN, k3, iterations=1)
+
+ # Feather edge to preserve fine fur transitions.
+ feather = max(3, int(round(min(w, h) * 0.012)))
+ if feather % 2 == 0:
+ feather += 1
+ alpha = cv2.GaussianBlur(mask_u8.astype(np.float32) / 255.0, (feather * 2 + 1, feather * 2 + 1), 0)
+ alpha = np.clip(alpha, 0.0, 1.0)
+
+ # Reduce alpha on likely laptop/screen blue or saturated non-fur pixels.
+ alpha[~not_blue_label] *= 0.05
+
+ # --- Purple recoloring preserving luminance and texture ---
+ # Convert to HSV and shift hue toward purple, retaining value detail.
+ hsv_new = hsv.astype(np.float32)
+ purple_hue = 142.0 # OpenCV hue for purple/magenta-violet region
+
+ # Stronger saturation so dark fur visibly becomes purple, but not neon-flat.
+ hsv_new[..., 0] = purple_hue
+ hsv_new[..., 1] = np.clip(np.maximum(hsv_new[..., 1] * 1.25, 85), 0, 210)
+ hsv_new[..., 2] = np.clip(hsv_new[..., 2] * 1.08 + 6, 0, 255)
+ purple_hsv_rgb = cv2.cvtColor(hsv_new.astype(np.uint8), cv2.COLOR_HSV2RGB).astype(np.float32)
+
+ # Also create a luminance-based purple tone to ensure very dark fur takes color.
+ purple = np.array([128.0, 50.0, 180.0], dtype=np.float32)
+ purple_lum = 0.299 * purple[0] + 0.587 * purple[1] + 0.114 * purple[2]
+ lum_scale = (gray[..., None] + 18.0) / max(purple_lum, 1.0)
+ lum_purple = np.clip(purple[None, None, :] * lum_scale, 0, 255)
+
+ # Blend hue-shift and luminance purple; keep original shading detail.
+ recolored = 0.58 * purple_hsv_rgb + 0.42 * lum_purple
+
+ # Preserve fine texture by mixing back some original contrast around local blur.
+ arr_f = rgb
+ blur = cv2.GaussianBlur(arr_f, (0, 0), sigmaX=max(1.0, min(w, h) * 0.006))
+ detail = arr_f - blur
+ recolored = np.clip(recolored + detail * 0.45, 0, 255)
+
+ # Avoid over-brightening deepest shadows: mix more original in very dark pixels but still purple-tint them.
+ shadow_factor = np.clip((gray - 18.0) / 55.0, 0.25, 1.0)[..., None]
+ purple_shadow = np.clip(arr_f * np.array([0.78, 0.52, 1.12], dtype=np.float32), 0, 255)
+ recolored = shadow_factor * recolored + (1.0 - shadow_factor) * purple_shadow
+
+ # Composite with feathered alpha.
+ a = alpha[..., None]
+ out = arr_f * (1.0 - a) + recolored * a
+ out = np.clip(out, 0, 255).astype(np.uint8)
+
+ return Image.fromarray(out, 'RGB')
The visible pizza has been fully replaced with a rectangular frosted cake-like object, covering the full target area. The surrounding person, table, fruit, and other objects are essentially preserved. The result is visually coherent, though the cake surface is somewhat simple and flat.
{
"visual_evidence": "A person is preparing food at a counter. The pizza occupies the lower-right foreground, with a browned perimeter and colorful toppings. The person's hands, utensils, fruit, clothing, and blue background are outside the intended edit.",
"target_object": "The pizza in the lower-right foreground",
"target_region": "Approximately x=0.43–0.96 and y=0.74–1.00, following the pizza's angled footprint",
@@ -2980,7 +3024,7 @@ y=7: ffffff*16 f9f9f9 c6c6c6 cbcbcb 949494 9a9a9a b9b9b9 c4c4c4 bababa bfbfbf e3
"executable_code": "def edit(image):\n import cv2\n import numpy as np\n from PIL import Image, ImageDraw, ImageFont\n \n # Convert to numpy for processing if needed, but we'll mostly use PIL Draw\n img = image.copy()\n draw = ImageDraw.Draw(img)\n \n w, h = img.size\n \n # Define colors\n maroon = (128, 0, 32) # Approximate dark maroon\n black = (0, 0, 0)\n white = (255, 255, 255)\n \n # Approximate regions based on 128x128 layout\n # Left group: 0-45, Centre group: 45-90, Right group: 90-128\n \n # --- EDIT 1: Application1 in SPIR-V Clients ---\n # The prompt says 'add a white rectangle... labelled Application1'.\n # Looking at the source, there is already a small box there. We will redraw it clearly.\n # Position: bottom right area\n app_x1, app_y1 = int(w * 0.85), int(h * 0.75)\n app_x2, app_y2 = int(w * 0.98), int(h * 0.88)\n \n # Draw white rect with black border\n draw.rectangle([app_x1, app_y1, app_x2, app_y2], fill=white, outline=black, width=1)\n \n # Label 'Application1'\n # Font size needs to be tiny for 128px width\n try:\n font_small = ImageFont.truetype(\"arial.ttf\", 6)\n font_tiny = ImageFont.truetype(\"arial.ttf\", 5)\n except:\n font_small = ImageFont.load_default()\n font_tiny = ImageFont.load_default()\n \n # Center text in box\n text = \"Application1\"\n bbox = draw.textbbox((0,0), text, font=font_tiny)\n tw, th = bbox[2]-bbox[0], bbox[3]-bbox[1]\n tx = app_x1 + (app_x2-app_x1 - tw)//2\n ty = app_y1 + (app_y1-app_y1 - th)//2\n draw.text((tx, ty), text, fill=black, font=font_tiny)\n \n # Connector from centre-left edge to 'SPIR-V Generated Library' (centre group)\n # Start: left edge of app box\n start_x, start_y = app_x1, (app_y1 + app_y2) // 2\n # End: right edge of centre group (approx x=90, y=80)\n end_x, end_y = int(w * 0.70), int(h * 0.65) \n draw.line([start_x, start_y, end_x, end_y], fill=black, width=1)\n # Add arrowhead (simple triangle)\n # Vector: end - start\n dx = end_x - start_x\n dy = end_y - start_y\n length = (dx**2 + dy**2)**0.5\n if length > 0:\n ux, uy = dx/length, dy/length\n # Arrow points\n p1 = (end_x - 4*ux + 2*uy, end_y - 4*uy - 2*ux)\n p2 = (end_x - 4*ux - 2*uy, end_y - 4*uy + 2*ux)\n draw.polygon([(end_x, end_y), p1, p2], fill=black)\n\n # --- EDIT 2: SPIR-V Library Helper in Centre Panel ---\n # Position: top-middle of centre group\n lib_x1, lib_y1 = int(w * 0.50), int(h * 0.25)\n lib_x2, lib_y2 = int(w * 0.68), int(h * 0.40)\n \n # Draw maroon rect\n draw.rectangle([lib_x1, lib_y1, lib_x2, lib_y2], fill=maroon, outline=black, width=1)\n \n # Label 'SPIR-V Library Helper' (two lines)\n text1 = \"SPIR-V Library\"\n text2 = \"Helper\"\n # Center text\n bbox1 = draw.textbbox((0,0), text1, font=font_tiny)\n bbox2 = draw.textbbox((0,0), text2, font=font_tiny)\n w1, h1 = bbox1[2]-bbox1[0], bbox1[3]-bbox1[1]\n w2, h2 = bbox2[2]-bbox2[0], bbox2[3]-bbox2[1]\n \n cx = (lib_x1 + lib_x2) // 2\n cy = (lib_y1 + lib_y2) // 2\n \n # Adjust for two lines\n total_h = h1 + h2 + 2\n start_y_text = cy - total_h // 2\n \n draw.text((cx - w1//2, start_y_text), text1, fill=white, font=font_tiny)\n draw.text((cx - w2//2, start_y_text + h1 + 2), text2, fill=white, font=font_tiny)\n \n # Arrow from bottom centre to 'SPIR-V Generated Library' (existing box below)\n # Start: bottom centre of new box\n start_x, start_y = cx, lib_y2\n # End: top of existing box (approx y=60, x=60)\n end_x, end_y = int(w * 0.58), int(h * 0.55) \n draw.line([start_x, start_y, end_x, end_y], fill=black, width=1)\n # Arrowhead\n dx = end_x - start_x\n dy = end_y - start_y\n length = (dx**2 + dy**2)**0.5\n if length > 0:\n ux, uy = dx/length, dy/length\n p1 = (end_x - 4*ux + 2*uy, end_y - 4*uy - 2*ux)\n p2 = (end_x - 4*ux - 2*uy, end_y - 4*uy + 2*ux)\n draw.polygon([(end_x, end_y), p1, p2], fill=black)\n\n # --- EDIT 3: SPIR-V Utility in SPIR-V Clients (Top) ---\n # Dashed container at top right\n cont_x1, cont_y1 = int(w * 0.78), int(h * 0.05)\n cont_x2, cont_y2 = int(w * 0.98), int(h * 0.30)\n \n # Draw dashed rectangle manually\n def draw_dashed_rect(draw, box, fill=None, outline=black, width=1, dash_length=3):\n x1, y1, x2, y2 = box\n # Top\n x = x1\n while x < x2:\n draw.line([(x, y1), (min(x+dash_length, x2), y1)], fill=outline, width=width)\n x += dash_length * 2\n # Bottom\n x = x1\n while x < x2:\n draw.line([(x, y2), (min(x+dash_length, x2), y2)], fill=outline, width=width)\n x += dash_length * 2\n # Left\n y = y1\n while y < y2:\n draw.line([(x1, y), (x1, min(y+dash_length, y2))], fill=outline, width=width)\n y += dash_length * 2\n # Right\n y = y1\n while y < y2:\n draw.line([(x2, y), (x2, min(y+dash_length, y2))], fill=outline, width=width)\n y += dash_length * 2\n\n draw_dashed_rect(draw, [cont_x1, cont_y1, cont_x2, cont_y2])\n \n # Inner maroon rectangle\n util_x1, util_y1 = cont_x1 + 2, cont_y1 + 2\n util_x2, util_y2 = cont_x2 - 2, cont_y2 - 2\n draw.rectangle([util_x1, util_y1, util_x2, util_y2], fill=maroon, outline=black, width=1)\n \n # Label 'SPIR-V Utility (ASM/DISASM)'\n text3 = \"SPIR-V Utility\"\n text4 = \"(ASM/DISASM)\"\n bbox3 = draw.textbbox((0,0), text3, font=font_tiny)\n bbox4 = draw.textbbox((0,0), text4, font=font_tiny)\n w3, h3 = bbox3[2]-bbox3[0], bbox3[3]-bbox3[1]\n w4, h4 = bbox4[2]-bbox4[0], bbox4[3]-bbox4[1]\n \n cx = (util_x1 + util_x2) // 2\n cy = (util_y1 + util_y2) // 2\n total_h = h3 + h4 + 2\n start_y_text = cy - total_h // 2\n \n draw.text((cx - w3//2, start_y_text), text3, fill=white, font=font_tiny)\n draw.text((cx - w4//2, start_y_text + h3 + 2), text4, fill=white, font=font_tiny)\n \n # Connector from mid-left edge to container's left border\n start_x, start_y = util_x1, (util_y1 + util_y2) // 2\n end_x, end_y = cont_x1, (util_y1 + util_y2) // 2 - 5 # Slightly slanted\n draw.line([start_x, start_y, end_x, end_y], fill=black, width=1)\n # Arrowhead pointing left\n dx = end_x - start_x\n dy = end_y - start_y\n length = (dx**2 + dy**2)**0.5\n if length > 0:\n ux, uy = dx/length, dy/length\n p1 = (end_x - 4*ux + 2*uy, end_y - 4*uy - 2*ux)\n p2 = (end_x - 4*ux - 2*uy, end_y - 4*uy + 2*ux)\n draw.polygon([(end_x, end_y), p1, p2], fill=black)\n\n return img",
"requires_inpaint": false
}
-```
VL + 图像:图像判分依据
The SPIR-V Library Helper box and downward arrow were added in roughly the correct place, and the top-right SPIR-V Utility container/box is partially present. However, the Utility label appears cramped/clipped, and the connector integration is rough. The requested Application1 white rectangle with black border is not properly created; it appears mostly as loose text with an arrow/connector rather than a clear bordered box. Unrelated diagram content is mostly preserved, but the added elements are visually messy and incomplete.
The SPIR-V Library Helper box and downward arrow were added in roughly the correct place, and the top-right SPIR-V Utility container/box is partially present. However, the Utility label appears cramped/clipped, and the connector integration is rough. The requested Application1 white rectangle with black border is not properly created; it appears mostly as loose text with an arrow/connector rather than a clear bordered box. Unrelated diagram content is mostly preserved, but the added elements are visually messy and incomplete.