Bernsen Local Thresholding Mahotas

284 views
Skip to first unread message

William Grimes

unread,
Feb 23, 2016, 12:15:31 PM2/23/16
to pythonvision
Hi,


I'm trying to use the Python and Mahotas library for image processing, specifically I am porting a script written for ImageJ to Python. 

A critical component of this involves image segmentation by Bernsen local thresholding, documentation in Python is:


run("Auto Local Threshold", "method=Bernsen  radius=5 parameter_1=15 parameter_2=0 white"); // stack



I want to implement exactly the same thing in Python, and happened to come across the function in Mahotas. I use a radius of 5 and contrast threshold of 15 in python.

I apply the same local thresholding in mahotas as below

binary = mahotas.thresholding.bernsen(image, 5, 15, gthresh={128})



However, there seems to be some difference in the results. It is easiest to see the segmentation contour images below. 

What I think is happening in the thresholding, mahotas for a foreground pixel assigns all pixels in the locality as foreground. ImageJ on the other hand for a foreground pixel only assigns that pixel, then looks at the locality of the next pixel. If that makes sense.

Any help on replicating the exact method as in ImageJ would be much appreciated, I don't want these bloated contours as in Mahotas.


Many Thanks,


Will



ImageJ





Mahotas


William Grimes

unread,
Feb 24, 2016, 6:16:56 AM2/24/16
to pythonvision
Here is a second example using a mahotas example image:























import mahotas as mh
import mahotas.demos

import matplotlib.pyplot as plt

im = mahotas.demos.nuclear_image()
im = im.max(2)

plt.imshow(mh.thresholding.bernsen(im, 5, 15));plt.gray();plt.show();



Same image with ImageJ Bernsen method:

run("Auto Local Threshold", "method=Bernsen  radius=5 parameter_1=15 parameter_2=0 white");




Reply all
Reply to author
Forward
0 new messages