macro "BaSiC_RGB_JPG_Clean_V17_2" { run("Close All"); print("\\Clear"); dir = getDirectory("Ordner mit JPG-Bildern wählen"); list = getFileList(dir); // Arbeitsverzeichnisse definieren tempR = dir + "temp_R" + File.separator; if(!File.exists(tempR)) File.makeDirectory(tempR); tempG = dir + "temp_G" + File.separator; if(!File.exists(tempG)) File.makeDirectory(tempG); tempB = dir + "temp_B" + File.separator; if(!File.exists(tempB)) File.makeDirectory(tempB); outDir = dir + "Korrekturen_Farbe_JPG" + File.separator; if (!File.exists(outDir)) File.makeDirectory(outDir); // Filter: Nur JPGs, keine Ordner validFiles = newArray(0); for (i = 0; i < list.length; i++) { lowName = toLowerCase(list[i]); if ((endsWith(lowName, ".jpg") || endsWith(lowName, ".jpeg")) && !endsWith(lowName, "/")) { validFiles = Array.concat(validFiles, list[i]); } } if (validFiles.length == 0) exit("Keine JPGs gefunden!"); setBatchMode(true); // --- SCHRITT 1: Kanäle trennen --- for (i = 0; i < validFiles.length; i++) { showStatus("Extrahiere Kanäle: " + (i+1)); open(dir + validFiles[i]); if (bitDepth() == 24 || is("composite")) { run("Split Channels"); tNames = getList("image.titles"); suf = ""; if (i < 10) { suf = "00"; } else if (i < 100) { suf = "0"; } for (j=0; j= 0) saveAs("Tiff", tempR + "f_" + suf + i + ".tif"); else if (indexOf(tL, "green") >= 0) saveAs("Tiff", tempG + "f_" + suf + i + ".tif"); else if (indexOf(tL, "blue") >= 0) saveAs("Tiff", tempB + "f_" + suf + i + ".tif"); close(); } } else { close(); } } // --- SCHRITT 2: BaSiC Korrektur --- paths = newArray(tempR, tempG, tempB); masterPaths = newArray(dir + "master_R.tif", dir + "master_G.tif", dir + "master_B.tif"); for (c = 0; c < 3; c++) { run("Close All"); setBatchMode(false); run("Image Sequence...", "open=[" + paths[c] + "] sort use"); if (nImages > 1) { run("Images to Stack", "name=Stack title=[] use"); } run("Stack to Hyperstack...", "order=xyczt(default) channels=1 slices=" + nSlices + " frames=1 display=Grayscale"); run("BaSiC ", "shading_estimation=[Estimate shading profiles] local_background_estimation=[No local background estimation] comparison=Unequal lash_regularization=1.5 darkfield_regularization=0.2 automatic_shading_profiles_estimation=true"); found = false; for (w=0; w<60; w++) { wait(1000); allTitles = getList("image.titles"); for (m=0; m= 0) { selectWindow(allTitles[m]); saveAs("Tiff", masterPaths[c]); close(); found = true; break; } } if (found) break; } run("Close All"); } // --- SCHRITT 3: Zusammenbau & Export --- setBatchMode(true); open(masterPaths[0]); rename("R_FINAL"); open(masterPaths[1]); rename("G_FINAL"); open(masterPaths[2]); rename("B_FINAL"); nS = nSlices; for (i = 1; i <= nS; i++) { selectWindow("R_FINAL"); setSlice(i); run("Duplicate...", "title=r"); run("8-bit"); selectWindow("G_FINAL"); setSlice(i); run("Duplicate...", "title=g"); run("8-bit"); selectWindow("B_FINAL"); setSlice(i); run("Duplicate...", "title=b"); run("8-bit"); run("Merge Channels...", "c1=r c2=g c3=b create"); run("Stack to RGB"); run("RGB Color"); run("Enhance Contrast", "saturated=0.35"); run("Apply LUT"); run("Input/Output...", "jpeg=100 list_separator=none save_column save_row"); origName = validFiles[i-1]; dotIndex = lastIndexOf(origName, "."); // FIX: Saubere if-else Logik für den Dateinamen ohne Punkt baseName = origName; if (dotIndex != -1) { baseName = substring(origName, 0, dotIndex); } saveAs("Jpeg", outDir + baseName + "_FF.jpg"); close(); } run("Close All"); setBatchMode(false); // --- SCHRITT 4: REINIGUNG --- print("Aufräumen..."); for (m=0; m<3; m++) { if (File.exists(masterPaths[m])) File.delete(masterPaths[m]); } tempDirs = newArray(tempR, tempG, tempB); for (d=0; d<3; d++) { tFiles = getFileList(tempDirs[d]); for (f=0; f