Posted by
Aryeh Weiss on
URL: http://imagej.273.s1.nabble.com/help-with-3D-segmentation-tp5014798p5015214.html
On 10/12/2015 10:00 PM, Feinstein, Timothy N wrote:
> Hello Aryeh and others,
>
> Thank you!! The droplet finder plus Gaussian blur and background
> subtraction works extremely well for nucleus detection in 3D tissue. I
> put together the script at the bottom based on yours to get the most
> reliable results with our data. The live preview was essential for
> calibrating the variables correctly.
>
> Some follow-up questions:
>
> Fiji can do Gaussian blur and median filtering in 3D. Is there any
> advantage to doing it that way? Does the extra time offset any precision
> improvement?
In my case, it did not matter. In X-Y, the resolution is high enough
that without blurring their would be many split nuclei,
because the nuclear staining is more donut like (with significant
variance).
In Z that is not the case, so I stayed with 2D blurring.
> Also, I am having trouble scripting the final quality control step. Right
> now I export the results, filter outliers in Excel and re-import the X and
> Y positions via Import>XY CoordinatesÅ That works pretty well when I
> overlay it on a max intensity projection, although it misses nuclei
> sitting on top of each other in the stack. It would be nice to preserve
> the masks from the live preview window as a stack image. Alternatively I
> wonder whether it would be possible to draw a small sphere centered on
> each XYZ centroid. Say, make a stack with spheres and merge that with the
> data stack using color merge, with spheres in red and data in green. You
> could pretty quickly judge which nuclei are inappropriately detected.
> This is just an idea; drawing a sphere in a stack centered on a designated
> XYZ position is outside my current abilities.
Below I appended an updated version of a python script which will prompt
for a file that contains a particle results table (as generated by
droplet finder) and produces a point ROIset which marks the center of
each particle (as listed in the particle results table). If you flatten
this onto the original 3D stack, you can use the 3D-viewer (in Java 1.6)
to get a reasonable idea of how well it is working. Even scrolling
though the stack gives you an idea of how well it is doing.
Another thing I did was to create a blank image stack, flatten the point
ROIs into that, threshold and dilate to get larger marks (like spheres)
at the centers. The the two stacks can be overlayed in the 3D viewer.
I still need to play more with the other approach (difference of
Gaussians), which also shows promise.
However, the nice thing about the DF plugins is that they take care of
processing the 3D watershed results and producing the Particle Results
table.
The person for whom I did this just needed a count of the cells, and he
is currently running it on lots of images to see how it works.
> My version of the nucleus detector (40x 1.2 water lens; 0.11 x 0.11 x 0.5
> um pixels):
>
> dupTitle=getTitle
> BG = getNumber("Enter background:",80);
I wonder if you can use a broad Gaussian filter, or one of the various
BG subtraction/estimation tools,
to find the background for subtraction.
> run("Subtract...", "value=BG stack");
> run("Despeckle", "stack");
Is Despeckle needed given the 3D median that you run in the next line?
> run("Median 3D...", "x=2 y=2 z=2");
> run("Gaussian Blur...", "sigma=0.70 scaled stack");
> run("32-bit");
> run("Brightness/Contrast...");
> run("Enhance Contrast", "saturated=0.35");
> run("DF_Filterstacker", "maximal_feature_size=8 minimal_feature_size=3
> z/x_aspect_ratio=5.000 radius_x=2 radius_y=2 radius_z=2 invert
> image=[BP_"+dupTitle+"] mask=[WS_BP_"+dupTitle+"] area_threshold=0.150
> maximum_threshold=0.30 connect_threshold=0.40 slice=1");
>
>
> On 05/11/2015 12:58 PM, Aryeh Weiss wrote:
>> This script produces a table called "Particle Results", with (among
>> other things) the X, Y, and Z coordinates of the objects.
>>
>>
"""
This script converts the output of the droplet finder plugin (Paticle
Results)
to a set of point ROIs whcih can be used to mark the drops (in my case,
nuclei)
on the original image.
Input: A particle-results table which was generated by the Droplet
Finder plugin
http://imagejdocu.tudor.lu/doku.php?id=plugin:analysis:droplet_counter:startOutput: A ROI set (in an open ROI Manager window) which contains a
single PointRoi
for each blob that is listed in the particle-results table.
Author: Aryeh Weiss
Last modified: 22 Nov 2015
"""
from ij import IJ, WindowManager
from ij.plugin.frame import RoiManager
from ij.measure import ResultsTable
from ij.gui import PointRoi
from ij.io import DirectoryChooser, OpenDialog
DEBUG = False
# Prompt for the input particle-results table
op = OpenDialog("Choose input table...", "")
path = op.getDirectory()+ op.getFileName()
tableName = op.getFileName()
tableDir = op.getDirectory()
tablePath = tableDir + tableName
print tablePath
if tableName[-4] == ".":
tablePrefix = tableName[:-4] # assumes that a suffix exists
else:
tablePrefix = inputName
# Open the table as a results table
rt = ResultsTable.open2(tablePath)
#IJ.renameResults("Results")
rt.show("Results") # automatically names the table "Results"
# Create an empty list to hold the 3D blob positions
pos = []
# Populate the 3D position list
for i in range(rt.size()):
pos.append([rt.getValue("position_x",i), rt.getValue("position_y",
i), rt.getValue("position_z", i)])
if (DEBUG):
for i in range(rt.size()):
print pos[i];
print len(pos)
# Some results-table methods require a table named "Results"
IJ.renameResults( "Results" , tableName )
# Close the ROI manager if it is open
# First Deselect and then Delete all ROIs so that the user will not be
prompted to save as overlay
# when closing the ROI manager
if "ROI Manager" in WindowManager.getNonImageTitles():
rm = RoiManager.getInstance()
rm.runCommand("Deselect")
rm.runCommand("Delete")
rm.close()
# Create a new ROI Manager
rm = RoiManager()
rm.show()
# Populate the ROI set by adding the PointRoi objects one at a time to
the ROI manager
for p in pos:
# The PointRoi constructor sets the XY coordinate of the ROI
cellRoi = PointRoi(int(p[0]),int(p[1]))
# setPosition sets the stack slice associated with the PointRoi
cellRoi.setPosition(int(p[2]))
rm.addRoi(cellRoi)
rm.runCommand("Show All without labels")
rm.runCommand("Save", tableDir + tablePrefix + "RoiSet.zip");
Hope you find this useful.
--aryeh
--
Aryeh Weiss
Faculty of Engineering
Bar Ilan University
Ramat Gan 52900 Israel
Ph: 972-3-5317638
FAX: 972-3-7384051
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html