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

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now