Created
May 22, 2012 23:05
-
-
Save fxthomas/2772207 to your computer and use it in GitHub Desktop.
Quick NumPy usage example
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
#!/usr/bin/python | |
# coding=utf-8 | |
# Import everything you need for image processing | |
from pylab import * | |
# This is an addon that's needed to be able to save the image | |
from scipy.misc import imsave | |
# Read image called "input.jpg" (rename that to whatever you want) | |
image = imread ("input.jpg") | |
# Create a vertical red line : | |
# * Starts at the 40th column | |
# * Height is the image's height | |
# * Width is 20px (so 40th col -> 60th col) | |
image[:, 40:60, 0] = 255 # RED | |
image[:, 40:60, 1] = 0 # GREEN | |
image[:, 40:60, 2] = 0 # BLUE | |
# You can also replicate part of an image using the same syntax | |
image[:, 150:170, :] = image[:, 170:190, :] | |
# Show image (useful for quick tests) | |
imshow (image) | |
show() | |
# Save image to test.jpg | |
imsave ("test.jpg", image) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment