Posted by
Aryeh Weiss on
Nov 05, 2015; 3:23pm
URL: http://imagej.273.s1.nabble.com/help-with-3D-segmentation-tp5014798p5014857.html
Hi Tim
Here is my latest incarnation of the DoG approach, which works on the
active image.
You will need to import the roimanager , or use auto-imports (bad
practice -- I promise to make it right when I have a chance...)
It downscales XY to be the same as Z (I tried going the other way --
then you run out of memory.)
It marks each center with a point ROI. If you then flatten the image and
display in the 3D viewer, you can visualize the result.
Notice that I scale the point locations to work with the original image.
If you are using java 1.8, comment out he last 4 lines of code.
When I have a chance, I will clean it up and post some images to give
you an idea of what you can expect.
Best regards
--aryeh
# shamelessly hacked for Albert Cardona's example
from script.imglib.analysis import DoGPeaks
from script.imglib.color import Red
from script.imglib.algorithm import Scale2D
from script.imglib.math import Compute
from script.imglib import ImgLib
from ij3d import Image3DUniverse
from javax.vecmath import Color3f, Point3f
from ij import IJ
cell_diameter = 4.0 # in microns
minPeak = 20.0 # The minimum intensity for a peak to be considered so.
imp = IJ.getImage()
# Scale the X,Y axis down to isotropy with the Z axis
cal = imp.getCalibration()
scale2D = cal.pixelWidth / cal.pixelDepth
print scale2D
#iso = Compute.inFloats(Scale2D(ImgLib.wrap(imp), scale2D))
# using scale3D shold allow me to scale z in the future, instead of only
downscaling XY
iso = Compute.inFloats(Scale3D(ImgLib.wrap(imp), scale2D, scale2D,1 ))
print type(iso)
# Find peaks by difference of Gaussian
sigma = (cell_diameter / cal.pixelWidth) * scale2D
peaks = DoGPeaks(iso, sigma, sigma * 0.5, minPeak, 1)
print "Found", len(peaks), "peaks"
# Convert the peaks into points in calibrated image space
ps = []
if "ROI Manager" in WindowManager.getImageTitles():
WindowManager.getWindow("ROI Manager").close()
rm = RoiManager()
rm.show()
for peak in peaks:
# imp.setSlice(int(peak[2]))
p = Point3f(peak)
p.scale(cal.pixelWidth * 1/scale2D)
ps.append(p)
print peak[2], peak.tolist(), type(p), p
cellRoi = PointRoi(peak[0]/scale2D,peak[1]/scale2D)
cellRoi.setPosition(int(peak[2]))
rm.addRoi(cellRoi)
print "Found", len(peaks), "peaks"
print type(iso)
# ImgLib.wrap(iso).show()
# Show the peaks as spheres in 3D, along with orthoslices:
univ = Image3DUniverse(1024, 1024)
univ.addIcospheres(ps, Color3f(1, 0, 0), 2, cell_diameter/2,
"Cells").setLocked(True)
univ.addOrthoslice(imp).setLocked(True)
univ.show()
On 05/11/2015 4:11 PM, Feinstein, Timothy N wrote:
> Hello Aryeh,
>
> I am also greatly interested in getting this to work and am grateful that
> you are working this out publicly. Regarding the coarser Z resolution,
> would it help at all to re-slice the image in Z to create the appearance
> of isotropic pixels? I have not tried that specifically but so far I have
> not found satisfactory settings for the 3D watershed approach.
>
> Best,
>
>
> Tim
>
> Timothy Feinstein, Ph.D.
> Research Scientist
> University of Pittsburgh Department of Developmental Biology
>
>
>
>
>
> On 11/5/15, 5:58 AM, "ImageJ Interest Group on behalf of Aryeh Weiss"
> <
[hidden email] on behalf of
[hidden email]> wrote:
>
>> This is an update on the problem I posted.
>>
>> First, thanks to the people who replies with suggestions. From these, I
>> am now following up on two of them.
>>
>> 1. Albert Cardona suggested trying the 3D (actually multi-D) difference
>> of Gaussians (DoG) filter. This looks promising, plus it introduced me
>> to imglib. It works great on isolated cells (actually, everything works
>> great on isolated cells) and seems reasonable for my image, but still
>> needs work. because I have such a dense collection of nuclei, it
>> sometimes detects dark blobs, which are actually an approximately
>> cell-sized island within a sea of nuclei.
>> Albert's sample code displays the result in 3D using the 3D viewer.
>> Unfortunately, java3D does not work in java 1.8, and in Java 1.6, while
>> the java3D test works, the code that generates the 3D view fails -- that
>> will go into a separate thread.
>> The net result is that I can mark the centers of the nuclei (which is
>> why it look promising) but I cannot visualize it in 3D to see if it
>> really looks right.
>>
>> 2. Thomas Boudier suggest some 3D bandpass filtering followed by a
>> seeded watershed. I will work more on finding the right parameters for
>> this approach after I finish with the DoG approach. One problem is
>> that the resolution in Z is much lower that in X-Y. As a result, the
>> watershed does not separate the nuclei along Z. It is not clear to me
>> why the DoG does. However, I still need to learn to to use the output
>> of the watershed -- I may not be interpreting the output correctly.
>>
>> I recently got access to Imaris (basic) with a spot detector. It does a
>> decent job, but since I don't have it on my computer, I plan to solve
>> this with ImageJ.
>>
>> When I have something that works and that I can visualize, I will post
>> it for the benefit of other who, like me, have to muddle their way from
>> 2D to 3D.
>>
>> --aryeh
>> --
>> Aryeh Weiss
>> Faculty of Engineering
>> Bar Ilan University
>> Ramat Gan 52900 Israel
>>
>> Ph: 972-3-5317638
>> FAX: 972-3-7384051
>>
>> On 01/11/2015 4:22 PM, Albert Cardona wrote:
>>> Try this:
>>>
>>>
https://www.ini.uzh.ch/~acardona/fiji-tutorial/#find-peaks>>>
>>> Works with difference of gaussian to find peaks, in nd (the example is
>>> in 3D just like in your data).
>>>
>>> The key in DoG is to determine the two sigmas. A bit of experimentation
>>> will take you there.
>>>
>>> Albert
>>>
>>>
>>> On Nov 1, 2015, at 8:06 AM, Aryeh Weiss <
[hidden email]
>>> <mailto:
[hidden email]>> wrote:
>>>
>>>> I have been asked to do a 3D segmentation of a DAPI stained image,
>>>> such as the image stack available at:
>>>>
https://drive.google.com/open?id=0B9hvIdSL8kGyY0NiRzRkaXlINmM>>>>
>>>> I find that I can do very well in 2D by blurring the image and doing
>>>> peak detection, or gray-scale watershed.
>>>> Gabriel Landini's domes followed by a peak detection or thresholding
>>>> step also works nicely.
>>>> However, I have not succeeded in extending this to 3D, using the 3D
>>>> morphological segmentation tools.
>>>>
>>>> A 3D-domes would be nice, but I have not found that.
>>>> I tried peak detection or 2D-domes and then 3D object counting, but
>>>> there is still too much overlap in the Z-direction, so that nuclei
>>>> which
>>>> overlap vertically are counted as one object.
>>>>
>>>> So I seek to tap into the knowledge available on this list, because I
>>>> am sure someone has already done this type of segmentation.
>>>>
>>>> Thanks in advance
>>>> --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>> --
>> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>
--
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