Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Batch Median Noise Reduction

Community Beginner ,
Nov 23, 2019 Nov 23, 2019

Hi,

I have a night timelapse consisting of single images where the foreground is very noisy. What I want to do is open three images, create a smartobject and then use the stackmode median to reduce noise. Then photoshop should move foreward one image and yet again open three images. Is there a way to automate this using actions and the batch editing? I didn't find a way to open more than one image automatically...

 

Thanks for your help!

Jakob

TOPICS
Actions and scripting , Windows
5.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Nov 23, 2019 Nov 23, 2019

Try this script. It will pull the files from a folder on your desktop called "source," but you can change the folder by editing the path in the code. It will save to a subfolder, called done, in the same folder. It will append the files with "median" so files don't get over written. It will also save the files as jpgs, and only open jpgs. You can change the file type by changing the extension in the line: 

var mask = '*.jpg'

 

#target photoshop
var srcFolder = new Folder('~/desktop/source/');
va
...
Translate
Community Expert , Jul 13, 2020 Jul 13, 2020

As suggested by Chuck, here is the modified script for mean blending:

 

 

/* 
https://community.adobe.com/t5/photoshop/batch-median-noise-reduction/m-p/10758011?page=1#M285346
Batch Median Noise Reduction
*/

#target photoshop
var srcFolder = new Folder('~/desktop/source/');
var doneFolder = new Folder(srcFolder + '/done/');
if (!doneFolder.exists) {
    doneFolder.create()
};

var jpgOptions = new JPEGSaveOptions();
jpgOptions.quality = 8
var mask = '*.jpg'
var fList = srcFolder.getFiles(mask);
...
Translate
Adobe
Community Expert ,
Apr 12, 2021 Apr 12, 2021

The script should select all layers, create a smart object, then set the smart object to use median blend mode for the layers stacked inside the smart object. I tested this many times. There is no median layer blend mode outside of smart objects, this is a feature of smart object layer stack modes.

 

You can change two lines of the script, removing or commenting // out the flatten step on line 99 and changing false to true on line 158 to save a layered TIFF. You can then verify the smart object stack blend mode.

 

You didn't mention that an auto align was required, so all the images are stacked as per the original position.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 12, 2021 Apr 12, 2021

The tiff output looks just like one single layer, a little bit noisy compared to a median stack I manually run.

 That thing with aligning I realized today while comparing individual shots but it should not be a problem with cameras with full electronic shutter. I will try again tomorrow, thanks for your help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 12, 2021 Apr 12, 2021

I'll look into the script, perhaps I missed something, I checked so many times during development!

 

That being said, a totally different method of combining the images would be required to take advantage of auto-align.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 12, 2021 Apr 12, 2021

Sadly, you are correct...

 

script-manual.png

 

full-script.png

 

 

EDIT 17th April: I believe that I have fixed this now!

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 12, 2021 Apr 12, 2021

Wow, that is really strange, I just tried 4 different methods to select all layers and although they work in isolated form, they don't work in the larger script. I'm not sure what I have done now! :]

 

EDIT 17th April: I believe that I have fixed this now!

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 13, 2021 Apr 13, 2021

Do not go crazy about it, I do not want you to waste too much time on it; but maybe this has become a chalenge for you now..;-)

The way I manually run these median stacks is File>scripts>statistics

Blend mode set to Median and I tick the "align images" box

 

I do not know if it could be a possible work around

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 16, 2021 Apr 16, 2021

 

UPDATE 17th April:

 

I believe that I have fixed the error where the layers were not being selected and made into a smart object with median stack blend mode (I had that bit of code incorrectly placed within a try block).

 

The previous code has been updated with a date stamp in the code of 17th April 2021, replacing the incorrect code from the 11th of April.

 

So the script (hopefully) works as originally intended.

 

That being said, it is not using the separate stack script auto-align, that is beyond the scope of the original script.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 16, 2021 Apr 16, 2021

@Seta666 

 

If you take a look at the following topic:

 

https://www.photoshopgurus.com/forum/threads/loading-all-images-in-a-folder-into-groups-of-3-is-it-p...

 

