Skip main navigation

Introduction to Images and Pixels

Learn about images and pixels by using code to import the image library, create an image object, and get a list of pixel objects
So let’s look at the code that works on an image or a picture. First thing you have to do of course is import the image library that defines the classes that we’re using to create images. Then we can create an image object. So from a file name, so arch.jpg, then we can ask the image to give us a list of all of its pixels. So we get a list of pixel objects. So images have pixels. And we can loop through the pixel list. So for P in pixel list. And we can set the pixels’ red. So using setRed of zero. And then we can update the pixel and the image.
So we’ve changed the red but we also have to update the image. And then we can show the result by getting a window and drawing the image in that window. And when we do that, because we’re setting the red to zero, what we’re going to see in a moment, takes a little bit of time, is that the original arch looks like it’s being seen through a green filter because what we’ve done is reduce the red so it looks more blue-greeny. This is sort of how water works. Water reduces the amount of red light that comes through so that’s why water looks blue-green. So that’s a little bit about images.

. . . . . . . . . . . . . . . . . .

This video introduces you to images and pixels by showing you code to import the image library, create an image object, and get a list of pixel objects. It also shows you how to loop through the pixel list to set each pixel to a certain color and update the pixel in the image to show the result.

This article is from the free online

The Power of Object-Oriented Programming

Created by
FutureLearn - Learning For Life

Our purpose is to transform access to education.

We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.

We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.

Learn more about how FutureLearn is transforming access to education