145x Filetype PDF File size 1.33 MB Source: courses.cs.tau.ac.il
Programming for Engineers in Python Recitation 12 Image Processing Plan: Image Processing with numpy Binary segmentation Image gradient Image brightening Morphological operators Erosion Dilation Smoothing Denoising Ternary segmentation 2 A 2D table of values (pixels), each in Grayscale Image 0..255: • 0 = Black • 255 = White 105 114 116 116 160 121 97 90 124 119 188 144 112 116 78 32 19 61 40 3 Image processing – basic functions Reading an image from disk: from scipy import misc im = misc.imread('C:/Koala.jpg') Creating an “empty” image matrix: im = numpy.zeros( (height,width), dtype=numpy.uint8 ) Important: each pixel is in the range 0-255 (type np.uint8) o Numerical operations cause overflow, e.g.: numpy.uint8(200) + numpy.uint8(100) = 44 = 300 mod 256 o Therefore, before doing numerical operations on image pixels, convert the whole image or a specific pixel to int 32-bit using numpy.int_ : a = numpy.uint8(200) ; b = numpy.uint8(100) numpy.int_(a) + numpy.int_(b) = 300 4
no reviews yet
Please Login to review.