Computer Architecture I Solution



You are asked to implement a Java program to manipulate the hue property of images.

The suggested steps to complete the activity are as follows:

  1. Read RBG value for each pixel in the given image

  1. Extract Red, Green and Blue values from RGB value using shift operators and masking operators

  2. Convert RGB value to HSB(Hue, Saturation and Brightness). You can use Color.RGBtoHSB() method to convert RGB values to HSB. Note that Hue value will be hard coded already.

  1. Then we need to convert HSB value back to RGB. You can use Color.HSBtoRGB() method for performing the conversion.

  1. Set RGB value to the pixel of the image.

Assume that, this is the original image:

If we set 90 as Hue value, then you program needs to manipulate the image as follows

If Hue = 180

If Hue = 270

A Skeleton for Reading and Manipulating Images in Java


import javax.imageio.*;

import java.awt.image.*;

public class ColorChanger{

public static void main(String args[])throws IOException{

BufferedImage raw,processed;

raw = File(“flower.png”));

int width = raw.getWidth();

int height = raw.getHeight();

processed = new BufferedImage(width,height,raw.getType()); float hue = 90/360.0f;//hard coded hue value

for(int y=0; y<height;y++){

for(int x=0;x<width;x++){

//this is how we grab the RGB value of a pixel at x,y coordinates in the image

int rgb = raw.getRGB(x,y);

//extract the red value

//extract the green value

//extract the blue value

//user Color.RGBtoHSB() method to convert RGB values to HSB

//then use Color.HSBtoRGB() method to convert the HSB value to a new RGB //value

  • set the new RGB value to a pixel at x,y coordinates in the image processed.setRGB(x,y,newRGB);



ImageIO.write(processed,“PNG”,new File(“processed.png”));