Welcome to Dream.In.Code
Getting Java Help is Easy!

Join 136,245 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,222 people online right now. Registration is fast and FREE... Join Now!




Image Processing

 
Reply to this topicStart new topic

Image Processing

soccerizzy26
14 Oct, 2008 - 07:22 AM
Post #1

D.I.C Head
**

Joined: 23 Jan, 2008
Posts: 65

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.
CODE

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 cool.gif. 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.
CODE

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
CODE
             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.
User is offlineProfile CardPM
+Quote Post

Gloin
RE: Image Processing
14 Oct, 2008 - 01:22 PM
Post #2

On MeD.i.Cation
Group Icon

Joined: 4 Aug, 2008
Posts: 723



Thanked: 47 times
My Contributions
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 Oct, 2008 - 01:28 PM
User is offlineProfile CardPM
+Quote Post

soccerizzy26
RE: Image Processing
14 Oct, 2008 - 01:41 PM
Post #3

D.I.C Head
**

Joined: 23 Jan, 2008
Posts: 65

Well thats the thing the actual picture that im using I get to choose thats what the code
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 Oct, 2008 - 01:43 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 03:48AM

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month