1

.

I have been using ImageJ to process images, but now I would like to have my workflow entirely in Python, if possible.

Until now I found everything I need using OpenCV, except one thing: ImageJ has a really nice number of thresholding methods which I don't see available in Python (as far as I know).

According to the documentation (here and here), there are a few thresholding methods available in OpenCV. In particular for my images I need the 'intermodes' method.

In a previous question it was mentioned that 'it is usually pretty simple to implement other Threshold Methods using OpenCV'

  1. are you aware of more thresholding methods than the ones listed above for OpenCV or in Python in general?
  2. if not, how would you go about to implement the 'intermodes' method in Python? Just port the original (MATLAB) code to python?

Any suggestions are welcome. Thanks

.

terauser
  • 53
  • 5
  • 1
    That page describes the Intermodes method quite thoroughly: "This assumes a bimodal histogram. The histogram is iteratively smoothed using a running average of size 3, until there are only two local maxima: j and k. The threshold t is then computed as (j+k)/2." You can get the histogram with `calcHist`, smooth it with Numpy or Scipy... – AKX Sep 01 '21 at 15:35
  • Well, it does look like ImageJ reallly does have a lot more options. However, you should check out the [thresholding tutorial](https://docs.opencv.org/master/d7/d4d/tutorial_py_thresholding.html) in the official docs to see if you find anything useful. Things you implement directly in Python should be slower than their OpenCV counterparts. For those methods with MATLAB implementations you may have a better chance of "translating" to numpy. – bfris Sep 01 '21 at 15:40
  • Finally, in numpy you have to be careful with exceeding 255 (or going less than 0) for byte datatypes. Numpy will happily rollover 257 to 1, and OpenCV will automatically truncate. – bfris Sep 01 '21 at 15:42

1 Answers1

1

1. Other Thresholding

OpenCV also has Otsu Thresholding which looks somewhat similar to intermodes

Other Methods are available in scikit-image

2. Making your own

Yes, you just define a function that does the thresholding for you. Make sure to vectorize appropriately with numpy

Eumel
  • 1,298
  • 1
  • 9
  • 19