Skip to content

Comparison Algorithm

imugi uses a multi-signal comparison approach to objectively measure how close your code is to the design.

Signals

SignalWhat it measuresWeight
SSIMStructural similarity — luminance, contrast, structure0.4 (with vision) or 1.0 (alone)
Pixel DiffRaw pixel-level comparison via pixelmatchUsed for heatmap
Claude VisionAI-powered visual assessment0.6 (when available)

Composite Score

The composite score is calculated as:

  • SSIM only (when vision unavailable): score = ssim
  • SSIM + Vision: score = ssim * 0.4 + vision * 0.6

The score is clamped to [0, 1].

When Vision is Used

Claude Vision analysis is activated when SSIM < 0.98. For very high SSIM scores, pixel-level comparison is sufficient and the API call is skipped.

Diff Regions

Pixel differences are clustered into regions using connected component analysis. Each region gets:

  • Position (x, y) and size (width, height)
  • Diff intensity — average difference magnitude
  • Pixel count — number of differing pixels

Region Classification

Regions are classified by type:

ClassificationDescription
colorColor mismatch
spacingMargin/padding difference
sizeElement size mismatch
positionElement position offset
missingElement present in design but not in code
extraElement in code but not in design
fontTypography difference

Priority Assignment

PriorityCriteria
highLarge area, high intensity, structural differences
mediumModerate area or intensity
lowSmall area, low intensity

Strategy Selection

Based on the composite score, imugi selects a patching strategy:

ScoreStrategyDescription
< 0.7Full regenerationRewrite the code from scratch
>= 0.7Surgical patchTargeted fixes for specific regions

The strategy can also switch based on iteration history — if surgical patches are not improving the score, imugi may escalate to full regeneration.