macro "BaSiC_Statistik_Boost" { run("Close All"); print("\\Clear"); dir = getDirectory("Wähle das Verzeichnis"); list = getFileList(dir); outDir = dir + "Korrekturen" + File.separator; if (!File.exists(outDir)) File.makeDirectory(outDir); // 1. Dateien sammeln validFiles = newArray(0); for (i = 0; i < list.length; i++) { if (endsWith(toLowerCase(list[i]), ".tif")) { validFiles = Array.concat(validFiles, list[i]); } } if (validFiles.length < 2) exit("Nicht genug Bilder!"); setBatchMode(true); // 2. MasterStack erstellen (mit DOPPELTER Kapazität) open(dir + validFiles[0]); w = getWidth(); h = getHeight(); type = bitDepth(); doubleCount = validFiles.length * 2; newImage("BoostStack", type + "-bit black", w, h, doubleCount); stackID = getImageID(); close(validFiles[0]); // 3. Bilder ZWEIMAL in den Stack kopieren (für bessere Statistik) for (i = 0; i < validFiles.length; i++) { open(dir + validFiles[i]); run("Select All"); run("Copy"); close(); selectImage(stackID); // Erster Durchgang (Slice 1-16) setSlice(i + 1); run("Paste"); // Zweiter Durchgang (Slice 17-32) setSlice(i + 1 + validFiles.length); run("Paste"); } setBatchMode(false); selectImage(stackID); // 4. BaSiC Aufruf mit sanften Werten print("BaSiC rechnet mit verdoppelter Statistik..."); run("BaSiC ", "shading_estimation=[Estimate shading profiles] " + "local_background_estimation=[No local background estimation] " + "comparison=Unequal " + "lash_regularization=0.7 " + // Noch etwas sanfter (0.7 statt 0.5) "darkfield_regularization=0.1 " + // Stabilerer Schwarzwert "automatic_shading_profiles_estimation=true"); // 5. Ergebnis finden und speichern wait(2000); correctedID = getImageID(); selectImage(correctedID); // Wir speichern nur die ersten 16 Bilder (die zweite Hälfte war nur für die Statistik) for (i = 1; i <= validFiles.length; i++) { setSlice(i); saveAs("Tiff", outDir + validFiles[i-1]); } print("FERTIG! Statistik wurde optimiert. Bilder in: " + outDir); }