forked from lfang-salk/Batch-processing-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSplit_RGB_channels.ijm
55 lines (43 loc) · 1.92 KB
/
Split_RGB_channels.ijm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//Batch split RGB channels and save different channel into different folders
//Specification:
//Input - RGB metallicRoughness.png images saved in one folder.
//Output - Splitted single channel images saved in three folders, each of which contains images of one single channel
//originally written by Linjing Fang on 1/16/2018
//Email: [email protected]
//adapted by Sooperfish
//**********************************************************************************//
// when this is true, the script runs faster but images are hidden
setBatchMode(true);
// load array of all RGB images in the input directory
path = getDirectory("Select the folder of your input png RGB images");
filelist = getFileList(path);
//Create folders for each splitted channel
File.makeDirectory(path + "Splitted channel - Metallic");
File.makeDirectory(path + "Splitted channel - Roughness");
File.makeDirectory(path + "Splitted channel - Ambient Occlusion");
for (i=0; i< filelist.length; i++) {
// process png files only
if (endsWith(filelist[i], ".png")) {
open(filelist[i]);
print("Splitting: "+ filelist[i]);
run("Split Channels");
// Save blue channel
selectWindow(filelist[i] + " (blue)");
NewName_blue = replace(filelist[i],"_metallicRoughness.png","_metallic.png");
print("Saving: " + NewName_blue);
path_blue = path + "Splitted channel - Metallic/";
save(path_blue + NewName_blue);
// Save green channel
selectWindow(filelist[i] + " (green)");
NewName_green = replace(filelist[i],"_metallicRoughness.png","_roughness.png");
print("Saving: " + NewName_green);
path_green = path + "Splitted channel - Roughness/";
save(path_green + NewName_green);
// Save red channel
selectWindow(filelist[i] + " (red)");
NewName_red = replace(filelist[i],"_metallicRoughness.png","_AO.png");
print("Saving: " + NewName_red);
path_red = path + "Splitted channel - Ambient Occlusion/";
save(path_red + NewName_red);
}
}