You will see that the well known and respected scripter Paul MR makes use of the underlying stacking code:

 

 

var loadLayersFromScript = true;
$.evalFile(app.path + "/" +  localize("$$$/ScriptingSupport/InstalledScripts=Presets/Scripts") + "/Load Files into Stack.jsx");
loadLayers.intoStack(files);

 

 

That script stacks into sets of 3, however, you can simply change that to 4...

 

I'll ask Paul about hooking into the auto-align.

 

EDIT: That topic is locked.

 

Does anybody here have any idea of how to pass through a parameter to use the auto align layers to the stack script, bypassing the GUI?

 

auto-align.png

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 17, 2021 Apr 17, 2021

@Stephen Marsh Thank you Stephen, that is more than enough. I will give it a try beguining of next week. With low magnification shots and cameras with electronic shutter auto align will not be needed

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 24, 2021 Apr 24, 2021

@Seta666 

 

I thought that the Statistics or Load Layers Into Stack scripts were doing something extra special when set to use auto align, however I found the following link in the Adobe help docs (it does help to RTFM at times):

 

https://helpx.adobe.com/au/photoshop/using/image-stacks.html

 

quote

If desired, select Attempt To Automatically Align Source Images (equivalent to choosing Edit > Auto-Align Layers).


Adobe

 

So this means that I can introduce an auto align step into this script.

 

Can you provide sample images for testing and or confirm what exact option you wish to use:

 

auto-align.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 24, 2021 Apr 24, 2021

Hi Stephen, 

 

I guess collage would be the one to use from those options (image can move/rotate between shots but reposition could also work as it is only few pixels we are talking about) . It is not a panorama, all images have same framing. This is not something I would need to use all the time, only at very high magnification; so both scripts are useful.

 

The script as it is now will work most of the time but I would like a second script with auto align (auto), median and 6000x4000 cropping afterwards for high magnification work. When using auto align image can end up being 6001x4002 and then stacking software gives an error (source images have a different size) this is why cropping would also be needed.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 24, 2021 Apr 24, 2021

Although I could probably just add auto align auto and the crop, it would really help to have samples so that I am not flying blind and wasting time. You can send me a private message offlist if you don't wish to publicly share the frames or if you can point to representative samples on the internet it would help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 24, 2021 Apr 24, 2021

When I say cropping I mean change canvas size, not just resizing.

 

Also if I wanted to stack 6 or 8 TIFF instead of 4 which are the code lines that should be changed?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 24, 2021 Apr 24, 2021

You would simply change the following line from:

 

// Images per set
var setQty = 4;

 

To:

 

// Images per set
var setQty = 6;

 

Or:

 

// Images per set
var setQty = 8;

 

Another option, rather than hard-coding in the value, is for a prompt to be displayed and you enter in the number as required. So you would delete the two lines above and replace them with:

 

//////////////////////////// Variable Set Quantity - GUI /////////////////////////////

// Loop the input prompt until a number is entered
var origInput;
while (isNaN(origInput = prompt('Enter the number of files per set:', '4')));
// Test if cancel returns null, then terminate the script
if (origInput === null) {
    alert('Script cancelled!');
    return
}
// Test if an empty string is returned, then terminate the script 
if (origInput === '') {
    alert('A value was not entered, script cancelled!');
    return
}
// Convert decimal input to integer
var setQty = parseInt(origInput);

//////////////////////////////////////////////////////////////////////////////////////

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 25, 2021 Apr 25, 2021

As I think about this task, are you sure that Auto Blend (focus stacking) wouldn't be a better option than Auto Align?

 

Either way, recent experience has shown that you first have to satisfy yourself that you can do this manually, then with a recorded action before looking for better automatiion through scripting.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 26, 2021 Apr 26, 2021
LATEST

Auto align is just in case shutter shake makes camera move a few pixels, but median is the way to go. Median will increase DR and reduce noise but some fine details may be lost; later all the resulting tiffs will go to stacking software (zerene stacker).

 

Focus stacking software thinks of noise as details and it adds up quickly

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines