Multi-Level Otsu Thresholding

I would like to create a multi-level Otsu thresholding routine, but before I try to do it, I wondered if anyone has already done the job?
The routine I would like is the same as the 'graythresh' command in Matlab. The default is 2 levels, but I would like it with 3 or 4.
Thanks in advance,
Hello Jason,

The binary version is implemented in method 1 of ImageThreshold. I have never seen an implementation of more than 2 levels so if you find an algorithm I'd be interested in implementing it.

WaveMetrics, Inc.
Hi A.G.
Thanks for the reply.
Here is a copy of the original paper outlining the multi-level threshold:…

As I mentioned, it is already in Matlab as the 'graythresh' command, also you can get a plugin for ImageJ/FiJi from here:

I can send you an example image from my work to explain why I need to do this (in fact I do it already inImageJ, I need to automate the process with my Igor scripts, as it is the major part of the work done outside Igor), but I will have to do this off-forum; Please send me a personal email if so.

I hope this is enough information for you?
Best Wishes,
Hi A.G.
I was wondering if the links above have been any help?
How can I look at the ImageThreshold/M=1 code?
If I could see how you have done the original method, I might stand a good chance of adding in the extra levels.
Hi Jason and A.G.,

I read this thread and out of interest, I read the paper by Liao, Chen and Chung, too. So I tried to implement the algorithm and it seems to work.
I haven't spend much time though to check if it makes sense in terms of image processing. Could you please try the Multilevel Thresholding project and tell me what you think?

Wolfgang Harneit
Hi Wolfgang,

I'm sorry for not replying here sooner. My work priorities shift around quite quickly.
I have been testing your code over the last couple of weeks. It pretty much does exactly what I wanted it to do.

It took me a couple of goes to understand the output you used, but looking through the code I realised you stacked the outputs on a single image with different grayscales per threshold level. I think that having separate images per threshold level would be a minor improvement, but the simple solution is to re-threshold the output image to 'find' the level you need. It's very simple to do that.

Thank you very much for investing the time to writing the code.
I think it is a very nice project, and looking at the downloads, clearly other people also do.