luispedro / mahotas

Computer Vision in Python
https://mahotas.rtfd.io
Other
844 stars 148 forks source link

Bernsen thresholding #84

Closed fkim1223 closed 7 years ago

fkim1223 commented 7 years ago

Hi, I recently discovered this python program to try bernsen's thresholding method. I liked the option to change gthresh value. I gave it a try and I was getting a different result from bernsen's method implemented in imagej though. After looking at the code, it appears that there may be an error on line 258: fmean = fmax/.2 + fmin/.2. I think the values should be divided by 2 not 0.2. Is it possible to check and recompile the code if it is an error? Thank you.

luispedro commented 7 years ago

That's a good catch!

fkim1223 commented 7 years ago

Hi Thank you for checking and making the change. I had tried modifying the code myself, and I think the line 259 may also have to be changed to something like np.choose(fptp < contrast_threshold,(f >= fmean, f >= gthresh)). After that, I'm getting a very similar result to that of imagej. I think the difference may be related to the way structural element is defined in both programs. I'll have to compare this later. I'm new to python, and it took me awhile to understand numpy choose command. Please check if my proposed modification makes sense. Would this program process 16 bit image as well?

luispedro commented 7 years ago

Yes, 16 bits should not be a problem.

There may indeed be a difference in whether the comparison to the threshold is performed as a > or a >=. I would actually like to compare with the original publication, but I cannot seem to get it.