// ---------- Vorbereitung ---------- if (isOpen("Log")) { selectWindow("Log"); run("Close"); } close("*"); // ---------- 1. BILDER ÖFFNEN ---------- flatPath = File.openDialog("1. Leerbild (Flatfield) öffnen"); open(flatPath); rename("FLAT_BASE"); run("32-bit"); origPath = File.openDialog("2. Originalbild (fleckig) öffnen"); open(origPath); origName = getTitle(); rename("ORIG_BASE"); run("32-bit"); // ---------- 2. KANÄLE SPLITTEN ---------- selectWindow("FLAT_BASE"); run("Make Composite"); run("Split Channels"); selectWindow("ORIG_BASE"); run("Make Composite"); run("Split Channels"); // ---------- 3. PARAMETER & DIVISION ---------- gSigma = 600; haloProtectionRadius = 15; finalNames = newArray(3); for (c = 1; c <= 3; c++) { fK = "C" + c + "-FLAT_BASE"; oK = "C" + c + "-ORIG_BASE"; targetName = "Final_C" + c; selectWindow(fK); run("Add...", "value=1.0"); imageCalculator("Divide create 32-bit", oK, fK); tempDiv = getTitle(); selectWindow(tempDiv); run("Duplicate...", "title=BG_Model"); run("Median...", "radius=" + haloProtectionRadius); run("Gaussian Blur...", "sigma=" + gSigma); imageCalculator("Divide 32-bit", tempDiv, "BG_Model"); rename(targetName); finalNames[c-1] = targetName; close("BG_Model"); } // ---------- 4. ZUSAMMENFÜGEN ---------- run("Merge Channels...", "c1=["+finalNames[0]+"] c2=["+finalNames[1]+"] c3=["+finalNames[2]+"] create"); run("RGB Color"); rename("FINAL_ADJUSTMENT"); run("Enhance Contrast", "saturated=0.35"); // ---------- 5. MASKE & GLÄTTUNG ---------- run("Duplicate...", "title=MaskenBasis"); run("8-bit"); run("Median...", "radius=3"); setThreshold(0, 255); run("Threshold..."); setOption("BlackBackground", true); waitForUser("Threshold", "Präparat ROT markieren. Dann OK."); run("Create Selection"); if (selectionType() != -1) { close("MaskenBasis"); selectWindow("FINAL_ADJUSTMENT"); run("Restore Selection"); run("Make Inverse"); run("Median...", "radius=4"); run("Select None"); } // Threshold-Fenster sofort schließen if (isOpen("Threshold")) { selectWindow("Threshold"); run("Close"); } // ---------- 6. SCHRITTWEISE MANUELLE KORREKTUR ---------- selectWindow("FINAL_ADJUSTMENT"); // --- TEIL A: FARBE --- run("Color Balance..."); waitForUser("Schritt 1: FARBE", "1. Farbe einstellen.\n2. 'APPLY' klicken!\n3. Dann OK."); if (isOpen("Color Balance")) { selectWindow("Color Balance"); run("Close"); } // --- TEIL B: HELLIGKEIT & KONTRAST --- if (isOpen("B&C")) { selectWindow("B&C"); run("Close"); } run("Brightness/Contrast..."); waitForUser("Schritt 2: HELLIGKEIT", "1. Helligkeit einstellen.\n2. 'APPLY' klicken!\n3. Dann OK."); if (isOpen("B&C")) { selectWindow("B&C"); run("Close"); } // ---------- 7. SPEICHERN ---------- dotIndex = lastIndexOf(origName, "."); baseName = ""; if (dotIndex >= 0) { baseName = substring(origName, 0, dotIndex); } else { baseName = origName; } finalFileName = baseName + "_FF.tif"; savePath = File.getParent(origPath) + File.separator + finalFileName; run("Properties...", "channels=1 slices=1 frames=1 unit=pixel pixel_width=1 pixel_height=1 voxel_depth=1"); saveAs("Tiff", savePath); // ---------- 8. RADIKALER CLEANUP ---------- // Wir nutzen einen Trick, um alles außer dem Hauptbild zu schließen close("*"); // Log-Fenster schließen (häufigster Fehlerherd) if (isOpen("Log")) { selectWindow("Log"); run("Close"); } // Eventuell verwaiste Tool-Fenster schließen if (isOpen("Threshold")) { selectWindow("Threshold"); run("Close"); } if (isOpen("B&C")) { selectWindow("B&C"); run("Close"); } if (isOpen("Color Balance")) { selectWindow("Color Balance"); run("Close"); } // Nur das Endergebnis öffnen open(savePath); run("Select None"); // Ende ohne Log-Eintrag, um das Log-Fenster nicht wieder zu triggern