2 Replies - 1261 Views - Last Post: 14 October 2008 - 02:41 PM Rate Topic: -----

#1 soccerizzy26  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 23-January 08

Image Processing

Post icon  Posted 14 October 2008 - 08:22 AM

I just started image processing and was given an assignment to basically make the top quarter of a picture with a sunset effect, the lower quarter should be lightened, the quarter lower than that in grayscale, and the bottom quarter needs to be negative.

I think the easy part was getting the first class which i called ImageUtility. This class includes all the code needed to do all the actual changes to the picture. I have compiled this class and have no errors. Here is my code for this class.
import java.awt.*; 
	
  public class ImageUtility 
	  { 
		  
		   public static void sunset(Picture pic, int a, int b) 
		   {
			   Pixel[] pixelArray = pic.getPixels();			 
			   Pixel pixs = null;
			   int value = 0;
			   int i = 0;
				
				while (i < pixelArray.length)
				{
					
				pixs = pixelArray[i];
				
				value = pixs.getBlue();
				pixs.setBlue((int) (value * 0.7));
				
				value = pixs.getGreen();
				pixs.setGreen((int) (value * 0.7));
				
				i++;
				}
			}
							   
		   
 
		   public static void lightening(Picture pic, int a, int b) 
		   {
			   Pixel[] pixelArray = pic.getPixels();
			   Color col = null;
			   Pixel pixs = null;
			   
			   for (int i = 0; i < pixelArray.length; i++)
			   {
				   pixs = pixelArray[i];
				   col = pixs.getColor();
				   col = col.brighter();
				   pixs.setColor(col);
				}
			}
		   
 
		   public static void grayscale(Picture pic, int a, int b) 
		   {
			   Pixel[] pixelArray = pic.getPixels();
			   Pixel pixs = null;
			   int amount = 0;
			   
			   for (int i = 0; i < pixelArray.length; i++)
			   {
				   pixs = pixelArray[i];
				   
				   amount = (int) ((pixs.getRed() + pixs.getGreen() + pixs.getBlue()) / 3);
				   
				   pixs.setColor(new Color(amount, amount, amount));
				}
			}
			 
 
		   public static void negativeImg(Picture pic, int a, int b) 
		   {
			   Pixel[] pixelArray = pic.getPixels();
			   Pixel pixs = null;
			   int redValue, blueValue, greenValue = 0;
			   
			   for (int i = 0; i < pixelArray.length; i++)
			   {
				   pixs = pixelArray[i];
				   
				   redValue = pixs.getRed();
				   greenValue = pixs.getGreen();
				   blueValue = pixs.getBlue();
				   
				   pixs.setColor (new Color(255 - redValue, 255 - greenValue, 255 - blueValue));
				}
			}
		}


The part where I'm having trouble is actually implementing the code. I made a class called MultiTrans and have made it so that the user could choose any file they want. In order to brake the picture up into quarters I knew i would have to define the height and width as integers so I did that. This is where I get confused, in the template for my first class my teacher made it so that there would be three objects to use, (picture pic, int a, int B). I have no idea what he want me to input for the objects. Also I'm not sure on how where I should put all of my code.
Here is what I have when I try to implement the sunset effect on an image.
public class MultiTrans
{
	public static void main(String[] args)  
	{ 
		String filename = FileChooser.pickAFile();
		System.out.println(filename);//so the user can choose any picture they want and it will be displayed
		Picture pic = new Picture(filename);
		int Height = pic.getHeight();
		int Width = pic.getWidth();
		
		int c = 0;//first pixel in the picture
		int d = ((height/4-1)*(width)+(width-1));//this should be the last picture in order to just capture the top quarter of the picture
		
		for (int a = 0; a<= d; a++)
		{
			ImageUtility.sunset(pic, 0, int d);
		} 
	} 
pic.show(); 
}



^right now the error message im getting is at this line
			 ImageUtility.sunset(pic, 0, int d);
and it is saying that '.class' expected, which i dont understand because I thought .sunset would be that class. If anyone could help me that'd be great.

Is This A Good Question/Topic? 0
  • +

Replies To: Image Processing

#2 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: Image Processing

Posted 14 October 2008 - 02:22 PM

You will have to create a ImageUtility object

ImageUtility img = new ImageUtility();
img.sunset(pic, 0, int d);

although I doubt you could have the keyword 'int' in the parameters.
It seems you haven't quite grasped the concept of Object Oriented Programming.

The following two variables:

Pixel[] pixelArray = pic.getPixels();
Pixel pixs = null;

are declared in all your methods in the class ImageUtility. What you ought to do is make them instancevariables of the class and assign them values in a constructor-method.

This post has been edited by Gloin: 14 October 2008 - 02:28 PM

Was This Post Helpful? 0
  • +
  • -

#3 soccerizzy26  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 23-January 08

Re: Image Processing

Posted 14 October 2008 - 02:41 PM

Well thats the thing the actual picture that im using I get to choose thats what the code
  String filename = FileChooser.pickAFile();
		System.out.println(filename);//so the user can choose any picture they want and it will be displayed
		Picture pic = new Picture(filename);

is for. But your right I haven't really grasped object oriented programming. But the thing is I can't make the instance variables because that s not part of my assignment but it probably would be easier. But the reason i have
Pixel[] pixelArray = pic.getPixels();

is because that selects all the pixels in the picture that I choose. The thing that I then I have to do is just select 1/4 of those pictures in the MultiTrans class. I know how to do that will a loop but im not sure exactly where to put it.

This post has been edited by soccerizzy26: 14 October 2008 - 02:43 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1