08.06.2015 Views

Building Machine Learning Systems with Python - Richert, Coelho

Building Machine Learning Systems with Python - Richert, Coelho

Building Machine Learning Systems with Python - Richert, Coelho

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Computer Vision – Pattern Recognition<br />

We now add the salt (which means some values will be almost white) and pepper<br />

noise (which means some values will be almost black):<br />

lenna = mh.stretch(lenna)<br />

lenna = np.maximum(salt*170, sep)<br />

lenna = np.minimum(pepper*30 + lenna*(~pepper), lenna)<br />

We used the values 170 and 30 as white and black. This is slightly smoother than the<br />

more extreme choices of 255 and 0. However, all of these are choices that need to be<br />

made by subjective preferences and style.<br />

Putting the center in focus<br />

The final example shows how to mix NumPy operators <strong>with</strong> a tiny bit of filtering to get<br />

an interesting result. We start <strong>with</strong> the Lenna image and split it into the color channels:<br />

im = mh.imread('lenna.jpg')<br />

r,g,b = im.transpose(2,0,1)<br />

[ 208 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!