Guest User

Untitled

a guest
Feb 6th, 2026
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.61 KB | None | 0 0
  1. # PS Helper: Intelligent Layer Classification System
  2.  
  3. ## Overview
  4.  
  5. PS Helper is a Photoshop UXP plugin that automatically classifies and organizes layers using a weighted voting system called **The Hive-Mind**. The system accumulates evidence from multiple signals—layer properties, naming patterns, pixel analysis, spatial relationships—and determines classification through consensus rather than rigid decision trees.
  6.  
  7. The system answers a fundamental challenge in design automation: **How do you teach a machine to "see" what a human sees when they glance at a layer stack?**
  8.  
  9. ---
  10.  
  11. ## The Problem
  12.  
  13. Professional Photoshop documents are chaos. A typical esports graphic might have:
  14. - 50+ layers with generic names like "Layer 23", "Rectangle 1 copy"
  15. - Textures, effects, and adjustments scattered throughout
  16. - Player photos clipped to frames
  17. - Logos in corners
  18. - Backgrounds buried at the bottom
  19.  
  20. A human can glance at this and instantly understand the structure. A computer sees only rectangles with pixel data.
  21.  
  22. **Traditional approaches fail because:**
  23. - Single-rule systems can't handle the nuance ("Rectangle 1" could be a logo frame, a subject frame, or just a shape)
  24. - Edge cases break rigid logic
  25. - Context matters enormously (a layer alone means little; a layer in context reveals truth)
  26.  
  27. ---
  28.  
  29. ## The Philosophy: The Hive-Mind
  30.  
  31. The Hive-Mind is not a decision tree. It's a **collective intelligence**—a system where every signal, every pattern, every piece of context contributes a vote toward understanding what a layer truly is.
  32.  
  33. > "No single signal is definitive. But together? Confident classification."
  34.  
  35. Like a swarm of bees, no single bee decides where the hive goes. The collective behavior emerges from thousands of small signals, each contributing their piece of truth.
  36.  
  37. Traditional classification asks: "What rule does this match?"
  38. The Hive-Mind asks: "What do all the signals collectively believe this is?"
  39.  
  40. ---
  41.  
  42. ## Classification Pipeline
  43.  
  44. ```
  45. ┌─────────────────────────────────────────────────────────────┐
  46. │ PHASE 1: DATA COLLECTION │
  47. │ Extract all layer properties: bounds, blend mode, opacity, │
  48. │ clipping state, masks, kind │
  49. └─────────────────────────────────────────────────────────────┘
  50. │
  51. ▼
  52. ┌─────────────────────────────────────────────────────────────┐
  53. │ PHASE 2: PIXEL ANALYSIS (Imaging API) │
  54. │ Full-resolution alpha analysis: │
  55. │ - solidContentRatio (alpha > 200) │
  56. │ - softContentRatio (alpha 20-150) │
  57. │ - boundsFilledRatio (actual content vs bounding box) │
  58. │ - colorVariance, dominantColorCount │
  59. │ - hasGradientAlpha (wide alpha transitions) │
  60. └─────────────────────────────────────────────────────────────┘
  61. │
  62. ▼
  63. ┌─────────────────────────────────────────────────────────────┐
  64. │ PHASE 3: DEFINITIVE RULES │
  65. │ Layer type determines classification (no override): │
  66. │ - adjustment layers → adjustment (95% confidence) │
  67. │ - solidColor/gradientFill/patternFill → fill (90%) │
  68. │ - text layers → text (90%) │
  69. └─────────────────────────────────────────────────────────────┘
  70. │
  71. ▼
  72. ┌─────────────────────────────────────────────────────────────┐
  73. │ PHASE 4: EXPLICIT NAME RULES │
  74. │ Name contains category keyword: │
  75. │ - "logo", "watermark" → logo │
  76. │ - "background", "bg" → background │
  77. │ - "subject", "player" → subject │
  78. │ - "texture", "grain" → texture │
  79. └─────────────────────────────────────────────────────────────┘
  80. │
  81. ▼
  82. ┌─────────────────────────────────────────────────────────────┐
  83. │ PHASE 5: INFERRED RULES (Weighted Voting) │
  84. │ Each signal casts weighted votes: │
  85. │ │
  86. │ scores = { logo: 0, subject: 0, background: 0, │
  87. │ texture: 0, graphics: 0, effect: 0, fill: 0 } │
  88. │ │
  89. │ if (inCorner && isSmall) scores.logo += 35 │
  90. │ if (looksLikeHumanName) scores.subject += 55 │
  91. │ if (isClipped) scores.background -= 100 │
  92. │ if (hasBlendMode && fullCoverage) scores.texture += 60 │
  93. │ │
  94. │ Winner = highest score (if >= 20) │
  95. │ Confidence = base + score/2 + margin/4 │
  96. └─────────────────────────────────────────────────────────────┘
  97. │
  98. ▼
  99. ┌─────────────────────────────────────────────────────────────┐
  100. │ PHASE 6: HOLISTIC CONTEXT ANALYSIS │
  101. │ - Guardrails: Enforce type constraints │
  102. │ - Sequence detection: Similar layers vote together │
  103. │ - True background detection: Find solid base │
  104. │ - Clipping chain analysis: Frame + subject = both subject │
  105. │ - Sibling consensus: Adjacent soft elements align │
  106. └─────────────────────────────────────────────────────────────┘
  107. │
  108. ▼
  109. ┌─────────────────────────────────────────────────────────────┐
  110. │ FINAL OUTPUT │
  111. │ { category, confidence, rule, reasons[] } │
  112. └─────────────────────────────────────────────────────────────┘
  113. ```
  114.  
  115. ---
  116.  
  117. ## Layer Categories
  118.  
  119. | Category | Description |
  120. |----------|-------------|
  121. | **background** | Solid base layer at bottom of stack. Full coverage, full alpha, normal blend, not clipped. |
  122. | **subject** | Main focal elements (people, products). Human names, team prefixes, camera filenames, centered position, clipped to frame. |
  123. | **texture** | Overlay layers (grain, noise, lighting). Blend modes, full coverage, reduced opacity. |
  124. | **graphics** | Shapes, borders, decorative elements. Generic shape names, thin elements, borders. |
  125. | **logo** | Brand marks, watermarks. Small size, corner position, intentional naming. |
  126. | **text** | Text layers. Definitive by layer kind. |
  127. | **fill** | Solid colors, gradients. Clipped layers, single color content. |
  128. | **effect** | Glows, flares, soft light effects. Soft alpha content (>40% soft pixels), small coverage. |
  129. | **adjustment** | Color/tonal adjustments. Definitive by layer kind (curves, levels, hueSaturation, etc.). |
  130.  
  131. ---
  132.  
  133. ## Signal Evidence System
  134.  
  135. ### Evidence Gathered Per Layer
  136.  
  137. ```javascript
  138. {
  139. // Layer type
  140. isTextLayer, isAdjustment, isFill, isShape, isSmartObject, isPixel,
  141.  
  142. // Name patterns
  143. nameContainsLogo, nameContainsBackground, nameContainsSubject,
  144. nameContainsTexture, nameContainsEffect, nameContainsLighting,
  145. hasIntentionalName, looksLikeHumanName, hasDateInName,
  146. hasTeamPrefix, hasCameraFileName, isGenericShapeName,
  147. looksLikeTextContent,
  148.  
  149. // Coverage & geometry
  150. coverage, boundsFilledRatio,
  151. isFullCoverage (>90% + >70% bounds fill),
  152. isLargeCoverage (>50%), isSmallElement (<15%), isTinyElement (<5%),
  153. isThinElement (boundsFilledRatio < 0.3),
  154.  
  155. // Alpha metrics (from pixel analysis)
  156. solidContentRatio, softContentRatio, opaqueRatio,
  157. isSolidElement (>60% solid), isSoftElement (>40% soft),
  158. hasGradientAlpha (wide alpha transitions),
  159. isSparse (<50% solid), isVerySparse (<25%),
  160.  
  161. // Color metrics
  162. isSingleColor, isLowColorVariance, colorVariance, dominantColorCount,
  163.  
  164. // Position
  165. isTopOfStack, isBottomOfStack,
  166. isInCorner, isInTrueCorner, isCentered,
  167. isVerticalBorder, isHorizontalBorder,
  168. spansFullHeight, spansFullWidth,
  169.  
  170. // Blend mode
  171. hasOverlayBlend, hasMultiplyBlend, hasScreenBlend, hasNonNormalBlend,
  172.  
  173. // Opacity
  174. hasLowOpacity (<50%), hasVeryLowOpacity (<25%),
  175.  
  176. // Relationships
  177. isClipped, hasClippedContent, hasClippedAdjustment,
  178. hasMask, hasMaskRestriction (reveals <50%)
  179. }
  180. ```
  181.  
  182. ---
  183.  
  184. ## Scoring Rules (Key Examples)
  185.  
  186. ### Background
  187. ```
  188. +50: full coverage + full alpha + normal blend + high opacity + not sparse + not clipped
  189. +30: bottom of stack (bonus)
  190. -100: is clipped (NEVER background)
  191. -40: has texture blend or reduced opacity
  192. -50: mask reveals only small area
  193. -30: frame shape (coverage without full alpha)
  194. ```
  195.  
  196. ### Subject
  197. ```
  198. +65: camera filename (DSCF####, IMG_####)
  199. +55: team/org prefix (NRG_, 100T_, FaZe_)
  200. +55: masked photo cutout (multi-color smart object with mask)
  201. +40: large centered element (not full coverage)
  202. +30: name looks like human name
  203. +25: date pattern in name
  204. ```
  205.  
  206. ### Texture
  207. ```
  208. +60: full coverage + blend mode (overlay/multiply/screen)
  209. +55: full coverage + reduced opacity (<90%)
  210. +55: soft overlay (large coverage + soft element)
  211. +45: high fill + blend mode
  212. +40: name suggests lighting
  213. ```
  214.  
  215. ### Logo
  216. ```
  217. +35: small corner element + not sparse
  218. +25: smart object in corner
  219. +20: true corner position (non-text)
  220. -100: team prefix (players, not logos)
  221. -60: vertical/horizontal border
  222. -50: generic shape name ("Rectangle 1")
  223. ```
  224.  
  225. ### Graphics
  226. ```
  227. +55: shape layer
  228. +50: vertical/horizontal border/stripe
  229. +45: frame shape (coverage without full alpha)
  230. +45: name looks like text content (rasterized text)
  231. +40: generic shape name
  232. +50: thin element (low bounds fill ratio)
  233. ```
  234.  
  235. ### Effect
  236. ```
  237. +55: soft element + small/medium coverage
  238. +45: faded edges + low opacity (glow pattern)
  239. +40: mask reveals only small area
  240. +35: screen blend + soft content
  241. +35: gradient light element (localized)
  242. ```
  243.  
  244. ---
  245.  
  246. ## Context Detection Systems
  247.  
  248. ### 1. Sequence Detection
  249. Adjacent layers with similar properties are detected and vote together.
  250.  
  251. **Similarity scoring:**
  252. - Both generic names (Layer X): +3
  253. - Both have blend modes: +2
  254. - Same blend mode: +2
  255. - Both sparse: +2
  256. - Similar coverage (±20%): +1
  257. - Both soft elements: +2
  258.  
  259. If similarity >= 4 AND both have generic names AND 3+ layers: sequence forms.
  260. Majority classification wins, all members align.
  261.  
  262. ### 2. Clipping Chain Analysis
  263. ```
  264. Rectangle 1 (hasClippedLayers: true)
  265. └─ DRYAD (1) (isClipped: true, looksLikeHumanName: true)
  266. ```
  267. - Base layer with clipped content analyzed as unit
  268. - If clipped layer is subject (human name, photo-like colors): base becomes subject-frame
  269. - Both receive subject classification and stay grouped
  270.  
  271. ### 3. True Background Detection
  272. Scans from bottom of stack to find the first layer that is:
  273. - Full coverage (>85%)
  274. - Full alpha (opaqueRatio >= 85%)
  275. - Actually fills bounds (boundsFilledRatio >= 80%)
  276. - Normal blend mode
  277. - High opacity (>90%)
  278. - NOT clipped
  279. - NOT adjustment/fill/text layer
  280.  
  281. All full-coverage layers ABOVE true background with blend modes or reduced opacity → texture.
  282.  
  283. ### 4. Guardrails (Enforced Constraints)
  284. ```
  285. Adjustment layers → ALWAYS adjustment
  286. Fill layers → ALWAYS fill (never background)
  287. Text layers → ALWAYS text/headline/caption
  288. Clipped layers → NEVER background (become fill)
  289. Frame shapes (high coverage, low alpha) → NEVER background
  290. Thin elements (low boundsFilledRatio) → NEVER background
  291. ```
  292.  
  293. ### 5. Sibling Consensus
  294. Adjacent soft elements (effect/texture confusion) within same parent:
  295. - If 3+ consecutive soft elements have mixed effect/texture
  296. - Apply majority vote
  297. - Ties broken by stack position (top = effect, bottom = texture)
  298.  
  299. ---
  300.  
  301. ## Pixel Analysis Deep Dive
  302.  
  303. The system uses Photoshop's Imaging API at **full resolution** for accurate classification.
  304.  
  305. ### Alpha Ranges
  306. ```
  307. 0-20: Transparent (not counted as visible)
  308. 21-150: Soft content (glows, soft brushes, effects)
  309. 151-200: Semi-solid (anti-alias or soft edge)
  310. 201-250: Near-opaque (anti-aliased edges of solid content)
  311. 251-255: Fully opaque (solid content)
  312. ```
  313.  
  314. ### Critical Metrics
  315. | Metric | Formula | Classification Impact |
  316. |--------|---------|----------------------|
  317. | `solidContentRatio` | solidPixels / visiblePixels | >0.6 = solid element (logo, graphic, subject) |
  318. | `softContentRatio` | softPixels / visiblePixels | >0.4 = soft element (glow, effect) |
  319. | `boundsFilledRatio` | visiblePixels / totalPixels | <0.3 = thin element (line, cross) |
  320. | `opaquePixelRatio` | opaquePixels / visiblePixels | <0.85 = has transparency holes (not background) |
  321.  
  322. ### Why This Matters
  323. A 2px cross spanning the document has:
  324. - High coverage (bounds fill canvas)
  325. - High opaqueRatio (the pixels that exist are solid)
  326. - **Low boundsFilledRatio** (most of the bounding box is empty)
  327.  
  328. Without boundsFilledRatio, this would incorrectly classify as background. With it → graphics.
  329.  
  330. ---
  331.  
  332. ## Training System
  333.  
  334. ### Correction Flow
  335. 1. User runs analysis on document
  336. 2. System classifies each layer with confidence and reasoning
  337. 3. User corrects mistakes via UI picker
  338. 4. Corrections saved with full context:
  339.  
  340. ```json
  341. {
  342. "layerName": "Layer 22",
  343. "layerKind": "pixel",
  344. "systemClassification": "background",
  345. "correctedClassification": "fill",
  346. "systemConfidence": 72,
  347. "systemReason": "full coverage + normal blend",
  348. "comment": "Clipped to group, gradient alpha indicates color overlay",
  349. "documentName": "project.psd",
  350. "createdAt": "2026-02-03T14:30:00Z"
  351. }
  352. ```
  353.  
  354. ### Training Insights Applied
  355. - Clipping masks change meaning (background → fill)
  356. - Frame + clipped subject = both are "subject" conceptually
  357. - Gradient alpha + single color = fill
  358. - Sequences of similar gradient elements = texture group
  359. - Rasterized text has no text signal → classify as graphics
  360. - Camera filenames (DSCF####, IMG_####) = subject photos
  361. - Team prefixes (NRG_, 100T_) = players, not logos
  362.  
  363. ---
  364.  
  365. ## Results
  366.  
  367. | Document | Layers | Correct | Accuracy |
  368. |----------|--------|---------|----------|
  369. | Casting talent IGS.psd | 26 | 26 | 100% |
  370.  
  371. Classification breakdown:
  372. - 1 background (name + position + coverage)
  373. - 6 subjects (human names, clipped to frames)
  374. - 6 subject-frames (Rectangle + hasClippedLayers)
  375. - 8 textures (blend modes, overflow coverage)
  376. - 2 logos (corner position, smart objects)
  377. - 1 fill (exact canvas coverage, middle stack)
  378. - 1 adjustment (layer kind)
  379. - 1 graphics (rasterized text, no text signal available)
  380.  
  381. ---
  382.  
  383. ## Why It Works
  384.  
  385. 1. **Many weak signals align** — No single signal is definitive, but 10 signals all pointing the same direction creates certainty.
  386.  
  387. 2. **Context resolves ambiguity** — A sparse layer alone is unclear. A sparse layer in a sequence of 5 similar layers is obviously texture.
  388.  
  389. 3. **Relationships reveal truth** — A rectangle alone means nothing. A rectangle with a person clipped to it is a subject frame.
  390.  
  391. 4. **The collective is smarter than the parts** — Individual signals make mistakes. The voting system corrects them through consensus.
  392.  
  393. 5. **Guardrails prevent impossible states** — Clipped layers can never be background. Adjustment layers can never be texture. The system enforces what it knows to be true.
  394.  
  395. ---
  396.  
  397. ## Summary
  398.  
  399. The Hive-Mind is:
  400. - **Additive** — Signals accumulate, never eliminate
  401. - **Democratic** — Every signal votes, no dictators
  402. - **Contextual** — Neighbors influence classification
  403. - **Confident through consensus** — Many agreeing signals = high confidence
  404. - **Emergent** — Complex behavior from simple rules
  405.  
  406. The system doesn't follow rules. The system **recognizes patterns**.
  407.  
  408. ---
  409.  
  410. *"You are adding the icing, adding more toppings always; never eating away of the current hive."*
Advertisement
Add Comment
Please, Sign In to add comment