Skip to content

DagSverreSeljebotn soc codeexample

DagSverreSeljebotn edited this page · 1 revision
Clone this wiki locally
import numpy
cimport c_numpy

def negative_grayscale_image(c_numpy.ndarray img):
  if img.nd != 2:
    raise ValueError("Array is not 2-dimensional")
  if img.dtype != numpy.dtype(numpy.uint8):
    raise ValueError("Array does not contain numpy.uint8 elements")

  cdef int di, dj, i, j
  di = arr.strides[0] / sizeof(c_numpy.npy_uint8)
  dj = arr.strides[1] / sizeof(c_numpy.npy_uint8)
  cdef c_numpy.npy_uint8* buf = <c_numpy.npy_uint8*>
  for i in range(arr.dimensions[0]):
    for j in range(arr.dimensions[1]):
      buf[i * di + j * dj] = 255 - buf[i * di + j * dj]
Something went wrong with that request. Please try again.