Before you keep reading...
Runestone Academy can only continue if we get support from individuals like you. As a student you are well aware of the high cost of textbooks. Our mission is to provide great books to you for free, but we ask that you consider a $10 donation, more if you can or less if $10 is a burden.
Before you keep reading...
Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.
🤔 A Preview of the End Goal¶
Computer Programming can be one of the most rewarding experiences ever. You get to create things inside the computer that can do wondrous tasks. From understanding human speech, to image processing, to computer generated animation, you can do almost anything with code! However like any other skill that you learn you have to walk before you run. You would not expect to sit down at a piano for the first time and play Beethoven’s Piano Sonata No.32; Op.111 in C Minor You have to work up to that with lots of practice. It is no different with writing code.
In this project the goal is to give you an idea of the kinds of things you will be able to do by the end of this course. You are not going to understand the code that we give you in this project, but you will be able to use it to do some cool things.
For many of you reading this or taking a first course in computer science that there are many unfamiliar aspects of writing code. The text editor used to create code may seem primitive as it lacks any kind of formatting. The Python interpreter itself may seem incredibly annoying to you at first, as programming languages only do what you tell them. They have no intelligence, they don’t do what you mean they do exactly what you tell them. And if in the process of telling the computer what you want it to do, by writing code, you make a little typo, or forget a particular character the computer will just give you an error message and sit there stupidly waiting for you to fix it! Don’t let that discourage you, especially early on, dealing with errors is a normal part of the process and will get easier as time goes by.
Image Processing Functions¶
Here is an example of a Python program that converts a color image to be black and white. You may or may not be able to look at the code and figure out what it does at this point, but this is definitely an example of something you will be able to do on your own by the end of the course.
The window above contains the source code for a procedure that converts an image to black and white. This procedure is often called a function, because it is a reusable bit of code that you might use in many different situations. As a programmer you will work with source code a lot. If we were to describe the process above in english this is how we might describe what is going on:
Get the height and width of the image.
Process every pixel in the image (located at a particular row and column) as follows:
Get the red, green, and blue values of the pixel
If the average value of red, green and blue is more than 127 then make a new all white pixel. Otherwise make a new all black pixel.
Replace the old color pixel with either the white or black pixel as deteremined in step b.
The following activecode editor contains 10 different image processing functions (process1, process2, … process10) Each of these functions accepts an image as a parameter and returns a transformed image. A few of the functions take a second parameter that tells the function how to do its job.
Your first task is to experiment with the different functions to discover what they do. You can use either of the supplied images in your experimenting as sometimes one image “works better” for demonstrating an effect than the other. Before you try each function, you might look at the code for it in the box above and see if you can make a prediction about what it does. Don’t worry if it looks like complete gibberish to you you can still do this just by experimenting with the different processes.
The following code box gives you a framework for trying each process.
Now it is your turn to combine these various effects together. The output from one function can be passed as the input toa new function for example: process1(process4(myimg)) Will combine the effects of process1 and process4. You can combine as many of these together as you wish. Experiement as much as you want to see what kind of creative effects you can achieve.
Post Project Questions
During this project I was primarily in my...
- 1. Comfort Zone
- 2. Learning Zone
- 3. Panic Zone
Completing this project took...
- 1. Very little time
- 2. A reasonable amount of time
- 3. More time than is reasonable
Based on my own interests and needs, the things taught in this project...
- 1. Don't seem worth learning
- 2. May be worth learning
- 3. Are definitely worth learning
For me to master the things taught in this project feels...
- 1. Definitely within reach
- 2. Within reach if I try my hardest
- 3. Out of reach no matter how hard I try