There are many different ways you can edit a photo using JES. This includes adding a grayscale filter or a negative filter. You can also mirror the image, or enhance a particular color.

How to Create Grayscale Images

Many easy-to-use photo editing apps let you edit images in different ways. One of these includes adding a grayscale filter. In JES, you can edit images to use a grayscale filter by changing the color of each pixel to use white, gray, or black.

JES uses the Jython programming language, which is very similar to Python and follows the same indentation rules. If needed, you can look at some useful Python commands for beginners to get you up to speed.

Create a new function called makeGrayscalePicture(): def makeGrayscalePicture(): Inside the new function, use the pickAFile() function to ask the user to select an image. Use the makePicture() function to create a picture object from the selected file: file = pickAFile() pic = makePicture(file) Use the getPixels() function to get an array of all the pixels inside the selected image: pixels = getPixels(pic) Use a for-loop to loop through each pixel in the image: for pixel in pixels: Inside the for-loop, get the RGB value of the pixel. You can store the red, green, and blue values of the color into different variables. r = getRed(pixel)g = getGreen(pixel)b = getBlue(pixel) Calculate the average value of each color. You can do this by adding the red, green, and blue values and dividing the total by 3: average = (r + g + b) / 3 Set all the red, green, and blue values to the same value. This will make the pixel gray. setRed(pixel, average)setGreen(pixel, average)setBlue(pixel, average) After the for-loop, display the picture: show(pic) Click on the Load Program button, located between the programming area and the command line. Run the function using the command line area: makeGrayscalePicture() Use the file explorer to select an image. Click on Open. Wait for the function to finish processing the image. A new window will open to display the new grayscale image.

How to Create Negative Images

A negative image is an image where the light areas of the photo appear darkened, and the dark parts of the photo appear lightened. You can create this effect by modifying the red, green, and blue values of each pixel.

Create a new function called makeNegativePicture(): def makeNegativePicture(): Inside the new function, use the pickAFile() function to ask the user to select an image. Use the makePicture() function to create a picture object from the selected file: file = pickAFile() pic = makePicture(file) Use the getPixels() function to get an array of all the pixels inside the selected image: pixels = getPixels(pic) Use a for-loop to loop through each pixel in the image: for pixel in pixels: Inside the for-loop, get the red, green, and blue values for the pixel: r = getRed(pixel)g = getGreen(pixel)b = getBlue(pixel) To create the negative effect, get the opposite value of the color on the RGB spectrum. For example, if the red value is 100, the opposite value would be 255 - 100, which is 155. newRed = 255 - rnewBlue = 255 - gnewGreen = 255 - b Replace the color of the pixel with the new red, green, and blue values: setRed(pixel, newRed)setBlue(pixel, newBlue)setGreen(pixel, newGreen) After the for-loop, display the picture: show(pic) Click on the Load Program button, located between the programming area and the command line. Run the makeNegativePicture() function from the command line: makeNegativePicture() Use the file explorer to select an image. Click on Open. A new window will open to display the negative image.

How to Enhance a Particular Color in an Image

You can also use JES to enhance specific colors of an image. For example, you can double the red value of each pixel to make the picture appear more red.

Create a new function called alterReds(): def alterReds(): Inside the new function, use the pickAFile() function to ask the user to select an image. Use the makePicture() function to create a picture object from the selected file: file = pickAFile() pic = makePicture(file) Use the getPixels() function to get an array of all the pixels inside the selected image: pixels = getPixels(pic) Use a for-loop to loop through each pixel in the image: for pixel in pixels: Inside the for-loop, get only the red value of the pixel: r = getRed(pixel) Double the red value and store it in a new variable: enhancedRed = r*2 Replace the red value of the pixel with the new, enhanced value. As an example, if the original RGB value of the pixel was rgb(100, 50, 50), the new value would be rgb(200, 50, 50). setRed(pixel, enhancedRed) After the for-loop, display the image: show(pic) Click on the Load Program button, located between the programming area and the command line. Run the function using the command line area: alterReds() Use the file explorer to select an image. Click on Open. A new window will open to display the edited image.

How to Mirror an Image

To mirror an image, every pixel on the left side of the image must exactly match the opposite pixel on the right side.

You can do this by creating a new empty image with a white background. You can then copy each pixel to create the new mirrored image.

Create a new function called mirror(): def mirror(): Inside the new function, use the pickAFile() function to ask the user to select an image. Use the makePicture() function to create a picture object from the selected file: file = pickAFile() pic = makePicture(file) Get the height and width of the selected image: width = getWidth(pic)height = getHeight(pic) Use the makeEmptyPicture() function to create a blank image. A blank image is a picture with a white background. Double the width so that you can fit the original image on the left side, and the flipped image on the right side: mirroredPic = makeEmptyPicture(width2, height) Create a for-loop to loop through each x and y coordinate of the original image. Inside the for-loop, get the pixel stored at that location: for x in range(0, width):    for y in range(0, height):        originalPix = getPixel(pic, x, y) Still inside the for-loop, get the pixel in the new blank image at the same x and y location. This is going to be the left side of the mirrored image: leftMirrorPixel = getPixel(mirroredPic, x, y) Copy the color of the original pixel to the pixel on the left side of the new image: setColor(leftMirrorPixel, getColor(originalPix)) Do the same thing for the right side. The y coordinate will be the same. Since the x coordinate will be from the right side, subtract the x coordinate from the full width of the new mirrored picture: rightMirrorPixel = getPixel(mirroredPic, (width2)-x-1, y) Copy the color of the original pixel to the pixel on the right side of the new image: setColor(rightMirrorPixel, getColor(originalPix)) After the for-loop, display the image: show(mirroredPic) Click on the Load Program button, located between the programming area and the command line. Run the mirror() function from the command line: mirror() Use the file explorer to select an image. Click on Open. A new window will open to display the mirrored image.

Editing Images Using JES

Now you hopefully understand how to edit photos in JES using a variety of techniques. These are not the only techniques you can apply to photos, so you can experiment more with other possibilities in JES.

If you want to improve your Python skills, short and fun projects are a great way to understand key Python concepts.