Last active
April 19, 2017 09:16
-
-
Save steveway/3b96366e9bbfe7bee8cbd70427efa718 to your computer and use it in GitHub Desktop.
Cython version of the ordered dither function, immensely faster!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| cimport numpy as np | |
| cimport cython | |
| DTYPE = np.double | |
| ctypedef np.double_t DTYPE_t | |
| DTYPE2 = np.uint8 | |
| ctypedef np.uint8_t DTYPE2_t | |
| @cython.boundscheck(False) # turn off bounds-checking for entire function | |
| @cython.wraparound(False) # turn off negative index wrapping for entire function | |
| cpdef np.ndarray[DTYPE2_t,ndim=2] apply_ordered_dither(np.ndarray[DTYPE2_t,ndim=2] inputarray,np.ndarray[DTYPE_t,ndim=2] bayer_map, int bayer_size): | |
| cdef int width, height, x, y | |
| width = inputarray.shape[0] | |
| height = inputarray.shape[1] | |
| # width, height = inputarray.shape | |
| for y in range(height): | |
| for x in range(width): | |
| inputarray[x, y] = 0 if inputarray[x, y] < bayer_map[x % bayer_size, y % bayer_size] else 255 | |
| return inputarray |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment