macro "BaSiC_RGB_ColorFix_V19" { run("Close All"); print("\\Clear"); dir = getDirectory("Ordner wählen"); list = getFileList(dir); // Verzeichnisse vorbereiten temp = newArray(dir+"temp_R"+File.separator, dir+"temp_G"+File.separator, dir+"temp_B"+File.separator); for (t=0; t<3; t++) { if(!File.exists(temp[t])) File.makeDirectory(temp[t]); } outDir = dir + "Korrekturen_Farbe" + File.separator; if (!File.exists(outDir)) File.makeDirectory(outDir); validFiles = newArray(0); for (i = 0; i < list.length; i++) { lowName = toLowerCase(list[i]); if ((endsWith(lowName, ".tif") || endsWith(lowName, ".jpg")) && !endsWith(lowName, "/")) { validFiles = Array.concat(validFiles, list[i]); } } setBatchMode(true); // --- SCHRITT 1: Kanäle trennen mit intelligenter Zuweisung --- for (i = 0; i < validFiles.length; i++) { showStatus("Verarbeite: " + (i+1)); open(dir + validFiles[i]); run("Split Channels"); chanIDs = getList("image.titles"); suf = ""; if (i < 10) { suf = "00"; } else if (i < 100) { suf = "0"; } for (j=0; j= 0 || indexOf(tL, "red") >= 0) targetDir = temp[0]; else if (indexOf(tL, "c2") >= 0 || indexOf(tL, "green") >= 0) targetDir = temp[1]; else if (indexOf(tL, "c3") >= 0 || indexOf(tL, "blue") >= 0) targetDir = temp[2]; else targetDir = temp[0]; // Fallback saveAs("Tiff", targetDir + "f_" + suf + i + ".tif"); close(); } } // --- SCHRITT 2: BaSiC Korrektur (unverändert stabil) --- 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); tList = getFileList(temp[c]); if (tList.length > 0) { run("Image Sequence...", "open=[" + temp[c] + "] sort use"); rename("Stack"); nS = nSlices; run("Stack to Hyperstack...", "order=xyczt(default) channels=1 slices=" + nS + " 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; } } } // --- SCHRITT 3: Zusammenbau mit Farb-Check --- setBatchMode(true); if (File.exists(masterPaths[0])) { open(masterPaths[0]); rename("R_FINAL"); } if (File.exists(masterPaths[1])) { open(masterPaths[1]); rename("G_FINAL"); } if (File.exists(masterPaths[2])) { open(masterPaths[2]); rename("B_FINAL"); } if (isOpen("R_FINAL")) { nS_Final = nSlices; for (i = 1; i <= nS_Final; i++) { selectWindow("R_FINAL"); setSlice(i); run("Duplicate...", "title=r"); run("8-bit"); if (isOpen("G_FINAL")) { selectWindow("G_FINAL"); setSlice(i); run("Duplicate...", "title=g"); run("8-bit"); } else { newImage("g", "8-bit black", getWidth(), getHeight(), 1); } if (isOpen("B_FINAL")) { selectWindow("B_FINAL"); setSlice(i); run("Duplicate...", "title=b"); run("8-bit"); } else { newImage("b", "8-bit black", getWidth(), getHeight(), 1); } // HIER findet die Hochzeit statt: run("Merge Channels...", "c1=r c2=g c3=b create"); run("Stack to RGB"); run("Enhance Contrast", "saturated=0.35"); saveAs("Tiff", outDir + "Korrektur_" + i + ".tif"); close(); } } setBatchMode(false); // --- SCHRITT 4: CLEANUP --- for (m=0; m<3; m++) { if (File.exists(masterPaths[m])) File.delete(masterPaths[m]); } for (d=0; d<3; d++) { tFiles = getFileList(temp[d]); for (f=0; f