An opencv function similar to matlab's graythresh

Hi i'm trying to convert a matlab code to opencv code. So I need something that does what graythesh in matlab does and give me a proper threshold for my grayscale image. Has this been already implemented in opencv cause I couldn't find it.

Thank you


As @georgesl mentioned, combine THRESH_OTSU with other types, for example:

threshold ( grey_image, bin_image, 0, 255, THRESH_BINARY | THRESH_OTSU );