# To compile: # python setup.py build_ext --inplace import numpy cimport numpy cimport cython @cython.boundscheck(False) @cython.wraparound(False) ################ # Thresholding # ################ # Threshold with user-specified outputs def threshold(numpy.ndarray[numpy.int32_t, ndim=2] img, numpy.int32_t value, numpy.int32_t hi, numpy.int32_t lo): cdef Py_ssize_t i, j for i in range(img.shape[0]): for j in range(img.shape[1]): img[i,j] = lo if img[i,j] < value else hi