For the activities on this page, I have used the sample picture flowers.jpg You can use an image of your own, or you can download the flowers image and use it. If you use an image of your own, make sure it is not too large. Less than 400x400 pixels would be best.
Exploring Pictures
JES has an inbuilt tool for exploring pictures.
In the command window, load a picture of your choice by typing pict=makePicture(pickAFile())
Now from the menus at the top, choose Media Tools >Picture Tool. Select pict (the location of your image). Now you can get information about your image and the colours at various locations.
Loading an Image and a Pixel
From previously, you need the following commands to get at your pixels:
Load a picture of your choice into a storage location named pict by typing the following in the command window:
pict=makePicture(pickAFile())
To load the pixel at coordinates (1,1) into a location named pixel, type the following
pixel=getPixel(pict, 1,1)
X and Y Coordinates of a Pixel
| Pixels know where they came from. You can ask them their x and y
coordinates with getX and getY.
|
>>> print getX(pixel) 1 >>> print getY(pixel) 1 |
Getting and Setting Colours for Pixels
| You can ask a pixel for its colour with getColor | >>> print getColor(pixel) color r=64 g=65 b=69 |
| Each pixel knows how to getRed and setRed (Green and blue work similarly.) | >>> print getRed(pixel) 64 >>> setRed(pixel,255) >>> print getRed(pixel) 255 |
| You can set the colour with setColor. Colour objects know their red, green, and blue components. | >>> setColor(pixel,color) |
| You can make new colours with makeColor. | >>> newColor=makeColor(0,100,0) >>> print newColor color r=0 g=100 b=0 |
| repaint Picture displays don't automatically get updated. If you show your picture and then change the pixels, you will need to use repaint to update it |
>>>repaint(pict) |
Modifying Some PixelsThe following example program will modify 4 pixels of the image and change them to green. They are the pixels at coordinates (50,100) (51,100) (52, 100) (53, 100)
You can see the effect on the adjacent image. So do we need to change every pixel individually? The answer is yes, but the good news is that we can write programs to make it quick and efficient. |
![]() |
![]() |
|
Saving Your Finished Picture
When you have finished manipulating a picture, you can write it to a new file by using writePictureTo then giving a path and filename to save it to. Make sure you put .jpg on the end of the filename.
Note: On Windows machines, you need to put an r in front of the filepath. That's so that Python correctly interprets it as a path.
>>> writePictureTo(picture,r"c:\docs\newpicture.jpg")
![]() |
|






