Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the algorithm behind Photoshop's Highlight or shadow alteration?

I want to write an image enhancement algorithm which is similar to photoshop's highlight and shadows alteration feature. Can you help me regarding what does this feature of photoshop do internally to an image?

like image 715
Sahil Garg Avatar asked Oct 30 '25 20:10

Sahil Garg


1 Answers

Simple approach

To begin with, you can already find already some clue in their documentation: https://helpx.adobe.com/photoshop/using/adjust-shadow-highlight-detail.html

It's quite hard to guess from those documents which algorithm they use exactly. Below I will only try to explain some approaches I would use if I was facing this problem. Don't expect there a clear algorithm, but use my answer as pointers to drive you at least to a path.

As I understood, this algorithm improve the contrast in a local scale, meaning for each pixel it will adjust the value based on the neighborhood. To do so you have several input parameters:

  • Neighborhood size (or Kernel)
  • Highlight Threshold: Everything above is considered as belonging to highlight
  • Shadow Threshold: Everything below is considered as belonging to shadow

Other ones are mentioned in the documentation, but they are not useful to understand the algorithmic concept.

1. Determine to which category the pixel belong: Highlight / Shadow / none.

For this part you might consider using either the grayscale image or the Value channel from HSV transformation.

I would take a look to the pixel and its neighborhood. Compute statistics of the local distribution (mean and variance).

I will compare the mean to the thresholds value define previously, then use the variance to distinguish if the pixel is noisy or belonging to a contour, which on those case I'll expect a huge variance.

2. Apply the processing

In case the pixel is belonging to the shadow or highlight class you want to improve its contrast, not the "gray" but the "color" contrast.

Dumb approach:
Will be to weight your color channel according to their intra-variances.

Here is an example: Consider your pixel being: (32, 35, 50)(R,G,B) and belonging to shadow class. I will determine 3 coefficients Rc, Gc, Bc which are defined between 0.5 - 1.5 (arbitrary) which apply to the respective channel.

Since the Blue is dominant I would have a high coefficient for the blue like 1.3 and lower the importance of R and G channel with a coefficient about 0.8.

To compute these coefficients you can think to look at color variance, meaning differences between the color channels themselves and differences between each channels and the pixel mean.


Other (high-level) approaches

Laplacian Pyramids

Using the pyramids to distinguish the details in different scales and the laplacian to improve the contrast.

  • http://mcclanahoochie.com/blog/portfolio/opencl-image-pyramid-detail-enhancement/
  • https://www.darktable.org/2017/11/local-laplacian-pyramids/

Those links could be really helpful for you, especially because the sources are available and the concept are well explained. I would advise you to continue your quest to look deeper in darktable. It's a powerful free/open-source alternative to Lightroom.
I already find some interesting stuff just by looking at their blog.

Sorry for this incomplete answer, I'll probably come back there to improve it.
All comments and suggestions are more than welcome

like image 64
Madeux Avatar answered Nov 01 '25 14:11

Madeux