Image Processing

The images package allows students to load, transform, and save digital images. For example, the following Java code loads an image, displays it, converts it to grayscale, and displays the changes:

import images.APImage;
import images.Pixel;
public class TestGrayscale{
    public static void main(String[]args){
        APImage image = new APImage("smokey.jpg");
        image.draw();
        for (Pixel p: image){
            int red = p.getRed();
            int green = p.getGreen();
            int blue = p.getBlue();
            int average = (red + green + blue) / 3;      
            p.setRed(average);
            p.setGreen(average);
            p.setBlue(average);      
        }
        image.draw();
    }
}

 

 

The APImage class includes methods to

  • get the width of an image
  • get its height
  • get a pixel at a given position
  • replace a pixel at a given position
  • iterate through all pixels
  • save an image to a file
  • create a copy (clone) of an image

The Pixel class includes methods to

  • get a pixel's red, green, or blue value
  • replace a pixel's red, green, or blue value

 

Download the images package

View the images API