Guest User

Untitled

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