File Exchange

image thumbnail

Hysteresis Thresholding

version 1.0 (2.13 KB) by

C implementation of Hysteresis Thresholding



View License

This function takes as parameters a grayscale image (real valued matrix of size x*w*1) and two thresholds (low and high), and returns the hysteresis thresholded version.

Hysteresis thresholding performs the following:
- every value below tLo is set to 0
- every value above tHi is set to 1
- the rest of the pixels are set to 1 if they are 4-way connected to any other 1-valued blob (area), 0 otherwise

It should be pretty straightforward to implement an 8-way connection check, if you want.

To compile and use perform the following:
mex hysteresis.c

Comments and Ratings (6)


I wasn't able to get this to work myself, but programing the functionality in Matlab is very easy

highmask = image>tHi;
lowmask = bwlabel(~(image<tLo));
final = ismember(lowmask,unique(lowmask(highmask)));


Denis (view profile)

There seems to be only 1 set of forward-backward propagation set. It'd be nice if the code was extended to do recursively until nothing changes anymore as suggested on

I guess its really just putting the propagation part in a while loop with checking if any pixel switched from 0 to 1.

Great function otherwise!


make sure grayscale image is of type double

Hi when I compiled and executed this code, I got the following error. I invoked it as TI = hysthresh(GI,0.1,0.4), where GI is a grayscale image.

??? Error using ==> hysthresh
YPRIME requires that Y be a 4 x 1 vector.

I also tried commenting this part in the code and recompiling the code. However, it ran out of memory.

hamid afshang

MATLAB Release
MATLAB 6.5 (R13)

Inspired: Circular Matrix computation

MATLAB Online Live Editor Challenge

Win cash prizes and have your live script featured on our website

Learn more

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video