// OHSU Ca Imaging - Morphological Segmentation // This is temporary while I figure out how to implement CNMF into a scriptable format. // ================================================================ // Written by Wilson Adams | Siciliano Lab | Sept 2021 // ================================================================ // Assumed stack to process is already open stk = getTitle(); Stack.getDimensions(width, height, channels, slices, frames); f_avg = 50; if (frames<50) { f_avg = frames; } else {} // Make an average intensity projection run("Z Project...", "stop=&f_avg projection=[Average Intensity]"); avgip = getTitle(); run("Enhance Contrast", "saturated=0.35"); // Generate a copy of image to bandpass filter run("Duplicate...", avgip+"_filt"); filt = getTitle(); run("Gaussian Blur...", "sigma=3"); run("Subtract Background...", "rolling=12"); //run("Bandpass Filter...", "filter_large=15 filter_small=8 suppress=None tolerance=5 autoscale saturate"); run("Morphological Filters", "operation=[White Top Hat] element=Disk radius=9"); filt = getTitle(); run("Duplicate...", avgip+"_mask"); setAutoThreshold("Huang dark"); run("Threshold..."); run("Convert to Mask"); mask = getTitle(); run("Duplicate...", avgip+"_dist"); run("Distance Map"); dist = getTitle(); selectWindow(filt); run("Find Maxima...", "prominence=80 output=[Point Selection]"); roiManager("Add"); roiManager("show none"); newImage(avgip+"_max", "8-bit black", 1024, 1024, 1); maxima = getTitle(); selectWindow(maxima); roiManager("Select", 0); roiManager("Fill"); run("Marker-controlled Watershed", "input=&dist marker=&maxima mask=&mask binary calculate use"); rename(avgip+"_roimap"); map = getTitle(); run("Duplicate...", avgip+"_roiext"); rois = getTitle(); setThreshold(1, 65535); run("Threshold..."); run("Convert to Mask"); roiManager("reset"); run("Analyze Particles...", "clear add"); run("Tile"); //run("Bandpass Filter...", "filter_large=15 filter_small=3 suppress=None tolerance=5 autoscale saturate"); //close("\\Others"); // run("TIFF Virtual Stack...", "open=[Z:/Collaborations/2021_09 OHSU/Data/E_drive_final_copy/2021_09 OHSU2021/2021_09_21 Animal 11/A11_S1 (fluo4)/Spontaneous/A10_S5_006.tif]");