1 Getting Up and Running 2 Loading and Viewing Your First ...
1 Getting Up and Running
To begin with, make sure that you are using the IPython shell with the PyLab extension. At the time of writing, in a Unix environment, you would type ipython -pylab
This will set up an interactive environment that behaves similarly to the MATLAB environment. Now, we will import some packages that we will need to perform basic operations. You should consult the Python tutorial to get a better understanding of what is happening. Type import scipy
2 Loading and Viewing Your First Image
Now we are ready to load an image. The PyLab package, which is automatically imported when you launch IPython with the "-pylab" flag, can only import PNG images. (Note: This may have changed with Matplotlib 0.98). So, we will use the imread function from the scipy package: img = scipy.misc.imread("einstein.png")
As you get more familiar with Python, you will learn how to shorten the length of that line by importing the imread function into the main namespace. Again, the reader is referred to the Python tutorial.
Now, let's look at that image: imshow(img)
The Matplotlib package treats the image as just an array of numbers and pseudo-colors it. If we want the image to be displayed in grayscale, we would type: gray()
This sets the colormap of the image to be grayscale.
3 Basic Filtering
Now that we have the image, we'll probably want to begin with some basic filtering. Most of basic filtering functions are in the scipy.signal package, so we'll need to import it: import scipy.signal
Let's convolve the image with a derivative filter: filtered_img = scipy.signal.convolve2d(img,[[-1,1]],"valid") imshow(filtered_img)
In particular, I would like to clarify what the command [[-1,1]] means. Python, unlike MATLAB, does not allow you to create arrays or matrices as literal values in your code. So, [[-1,1]] is a list containing the list [-1,1]. To see how NumPy treats this, you can type array([[-1,1]]) to see how this is converted into an array. To see more, try the command array([[-1,1]]).shape and array([-1,1]).shape and compare the difference.
1
4 Writing Your First Script
Of course, you will not want to type in commands every time. IPython has a nice feature that you can use to run scripts. Typing run?script name? will run the script, then add the variables to the root namespace. To see this, type the following script in: import scipy,scipy.signal from pylab import * img = scipy.misc.imread("einstein.png") filtered_img = scipy.signal.convolve2d(img,[[-1,1]],"valid") imshow(filtered_img) gray() show()
In all the scripts, you will need to import the numerical libraries as the run commands starts with a fairly empty namespace.
5 From Here
At this point, you should consult information available at .You should also read the Python tutorial at .
2
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- matplotlib eds uga
- stereo vision
- documentation
- sesg6025 coursework fractals and integration
- 1 getting up and running 2 loading and viewing your first
- 1 lecture 15 data visualization
- matplotlib 2d and 3d plotting in python
- cs 4476 introduction to computer vision fall 2018 ps0
- python university of pennsylvania
Related searches
- getting your first book published
- getting your first novel published
- get up and running windows update
- 1 or 2 374 374 1 0 0 0 1 168 1 1 default username and password
- 1 or 3 2 0 5 374 374 168 1 1 default username and password
- 1 or 2 711 711 1 0 0 0 1 168 1 1 default username and password
- 1 or 3 2 0 5 711 711 168 1 1 default username and password
- 1 or 2 693 693 1 0 0 0 1 168 1 1 default username and password
- 1 or 3 2 0 5 693 693 168 1 1 default username and password
- 1 or 2 593 593 1 0 0 0 1 or 2dvchrbu 168 1 1 default username and password
- 1 or 3 2 0 5 593 593 or 2dvchrbu 168 1 1 default username and password
- 1 or 2 910 910 1 0 0 0 1 168 1 1 default username and password