To learn the basics of Python we used the book Introduction to Computing and Programming in Python, A Multimedia Approach. The first two chapters were very basic. Although they presented an introduction to basic Python syntax for us, these chapters are meant for someone with little or no previous programming experience. For non-Computer Science majors, these first chapters are a good explanation of universal programming basics, such as how variables work, what an algorithm is, method parameters, etc, without getting too in depth into a topic they might not be that interested in.
As for the next couple chapters (particularly 3-5, we did not explore beyond chapter 5, as it didn’t pertain to the image manipulation we were interested in), they presented a good background into image manipulation. While becoming familiar with Python, we were also able to learn, understand, and develop image manipulation algorithms.
The technique for learning to program employed in this book is good for those students who aren’t interested in becoming expert programmers or who don’t want to take the time to delve into the depths of programming (at least not yet). Instead of writing tedious, uninteresting programs that output strings or numbers, this book allows beginner programmers to write simple methods that can produce (hopefully) visually appeasing output and keep them interested in the subject.
Posts Tagged ‘python’
A Book Review
November 12th, 2009Working with Blender
November 2nd, 2009Stephanie and I have started looking at the 3D imaging program Blender. It’s a very large and complex program and we’re still trying to figure out just how to navigate around it.
However, much progress has been made, especially with becoming familiar with the idea of scripting. The tutorial in the Blender 3D: Noob to Pro wikibook (http://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro), was a good starting point in learning 1) how to navigate around Blender’s Python API, such as its built-in text editor; 2) the fundamentals of how scripting works and some basic Blender Python commands. This involved using the NMesh Module, which allows one to create a NMesh object and then add vertices and faces to the object.
Creating the NMesh object:
obj = NMesh.GetRaw()
Creating a vertex and adding it to the the NMesh object’s vert list:
v0 = NMesh.Vert(0.0, 0.0, 0.0)
obj.verts.append(v0)
Creating a face, give it some vertices, then add it to the NMesh object’s faces list:
f0 = NMesh.Face()
f0.v.append(obj.verts[3])
f0.v.append(obj.verts[4])
f0.v.append(obj.verts[2])
obj.faces.append(f0)
In this way I was able to create multiple faces, which utilized many vertices, and eventually create a 3D pyramid:

A pyramid created from a Blender Python script
Next, I tried a little more complex figure and created a box sitting on a 2D plane (I like to call it a building):

A more complex 3D object
In the near future, I would like to play around with the other available modules of the Blender Python API (http://www.blender.org/documentation/249PythonDoc/), especially the Mesh Module, which I would like to compare to NMesh and see which one, if either, would be better suited to work with over the course of this project. Also, I would like to look into more efficient object creation techniques, via for loops and such.
Our First Week
September 28th, 2009(A Retrospective)
Diving right in! We’ve decided to start off this project by learning Python- specifically, the manipulation of pictures. Sara and I are using Mark Guzdial and Barbara Ericson’s “Introduction to Computing and Programming in Python, A Multimedia Approach”, and after skimming the first few chapters and reading up on the three-part makeup of pixels, we tried a few problems of our own, with questionably professional test images.
“clearRed” was easy enough to understand- I’m loving how simple for-loops are in Python compared to Java or C; we basically pick an index to represent each pixel of the function’s input picture, and then cycle through each pixel and modify the numeric value of- in this case- the “red” component.
So, this is Zon, our source image and the result after we applied “clearRed”. It’s really the sun, but it took us about ten minutes to figure out that “zon”, which was the file’s name, is not German, but in fact Dutch. I know, right? You learn something new every day.

Zon and Apocolypse Zon
After getting used to single for-loops and manipulating (or removing) colors, we tried Posterization, which lumps values together based on their luminance, “flattening” a picture (like a poster!)
Next we moved on to nested for-loops and multiple input images, which lets us get into more interesting effects like blurring (averaging the luminance values of surrounding pixels) and line-detection, which looks at the absolute value of the luminance of surrounding pixels.
Basically, a whole lot of fun in which we messed with a picture of a monkey.

George, Posterized George, and Blurry/Line-erific George