Recommended Free Tools
Yes, Python can colorize a black-and-white image, but this classic method is not a one-click automatic colorizer. You provide a grayscale image and a second, aligned image containing a few color scribbles. An optimization process then propagates those clues to nearby pixels whose intensities are similar. The result reflects both the mathematical assumptions and the colors you chose.
What “optimization-based colorization” means
Anat Levin, Dani Lischinski and Yair Weiss introduced Colorization using optimization at ACM SIGGRAPH in 2004. Their method treats colorization as an interactive problem: an artist supplies sparse color marks, and the algorithm infers colors for the remaining pixels. The original work demonstrated the approach on still images and movie clips, so the same idea can be applied spatially to photographs and across time in video.
The central premise is that neighboring pixels with similar intensities should have similar colors. In plain language, a pixel is more likely to receive a color resembling nearby pixels when its brightness is similar to theirs. The method does not identify the historically “true” color of an object, and it does not understand objects in the way a modern learned model might. Its output depends on the supplied clues and on how well the local intensity relationship fits the image.
What you need as input
1. A grayscale image
Use one channel of luminance or a grayscale image with consistent dimensions. Keep the image in a numeric format that preserves the intended intensity range, such as floating-point values normalized to 0–1.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
2. A color-clue image
Create a second image with exactly the same width and height. Paint colored marks over selected regions and leave the rest neutral or explicitly marked as unknown, according to the implementation you choose. A red mark on a jacket, for example, tells the solver that nearby pixels with compatible intensity should tend toward that chromatic value.
3. A defined color representation
Many implementations separate lightness from chromatic channels so the original grayscale intensity can be retained while the unknown color components are solved. The exact representation is an implementation choice; document the channel order, numeric range and conversion rules so that the saved image is interpreted correctly.
How the algorithm uses scribbles
The scribbles act as constraints or guidance values. For every unmarked pixel, the optimization balances relationships with neighboring pixels. Similar intensities receive stronger encouragement to have similar colors, while large intensity differences weaken that relationship. Marked pixels anchor the solution to the artist’s chosen colors.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
Levin, Lischinski and Weiss formulate this as a quadratic cost function. The unknown color values are selected to minimize the total cost of violating the local smoothness relationships while honoring the user’s clues. Because the resulting objective is quadratic, it can be expressed as a system of equations and solved with standard numerical techniques.
A Python implementation workflow
The following organization is a general implementation outline, not a claim that a particular current package exposes the original algorithm as a ready-made function.
Step 1: Load and validate both images
- Read the grayscale image and the color-clue image.
- Verify identical width, height and pixel alignment. Do not resize one independently after drawing scribbles.
- Convert intensities and color channels to a documented floating-point range.
- Check that clue pixels are distinguishable from unknown pixels; an all-zero color may be a legitimate clue, so a separate mask is safer.
gray = load_grayscale("photo.png")
clues = load_rgb("scribbles.png")
mask = load_mask("scribble_mask.png")
assert gray.shape[:2] == clues.shape[:2] == mask.shape
# Convert gray, clues and any working color channels to documented float ranges
The names above are placeholders for the image I/O functions in your selected stack. scikit-image is a Python image-processing toolbox built around NumPy and SciPy, but its documentation does not establish that this exact 2004 colorization algorithm is included as a built-in operation.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Step 2: Choose the solved channels
Keep the grayscale lightness as the image’s luminance and solve for two chromatic channels, or use another representation required by your implementation. Convert the scribble colors into that same representation. A mismatch here—such as supplying RGB clues to a solver expecting different channels—produces incorrect colors even when the optimization is implemented correctly.
Step 3: Build the neighborhood system
Represent each unknown pixel as a variable. For its local neighbors, compute weights from intensity similarity. Nearby pixels with close grayscale values receive stronger coupling; dissimilar intensities receive weaker coupling. The exact neighborhood size, weighting formula and boundary handling belong to the implementation specification and should not be silently changed between runs.
# Conceptual structure; weighting and matrix construction are implementation-specific
for pixel in pixels:
for neighbor in local_neighbors(pixel):
weight = similarity(gray[pixel], gray[neighbor])
add_quadratic_term(pixel, neighbor, weight)
for pixel in known_scribble_pixels(mask):
constrain(pixel, clue_color[pixel])
Step 4: Solve the quadratic system
Assemble the sparse linear system for each unknown color channel and solve it with a suitable numerical method. Sparse storage matters for ordinary photographs because a variable is connected mainly to local neighbors, not to every pixel in the image. The solver must also enforce the scribble constraints; otherwise the output can drift toward an unconstrained smooth solution.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Step 5: Recombine and save
Combine the solved chromatic channels with the grayscale lightness, convert back to the output color space, clip values to the valid range and write an image file. Inspect the result at the same resolution as the input. A color-space conversion or channel-order error can make a mathematically valid solution look wildly tinted.
solved_chroma = solve_sparse_system(system, constraints)
result = combine_with_lightness(gray, solved_chroma)
result = clip_to_valid_range(convert_to_rgb(result))
save_image("colorized.png", result)
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Why extra scribbles change the result
Ambiguous regions
A grayscale image can contain several objects with comparable intensities but different intended colors. If the local evidence does not separate them, the solver has no reliable basis for choosing between those colors. Add clues on each region rather than expecting one mark to identify every object.
Weak or conflicting clues
A tiny mark may not influence the surrounding area enough, while marks that disagree across a boundary can pull the solution in competing directions. Place strokes inside the regions they describe and avoid crossing edges unless that is deliberate.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Similar-intensity object boundaries
Two adjacent objects can have nearly identical grayscale values. The method’s intensity-similarity assumption may then encourage color to cross the boundary. More carefully placed scribbles, a better-preserved edge model or manual correction may be necessary.
Artist-dependent color choices
The algorithm propagates the colors you provide; it cannot establish whether a historical garment, landscape or face had a particular real-world color. Save the clue image with the output so another person can understand the decisions behind the result.
Still images versus video
The original publication discusses both stills and movie clips. For video, clues and inferred colors must remain coherent across neighboring frames as well as within each frame. A workflow that solves every frame independently can produce visible flicker, so a video implementation needs a temporal formulation or another mechanism for propagating information through time. Do not assume that a still-image Python script automatically provides temporal consistency.
Choosing Python tools responsibly
Use established image I/O, array and sparse-linear-algebra components for the surrounding pipeline. scikit-image documents itself as a collection of image-processing algorithms for Python and identifies NumPy and SciPy as underlying libraries. That makes it useful for loading, conversion, masking and inspection, but the cited documentation does not say that it implements Levin, Lischinski and Weiss’s exact optimization method.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsPublic repositories by Orhan Yilmaz and by Soumik12345 illustrate possible Python or mixed Python/C++ implementations, including user-guided command-line workflows and separate clue images. Treat them as examples rather than guaranteed installation targets: dependency names, APIs and code age require checking against the repository’s current documentation before you create an environment. A repository listing an old package such as scikits.sparse or scikits.learn is not, by itself, evidence of present-day compatibility.
A practical checklist before running
- The grayscale and clue images have identical dimensions and alignment.
- The clue mask distinguishes unknown pixels from valid dark colors.
- All channels use the ranges and color space expected by the solver.
- At least one clue is supplied for every region whose color cannot be inferred safely from neighboring intensities.
- The sparse-system construction and solver are compatible with your installed NumPy/SciPy versions.
- The output is clipped and converted correctly before saving.
- You retain the clue image and parameter settings alongside the colorized result.
Can Python automatically add color to a grayscale photo?
Python can automate the loading, optimization and export stages, but this particular approach is user-guided rather than fully automatic. Without color scribbles, there are no explicit artist choices for the optimization to propagate. If you need a system that proposes colors without manual marks, you are looking at a different class of method based on learned image priors; its behavior and trade-offs should be evaluated separately rather than attributed to this 2004 optimization.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

