Skip to main content
Participant
January 15, 2025
Question

Seeking JavaScript Equivalent for Photoshop's "Find Neutral Gray" Technique for Batch Processing

  • January 15, 2025
  • 2 replies
  • 480 views

Hi Photoshop Community,

I'm looking for a way to replicate the "Find Neutral Gray" technique described in this article ( https://www.photoshopessentials.com/photo-editing/neutral-gray/  ) using JavaScript. The article outlines a method to identify neutral gray areas in an image for color correction, which involves the following steps in Photoshop:

  1. Create a new layer and fill it with 50% gray.

  2. Set the layer's blend mode to "Difference".

  3. Add a Threshold adjustment layer.

  4. Adjust the Threshold slider to reveal the darkest areas, which represent areas closest to neutral gray.

  5. Use the Color Sampler Tool to mark a point in the darkest area.

  6. Remove the gray layer and Threshold layer.

  7. Add a Levels or Curves adjustment layer and use the "Set Gray Point" eyedropper to click on the marked point, neutralizing the midtones.

 

I need to use this technique in batch actions within Photoshop. This means the JavaScript code needs to be suitable for automation within a Photoshop batch process.

If achieving this exact workflow with JavaScript in a batch process is not feasible, I'd be grateful for alternative suggestions. What other methods do you recommend for color correction that can be automated for batch processing, besides the standard automatic calculation of curves with "Find Dark & Light Colors" and the "Snap Neutral Midtones" option? I'm looking for a robust and reliable method that can be applied to a large number of images consistently.

Any guidance or code examples on how to approach this would be greatly appreciated!

Thanks in advance for your help.

2 replies

Stephen Marsh
Community Expert
Community Expert
January 15, 2025
quote

If achieving this exact workflow with JavaScript in a batch process is not feasible, I'd be grateful for alternative suggestions. What other methods do you recommend for color correction that can be automated for batch processing, besides the standard automatic calculation of curves with "Find Dark & Light Colors" and the "Snap Neutral Midtones" option?

 

I'm looking for a robust and reliable method that can be applied to a large number of images consistently.

 

Any guidance or code examples on how to approach this would be greatly appreciated!

Thanks in advance for your help.


By @zelenook5F94

 

I usually don't recommend automated colour correction.

 

However, if you insist, then I'm going straight for alternatives.

 

If the images are raw camera files, JPEG or TIFF (or HEIC on Mac), then batch processing via Adobe Bridge and the Adobe Camera Raw plugin using the "Auto" setting could be an option (don't overwrite the originals).

 

Otherwise from within Photoshop, the Camera Raw Filter "Auto" can be scripted, and the script recorded into a batch action or a batch script.

 

  // Camera Raw Filter - Auto
  var desc1 = new ActionDescriptor();
  desc1.putBoolean(charIDToTypeID("AuTn"), true);
  executeAction(stringIDToTypeID('Adobe Camera Raw Filter'), desc1, DialogModes.NO);

 

YMMV, so again, don't overwrite the originals or work with duped merged layers or smart object layers etc.

 

Something that I just read about today is interesting, however, I haven't had any personal experience with it:

 

https://blog.adobe.com/en/publish/2024/10/14/the-adobe-adaptive-profile

Inspiring
January 15, 2025

Stefano, the camera raw auto function is not suitable for doing what the user asks. Unfortunately what you ask is not possible, I have considered doing programming for this many times, but I have always had a negative outcome.

Stephen Marsh
Community Expert
Community Expert
January 15, 2025

@Ciccillotto 

 

Yes, auto white balance would be closer and that too is scriptable for the CRF, but again it's auto and not designed for rendered data, so results are often less than satisfactory.

 

I'm not a fan of the method originally mentioned either.

 

Content and context aware colour correction is one of those things that should be better done with machine learning but is yet to be brought to market by Adobe.

 

https://data.csail.mit.edu/graphics/fivek/

c.pfaffenbichler
Community Expert
Community Expert
January 15, 2025

I expect it might be necessary to iterate the threshold and evaluate the histogram and/or load selections to determine when the area is small enough (or disappears). 

Which would be a bit of a performance-issue but otherwise what is giving you problems? 

 

But I am talking about ESTK-Scripting, UXP-Scripting might be more efficient.