Close Menu
    Facebook LinkedIn YouTube WhatsApp X (Twitter) Pinterest
    Trending
    • Portable water filter provides safe drinking water from any source
    • MAGA Is Increasingly Convinced the Trump Assassination Attempt Was Staged
    • NCAA seeks faster trial over DraftKings disputed March Madness branding case
    • AI Trusted Less Than Social Media and Airlines, With Grok Placing Last, Survey Says
    • Extragalactic Archaeology tells the ‘life story’ of a whole galaxy
    • Swedish semiconductor startup AlixLabs closes €15 million Series A to scale atomic-level etching technology
    • Republican Mutiny Sinks Trump’s Push to Extend Warrantless Surveillance
    • Yocha Dehe slams Vallejo Council over rushed casino deal approval process
    Facebook LinkedIn WhatsApp
    Times FeaturedTimes Featured
    Saturday, April 18
    • Home
    • Founders
    • Startups
    • Technology
    • Profiles
    • Entrepreneurs
    • Leaders
    • Students
    • VC Funds
    • More
      • AI
      • Robotics
      • Industries
      • Global
    Times FeaturedTimes Featured
    Home»Artificial Intelligence»From RGB to Lab: Addressing Color Artifacts in AI Image Compositing
    Artificial Intelligence

    From RGB to Lab: Addressing Color Artifacts in AI Image Compositing

    Editor Times FeaturedBy Editor Times FeaturedJanuary 17, 2026No Comments14 Mins Read
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr WhatsApp Email
    Share
    Facebook Twitter LinkedIn Pinterest Telegram Email WhatsApp Copy Link


    Introduction

    alternative is a staple of picture enhancing, reaching production-grade outcomes stays a big problem for builders. Many current instruments work like “black bins,” which implies we’ve little management over the stability between high quality and velocity wanted for an actual software. I bumped into these difficulties whereas constructing VividFlow. The challenge is especially centered on Picture-to-Video era, but it surely additionally gives a characteristic for customers to swap backgrounds utilizing AI prompts.

    To make the system extra dependable throughout various kinds of photos, I ended up specializing in three technical areas that made a big distinction in my outcomes:

    • A Three-Tier Fallback Technique: I discovered that orchestrating BiRefNet, U²-Web, and conventional gradients ensures the system all the time produces a usable masks, even when the first mannequin fails.
    • Correction in Lab Coloration Area: Transferring the method to Lab house helped me take away the “yellow halo” artifacts that always seem when mixing photos in normal RGB house.
    • Particular Logic for Cartoon Artwork: I added a devoted pipeline to detect and protect the sharp outlines and flat colours which can be distinctive to illustrations.

    These are the approaches that labored for me once I deployed the app on HuggingFace Areas. On this article, I need to share the logic and a few of the math behind these selections, and the way they helped the system deal with the messy number of real-world photos extra persistently.

    1. The Drawback with RGB: Why Backgrounds Go away a Hint

    Normal RGB alpha mixing tends to go away a cussed visible mess in background alternative. While you mix a portrait shot towards a coloured wall into a brand new background, the sting pixels often maintain onto a few of that authentic colour. That is most blatant when the unique and new backgrounds have contrasting colours, like swapping a heat yellow wall for a cool blue sky. You typically find yourself with an unnatural yellowish tint that instantly provides away the truth that the picture is a composite. This is the reason even when your segmentation masks is pixel-perfect, the ultimate composite nonetheless appears clearly pretend — the colour contamination betrays the edit.

    The problem is rooted in how RGB mixing works. Normal alpha compositing treats every colour channel independently, calculating weighted averages with out contemplating how people truly understand colour. To see this downside concretely, think about the instance visualized in Determine 1 beneath. Take a darkish hair pixel (RGB 80, 60, 40) captured towards a yellow wall (RGB 200, 180, 120). Through the photograph shoot, gentle from that wall displays onto the hair edges, making a colour forged. In the event you apply a 50% mix with a brand new blue background in RGB house, the pixel turns into a muddy common (RGB 140, 120, 80) that preserves apparent traces of the unique yellow—precisely the yellowish tint downside we need to eradicate. As an alternative of a clear transition, this contamination breaks the phantasm of pure integration.

    Determine 1. RGB versus Lab house mixing comparability at pixel degree.

    As demonstrated within the determine above, the center panel reveals how RGB mixing produces a muddy consequence that retains the yellowish tint from the unique wall. The rightmost panel reveals the answer: switching to Lab colour house earlier than the ultimate mix permits surgical elimination of this contamination. Lab house separates lightness (L channel) from chroma (a and b channels), enabling focused corrections of colour casts with out disturbing the luminance that defines object edges. The corrected consequence (RGB 75, 55, 35) achieves pure hair darkness whereas eliminating yellow affect by vector operations within the ab airplane, a mathematical course of I’ll element in Part 5.

    2. System Structure: Orchestrating the Workflow

    The background alternative pipeline orchestrates a number of specialised parts in a fastidiously designed sequence that prioritizes each robustness and effectivity. The structure ensures that even when particular person fashions encounter difficult eventualities, the system gracefully degrades to various approaches whereas sustaining output high quality with out losing GPU assets.

    Following the structure diagram, the pipeline executes by six distinct levels:

    Picture Preparation: The system resizes and normalizes enter photos to a most dimension of 1024 pixels, guaranteeing compatibility with diffusion mannequin architectures whereas sustaining facet ratio.

    Semantic Evaluation: An OpenCLIP imaginative and prescient encoder analyzes the picture to detect topic sort (particular person, animal, object, nature, or constructing) and measures colour temperature traits (heat versus cool tones).

    Immediate Enhancement: Primarily based on the semantic evaluation, the system augments the person’s authentic immediate with contextually applicable lighting descriptors (golden hour, mushy subtle, shiny daylight) and atmospheric qualities (skilled, pure, elegant, cozy).

    Background Era: Steady Diffusion XL synthesizes a brand new background scene utilizing the improved immediate, configured with a DPM-Solver++ scheduler operating for twenty-five inference steps at steerage scale 7.5.

    Sturdy Masks Era: The system makes an attempt three progressively easier approaches to extract the foreground. BiRefNet gives high-quality semantic segmentation as the primary selection. When BiRefNet produces inadequate outcomes, U²-Web by rembg presents dependable general-purpose extraction. Conventional gradient-based strategies function the ultimate fallback, guaranteeing masks manufacturing no matter enter complexity.

    Perceptual Coloration Mixing: The fusion stage operates in Lab colour house to allow exact elimination of background colour contamination by chroma vector deprojection. Adaptive suppression energy scales with every pixel’s colour similarity to the unique background. Multi-scale edge refinement produces pure transitions round fantastic particulars, and the result’s composited again to straightforward colour house with correct gamma correction.

    3. The Three-Tier Masks Technique: High quality Meets Reliability

    In background alternative, the masks high quality is the ceiling, your closing picture can by no means look higher than the masks it’s constructed on. Nevertheless, counting on only one segmentation mannequin is a recipe for failure when coping with real-world selection. I discovered {that a} three-tier fallback technique was one of the best ways to make sure each person will get a usable consequence, whatever the picture sort.

    1. BiRefNet (The High quality Chief): That is the first selection for complicated scenes. In the event you have a look at the left panel of the comparability picture, discover how cleanly it handles the person curly hair strands. It makes use of a bilateral structure that balances high-level semantic understanding with fine-grained element. In my expertise, it’s the one mannequin that persistently avoids the “uneven” go searching flyaway hair.
    2. U²-Web through rembg (The Balanced Fallback): When BiRefNet struggles, typically with cartoons or very small topics—the system robotically switches to U²-Web. Trying on the center panel, the hair edges are a bit “fuzzier” and fewer detailed than BiRefNet, however the total physique form remains to be very correct. I added customized alpha stretching and morphological refinements to this stage to assist preserve extremities like palms and toes from being unintentionally clipped.
    3. Conventional Gradients (The “By no means Fail” Security Web): As a closing resort, I exploit Sobel and Laplacian operators to seek out edges primarily based on pixel depth. The proper panel reveals the consequence: it’s a lot easier and misses the fantastic hair textures, however it’s assured to finish and not using a mannequin error. To make this look skilled, I apply a guided filter utilizing the unique picture as a sign, which helps clean out noise whereas protecting the structural edges sharp.

    4. Perceptual Coloration Area Operations for Focused Contamination Elimination

    The answer to RGB mixing’s colour contamination downside lies in selecting a colour house the place luminance and chromaticity separate cleanly. Lab colour house, standardized by the CIE (2004), gives precisely this property by its three-channel construction: the L channel encodes lightness on a 0–100 scale, whereas the a and b channels symbolize colour opponent dimensions spanning green-to-red and blue-to-yellow respectively. Not like RGB the place all three channels couple collectively throughout mixing operations, Lab permits surgical manipulation of colour data with out disturbing the brightness values that outline object boundaries.

    The mathematical correction operates by vector projection within the ab chromatic airplane. To grasp this operation geometrically, think about Determine 3 beneath, which visualizes the method in two-dimensional ab house. When an edge pixel reveals contamination from a yellow background, its measured chroma vector C represents the pixel’s colour coordinates (a, b) within the ab airplane, pointing partially towards the yellow route. Within the diagram, the contaminated pixel seems as a crimson arrow with coordinates (a = 12, b = 28), whereas the background’s yellow chroma vector B seems as an orange arrow pointing towards (a = 5, b = 45). The important thing perception is that the portion of C that aligns with B represents undesirable background affect, whereas the perpendicular portion represents the topic’s true colour.

    Determine 3. Vector projection in Lab ab chromatic airplane eradicating yellow background contamination.

    As illustrated within the determine above, the system removes contamination by projecting C onto the normalized background route B̂ and subtracting this projection. Mathematically, the corrected chroma vector turns into:

    [mathbf{C}’ = mathbf{C} – (mathbf{C} cdot mathbf{hat{B}}) mathbf{hat{B}}]

    the place C · B̂ denotes the dot product that measures how a lot of C lies alongside the background route. The yellow dashed line in Determine 3 represents this projection part, exhibiting the contamination magnitude of 15 models alongside the background route. The purple dashed arrow demonstrates the subtraction operation that yields the corrected inexperienced arrow C′ = (a = 4, b = 8). This corrected chroma reveals considerably diminished yellow part (from b = 28 right down to b = 8) whereas sustaining the unique red-green stability (a stays close to its authentic worth). The operation performs exactly what visible inspection suggests is required: it removes solely the colour part parallel to the background route whereas preserving perpendicular parts that encode the topic’s inherent coloration.

    Critically, this correction occurs solely within the chromatic dimensions whereas the L channel stays untouched all through the operation. This preservation of luminance maintains the sting construction that viewers understand as pure boundaries between foreground and background parts. Changing the corrected Lab values again to RGB house produces the ultimate pixel colour that integrates cleanly with the brand new background with out seen contamination artifacts.

    5. Adaptive Correction Power By way of Coloration Distance Metrics

    Merely eradicating all background colour from edges dangers overcorrection, edges can develop into artificially grey or desaturated, dropping pure heat. To stop this, I carried out adaptive energy modulation primarily based on how contaminated every pixel truly is, utilizing the ΔE colour distance metric:

    [Delta E = sqrt{(Delta L)^2 + (Delta a)^2 + (Delta b)^2}]

    the place ΔE beneath 1 is imperceptible whereas values above 5 point out clearly distinguishable colours. Pixels with ΔE beneath 18 from the background are categorized as contaminated candidates for correction.

    The correction energy follows an inverse relationship, pixels very near the background colour obtain sturdy correction whereas distant pixels get light remedy:

    [S = 0.85 times maxleft(0, 1 – frac{Delta E}{18}right)]

    This formulation ensures energy gracefully tapers to zero as ΔE approaches the brink, avoiding sharp discontinuities.

    Determine 4 illustrates this by a zoomed comparability of hair edges towards totally different backgrounds. The left panel reveals the unique picture with yellow wall contamination seen alongside the hair boundary. The center panel reveals how normal RGB mixing preserves a yellowish rim that instantly betrays the composite as synthetic. The fitting panel reveals the Lab-based correction eliminating colour spill whereas sustaining pure hair texture, the sting now integrates cleanly with the blue background by focusing on contamination exactly on the masks boundary with out affecting reliable topic colour.

    Determine 4. Hair edge comparability: Authentic (left), RGB mix (center), Lab adaptive correction (proper).

    6. Cartoon-Particular Enhancement for Line Artwork Preservation

    Cartoon and line-art photos current distinctive challenges for generic segmentation fashions skilled on photographic information. Not like pure images with gradual transitions, cartoon characters characteristic sharp black outlines and flat colour fills. Normal deep studying segmentation typically misclassifies black outlines as background whereas giving inadequate protection to strong fill areas, creating seen gaps in composites.

    I developed an automated detection pipeline that prompts when the system identifies line-art traits by three options: edge density (Canny edge pixels ratio), colour simplicity (distinctive colours relative to space), and darkish pixel prevalence (luminance beneath 50). When these thresholds are met, specialised enhancement routines set off.

    Determine 5 beneath reveals the enhancement pipeline by 4 levels. The primary panel shows the unique cartoon canine with its attribute black outlines and flat colours. The second panel reveals the improved masks, discover the whole white silhouette capturing your complete character. The third panel reveals Canny edge detection figuring out sharp outlines. The fourth panel highlights darkish areas (luminance < 50) that mark the black strains defining the character’s kind.

    Determine 5. Cartoon enhancement pipeline: Authentic, enhanced masks, edge detection, black define areas.

    The enhancement course of within the determine above operates in two levels. First, black define safety scans for darkish pixels (luminance < 80), dilates them barely, and units their masks alpha to 255 (full opacity), guaranteeing black strains are by no means misplaced. Second, inner fill enhancement identifies high-confidence areas (alpha > 160), applies morphological closing to attach separated components, then boosts medium-confidence pixels inside this zone to minimal alpha of 220, eliminating gaps in flat-colored areas.

    This specialised dealing with preserved masks protection throughout anime characters, comedian illustrations, and line drawings throughout growth. With out it, generic fashions produce masks technically right for pictures however fail to protect the sharp outlines and strong fills that outline cartoon imagery.

    Conclusion: Engineering Selections Over Mannequin Choice

    Constructing this background alternative system bolstered a core precept: production-quality AI purposes require considerate orchestration of a number of methods reasonably than counting on a single “greatest” mannequin. The three-tier masks era technique ensures robustness throughout various inputs, Lab colour house operations eradicate perceptual artifacts that RGB mixing inherently produces, and cartoon-specific enhancements protect inventive integrity for non-photographic content material. Collectively, these design selections create a system that handles real-world variety whereas sustaining transparency about how corrections are utilized—important for builders integrating AI into their purposes.

    A number of instructions for future enhancement emerge from this work. Implementing guided filter refinement as normal post-processing might additional clean masks edges whereas preserving structural boundaries. The cartoon detection heuristics presently use fastened thresholds however may benefit from a light-weight classifier skilled on labeled examples. The adaptive spill suppression presently makes use of linear falloff, however clean step or double clean step curves would possibly present extra pure transitions. Lastly, extending the system to deal with video enter would require temporal consistency mechanisms to forestall flickering between frames.

    Venture Hyperlinks:

    Acknowledgments:

    This work builds upon the open-source contributions of BiRefNet, U²-Web, Steady Diffusion XL, and OpenCLIP. Particular because of the HuggingFace workforce for offering the ZeroGPU infrastructure that enabled this deployment.


    References & Additional Studying

    Coloration Science Foundations

    • CIE. (2004). Colorimetry (third ed.). CIE Publication 15:2004. Worldwide Fee on Illumination.
    • Sharma, G., Wu, W., & Dalal, E. N. (2005). The CIEDE2000 color-difference formulation: Implementation notes, supplementary check information, and mathematical observations. Coloration Analysis & Software, 30(1), 21-30.

    Deep Studying Segmentation

    • Peng, Z., Shen, J., & Shao, L. (2024). Bilateral reference for high-resolution dichotomous picture segmentation. arXiv preprint arXiv:2401.03407.
    • Qin, X., Zhang, Z., Huang, C., Dehghan, M., Zaiane, O. R., & Jagersand, M. (2020). U²-Web: Going deeper with nested U-structure for salient object detection. Sample Recognition, 106, 107404.

    Picture Compositing & Coloration Areas

    • Lucas, B. D. (1984). Coloration picture compositing in a number of colour areas. Proceedings of the IEEE Convention on Pc Imaginative and prescient and Sample Recognition.

    Core Infrastructure

    • Rombach, R., et al. (2022). Excessive-resolution picture synthesis with latent diffusion fashions. Proceedings of the IEEE/CVF Convention on Pc Imaginative and prescient and Sample Recognition, 10684-10695.
    • Radford, A., et al. (2021). Studying transferable visible fashions from pure language supervision. Proceedings of the Worldwide Convention on Machine Studying, 8748-8763.

    Picture Attribution

    • All figures on this article had been generated utilizing Gemini Nano Banana and Python code.



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Editor Times Featured
    • Website

    Related Posts

    A Practical Guide to Memory for Autonomous LLM Agents

    April 17, 2026

    You Don’t Need Many Labels to Learn

    April 17, 2026

    Beyond Prompting: Using Agent Skills in Data Science

    April 17, 2026

    6 Things I Learned Building LLMs From Scratch That No Tutorial Teaches You

    April 17, 2026

    Introduction to Deep Evidential Regression for Uncertainty Quantification

    April 17, 2026

    memweave: Zero-Infra AI Agent Memory with Markdown and SQLite — No Vector Database Required

    April 17, 2026

    Comments are closed.

    Editors Picks

    Portable water filter provides safe drinking water from any source

    April 18, 2026

    MAGA Is Increasingly Convinced the Trump Assassination Attempt Was Staged

    April 18, 2026

    NCAA seeks faster trial over DraftKings disputed March Madness branding case

    April 18, 2026

    AI Trusted Less Than Social Media and Airlines, With Grok Placing Last, Survey Says

    April 18, 2026
    Categories
    • Founders
    • Startups
    • Technology
    • Profiles
    • Entrepreneurs
    • Leaders
    • Students
    • VC Funds
    About Us
    About Us

    Welcome to Times Featured, an AI-driven entrepreneurship growth engine that is transforming the future of work, bridging the digital divide and encouraging younger community inclusion in the 4th Industrial Revolution, and nurturing new market leaders.

    Empowering the growth of profiles, leaders, entrepreneurs businesses, and startups on international landscape.

    Asia-Middle East-Europe-North America-Australia-Africa

    Facebook LinkedIn WhatsApp
    Featured Picks

    How Federal Agencies Got Caught Up in Trump’s Anti-Immigration Crusade

    March 4, 2026

    AI Toys for Kids Talk About Sex, Drugs, and Chinese Propaganda

    December 13, 2025

    Baseus Inspire XC1 Review: Excellent Open Earbuds

    October 25, 2025
    Categories
    • Founders
    • Startups
    • Technology
    • Profiles
    • Entrepreneurs
    • Leaders
    • Students
    • VC Funds
    Copyright © 2024 Timesfeatured.com IP Limited. All Rights.
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us

    Type above and press Enter to search. Press Esc to cancel.