Copy link to clipboard
Copied
Hi guys,
this is what I am dealing with:
yesterday I shot about 200 products, 3 shots/per product using focus stacking.
Filenames are in exact sequence: filename001, filename002, filename003 are 3 different focus shots of the same product.
The next three files sequence ex: filename004.tif filename005.tif filename006.tif are the shots of the next product etc.
So there is a folder with 600 shots which I have to repeat an action, that :
a) Open three first shots and plays an action or script (any)
b) then saves a new one image with a filename something like filename003-new.tif for the first three, filename005-new.tif for the next... etc
c) then repeat the action for the next three shots until the folder ends.
The result would be an image that had Auto-align the three images into a new one as layers and then Auto blend> stack images.
Any ideas?
You could try this script, it prompts for the folder where the files are, creates a folder off this called Processed where the tif file are saved.
...#target photoshop;
app.bringToFront();
main();
function main(){
var selectedFolder = Folder.selectDialog("Please select the folder to process");
if(selectedFolder == null ) return;
var outFolder = Folder(selectedFolder + "/processed");
if(!outFolder.exists) outFolder.create();
var threeFiles = new Array();
var PictureFiles = selectedFolder.getFiles(/\.(jpg|
Copy link to clipboard
Copied
You could try this script, it prompts for the folder where the files are, creates a folder off this called Processed where the tif file are saved.
#target photoshop;
app.bringToFront();
main();
function main(){
var selectedFolder = Folder.selectDialog("Please select the folder to process");
if(selectedFolder == null ) return;
var outFolder = Folder(selectedFolder + "/processed");
if(!outFolder.exists) outFolder.create();
var threeFiles = new Array();
var PictureFiles = selectedFolder.getFiles(/\.(jpg|jpe|dng|bmp|tif|tiff|psd|crw|cr2|exr|pcx|nef|dcr|dc2|erf|raf|orf|tga|mos|pef|png)$/i);
while(PictureFiles.length>2){
for(var a = 0;a<3;a++){threeFiles.push(PictureFiles.shift());}
stackFiles(threeFiles);
selectAllLayers();
autoAlign();
autoBlendLayers();
var layerName = activeDocument.activeLayer.name.replace(/\....$/i,'');
var saveFile = new File(outFolder+ '/' + layerName + '.psd');
SaveTIFF(saveFile);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
threeFiles=[];
}
};
function autoBlendLayers(){
var d=new ActionDescriptor();
d.putEnumerated(stringIDToTypeID("apply"), stringIDToTypeID("autoBlendType"), stringIDToTypeID("maxDOF"));
d.putBoolean(stringIDToTypeID("colorCorrection"), true);
d.putBoolean(stringIDToTypeID("autoTransparencyFill"), false);
executeAction(stringIDToTypeID("mergeAlignedLayers"), d, DialogModes.NO);
};
function SaveTIFF(saveFile){
tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.embedColorProfile = true;
tiffSaveOptions.alphaChannels = true;
tiffSaveOptions.layers = true;
tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;
activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);
};
function selectAllLayers() {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
desc.putReference( charIDToTypeID('null'), ref );
executeAction( stringIDToTypeID('selectAllLayers'), desc, DialogModes.NO );
};
function stackFiles(sFiles){
var loadLayersFromScript = true;
var SCRIPTS_FOLDER = decodeURI(app.path + '/' + localize('$$$/ScriptingSupport/InstalledScripts=Presets/Scripts'));
$.evalFile( new File(SCRIPTS_FOLDER + '/Load Files into Stack.jsx'));
loadLayers.intoStack(sFiles);
};
function autoAlign() {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
desc.putReference( charIDToTypeID('null'), ref );
desc.putEnumerated( charIDToTypeID('Usng'), charIDToTypeID('ADSt'), stringIDToTypeID('ADSContent') );
desc.putEnumerated( charIDToTypeID('Aply'), stringIDToTypeID('projection'), charIDToTypeID('Auto') );
desc.putBoolean( stringIDToTypeID('vignette'), false );
desc.putBoolean( stringIDToTypeID('radialDistort'), false );
executeAction( charIDToTypeID('Algn'), desc, DialogModes.NO );
};
function autoBlend() {
var desc = new ActionDescriptor();
desc.putEnumerated( charIDToTypeID('Aply'), stringIDToTypeID('autoBlendType'), stringIDToTypeID('maxDOF') );
desc.putBoolean( charIDToTypeID('ClrC'), true );
executeAction( stringIDToTypeID('mergeAlignedLayers'), desc, DialogModes.NO );
};
Copy link to clipboard
Copied
You are my Hero!
It worked like a charm!
Congrats!
Did u code the script?
Copy link to clipboard
Copied
Yes, but I chose 3 pics that were simular for a test and the result was very unusual
Copy link to clipboard
Copied
What do you mean "unusual", not well stack focused, perhaps?
Nope. In my case the the result was what I expected! Excellent job!
Copy link to clipboard
Copied
It gave unusual artifacts, as the pics could not be properly aligned.
Copy link to clipboard
Copied
Yes, sometimes this happens. Although, this is not a script problem.
Copy link to clipboard
Copied
Hi @SuperMerlin
Is it possible to sort layers by histogram value ?
1.Top - histogram value : mean <= 100
2.Center : histogram value : mean >= 111 && mean <= 180
4.Bottom : histogram value : >= 181
Thank you !
Copy link to clipboard
Copied
Sorry :
3.Bottom : histogram value : >= 181
Copy link to clipboard
Copied
Thank you very much for sharing this script!
Copy link to clipboard
Copied
What do I have to do manually in Photoshop to get this result:
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
desc.putReference( charIDToTypeID('null'), ref );
desc.putEnumerated( charIDToTypeID('Usng'), charIDToTypeID('ADSt'), stringIDToTypeID('ADSContent') );
desc.putEnumerated( charIDToTypeID('Aply'), stringIDToTypeID('projection'), charIDToTypeID('Auto') );
desc.putBoolean( stringIDToTypeID('vignette'), false );
desc.putBoolean( stringIDToTypeID('radialDistort'), false );
executeAction( charIDToTypeID('Algn'), desc, DialogModes.NO );
Copy link to clipboard
Copied
I create new version of the script. Sometimes I do with dozens of focus stacking images and hundreds, even thousands of jpgs, so I wanted process them once. The script do it 👍
For example,
If you have folder root, and folders f1.jpg, f2.jpg, ..., fn.jpg inside of root with files inside each of it:
- you run script, choose root, wait, and have files inside root: f1_fs.jpg, f2_fs.jpg, ..., fn_fs.jpg. That is fantastic.
Thank you all, SuperMerlin especially, for the script. ☺️
I put the script at GitHub:
Copy link to clipboard
Copied
Sorry, I mistake with folder names and filenames, but I can't edit message. Hope you understand what I mean.
Copy link to clipboard
Copied
Hi There, I'm trying to do something similar to this. I'm doing photo stacks of 10 images, but they are JPG files. I saved the files as a .PSJS files and tried to open the script in PhotoShop but it doesn't seem to do anything when Opened. I don't even get the "Please Select Folder prompt". I think I found and modified the A<3 varilable to A<10, but not sure what else would need to be modified to make it work. Can you let me know what else I would have to do for this?
Copy link to clipboard
Copied
I saved the files as a .PSJS files and tried to open the script in PhotoShop but it doesn't seem to do anything when Opened.
By @Lucky_me
This is a legacy ExtendScript .JSX file, not a new UXP Script .PSJS file.
https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html
NOTE: When Adobe changed the forum software, many old scripts were broken if they contained a variable in square brackets, such as [i] or [a] etc.
/*
Automate focus stacking.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/automate-focus-stacking-script-action-help-needed/m-p/12742549#M622233
SuperMerlin, Jun 07, 2019
*/
#target photoshop;
app.bringToFront();
main();
function main() {
var selectedFolder = Folder.selectDialog("Please select the folder to process");
if (selectedFolder == null) return;
var outFolder = Folder(selectedFolder + "/processed");
if (!outFolder.exists) outFolder.create();
var threeFiles = new Array();
var PictureFiles = selectedFolder.getFiles(/\.(jpg|jpe|dng|bmp|tif|tiff|psd|crw|cr2|exr|pcx|nef|dcr|dc2|erf|raf|orf|tga|mos|pef|png)$/i);
while (PictureFiles.length > 2) {
for (var a = 0; a < 3; a++) {
threeFiles.push(PictureFiles.shift());
}
stackFiles(threeFiles);
selectAllLayers();
autoAlign();
autoBlendLayers();
var layerName = activeDocument.activeLayer.name.replace(/\....$/i, '');
var saveFile = new File(outFolder + '/' + layerName + '.psd');
SaveTIFF(saveFile);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
threeFiles = [];
}
};
function autoBlendLayers() {
var d = new ActionDescriptor();
d.putEnumerated(stringIDToTypeID("apply"), stringIDToTypeID("autoBlendType"), stringIDToTypeID("maxDOF"));
d.putBoolean(stringIDToTypeID("colorCorrection"), true);
d.putBoolean(stringIDToTypeID("autoTransparencyFill"), false);
executeAction(stringIDToTypeID("mergeAlignedLayers"), d, DialogModes.NO);
};
function SaveTIFF(saveFile) {
tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.embedColorProfile = true;
tiffSaveOptions.alphaChannels = true;
tiffSaveOptions.layers = true;
tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;
activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);
};
function selectAllLayers() {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
desc.putReference(charIDToTypeID('null'), ref);
executeAction(stringIDToTypeID('selectAllLayers'), desc, DialogModes.NO);
};
function stackFiles(sFiles) {
var loadLayersFromScript = true;
var SCRIPTS_FOLDER = decodeURI(app.path + '/' + localize('$$$/ScriptingSupport/InstalledScripts=Presets/Scripts'));
$.evalFile(new File(SCRIPTS_FOLDER + '/Load Files into Stack.jsx'));
loadLayers.intoStack(sFiles);
};
function autoAlign() {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
desc.putReference(charIDToTypeID('null'), ref);
desc.putEnumerated(charIDToTypeID('Usng'), charIDToTypeID('ADSt'), stringIDToTypeID('ADSContent'));
desc.putEnumerated(charIDToTypeID('Aply'), stringIDToTypeID('projection'), charIDToTypeID('Auto'));
desc.putBoolean(stringIDToTypeID('vignette'), false);
desc.putBoolean(stringIDToTypeID('radialDistort'), false);
executeAction(charIDToTypeID('Algn'), desc, DialogModes.NO);
};
function autoBlend() {
var desc = new ActionDescriptor();
desc.putEnumerated(charIDToTypeID('Aply'), stringIDToTypeID('autoBlendType'), stringIDToTypeID('maxDOF'));
desc.putBoolean(charIDToTypeID('ClrC'), true);
executeAction(stringIDToTypeID('mergeAlignedLayers'), desc, DialogModes.NO);
};