image processing with Numpy / SciPy ... problem in our 1st project, we were given an image f of width w ... however Python is an interpreted language so that we.
Image Processing Prof. Christian Bauckhage
outline additional material for lecture 06 / project 01
image processing with Numpy / SciPy
summary
problem
in our 1st project, we were given an image f of width w and height h and had to create an image g such that
0 if rmin 6 [x, y] − w2 , h2 6 rmax g[x, y] = f [x, y] otherwise
image f
image g
solution
here, we shall briefly sketch how a NumPy / SciPy black belt would accomplish this note that a NumPy / SciPy recipe with a much more detailed discussion will soon be made available on researchgate
preliminaries
assuming that NumPy has been imported as import numpy as np and that the image we are working with is an array f of shape (h,w), we first compute the center point of the image c = np.array(f.shape) / 2. and then compare three possible solutions g1 = mask_out_ring_V1(f, c, 25, 50) g2 = mask_out_ring_V2(f, c, 25, 50) g3 = mask_out_ring_V3(f, c, 25, 50)
the intuitive but na¨ıve solution
def mask_out_ring_V1(f, center, rmin, rmax): h,w = f.shape cy,cx = center g = np.copy(f) for y in range(h): for x in range(w): dstnc = np.sqrt((x-cx)**2 + (y-cy)**2) if dstnc >= rmin and dstnc = rmin) & (dstnc =rmin) & (dstnc