Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Coloring Pixels

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Coloring Pixels

    I want to write an edge detection program that takes two adjacent pixels, computes the color distance between them and compares that to the given threshold. If the color distance is less than the threshold, the left-most pixel will be colored black. If the color distance is greater than the threshold, the left-most pixel will be colored white. How do I do this? I already know how to get the pixels. Now, I just have to manipulate them.

    I need to know:

    -How to get the color value of two adjacent pixels.
    I want to know how to take the color data for two adjacent pixels (the color value will be in the 0-255 scale). So say if pixel1 = 150, pixel2=130, threshold=10. Since pixel1-pixel2=10, which is greater than 10, I want to color pixel1 black.
    -How do I color a pixel black?
    -What data type are pixels? (int, double, etc)

    This is part of my code:
     grabber = new PixelGrabber(logoCopy, 0, 0, -1, -1, false);
            grabber.startGrabbing();
     
    if(grabber.grabPixels())
            {
             height = img.getHeight(null);
             width = img.getWidth(null);
             pixels = new int[width*height]; //this is the array pixels
       //grab the pixels using getPixels()
            int[] data = (int[]) grabber.getPixels();
     
            //go through each row and column to read the value of each pixel
            for(int i=0;i<data.length;i++)
            { //reads the color value of each pixel
                 //alpha=(data[i] >>24) & 0xff; //this is the alpha value (transparency)
                 r = (data[i] >> 16) & 0xff; //this is the red value
      System.out.println("Grayscale =" + r);

    cross post:
    http://www.java-forums.org/java-2d/3...els-color.html
    Java 2D - Pixel Manipulation
    Last edited by Javajava; July 7th, 2010 at 10:33 AM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Coloring Pixels

    This is cross posted on at least two other forums.
    No need to answer here.

  3. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Coloring Pixels

    In the future, please mark solved questions as Solved (using Thread Tools -> Mark as Solved) when the question has been resolved. I have done this for you this time (it looks solved based off of what the other forums have said). If you still have questions concerning this topic, you can re-open this thread by marking this thread as un-solved (same procedure as above)

Similar Threads

  1. Obtaining straightline pixels
    By base2coder in forum Java Theory & Questions
    Replies: 4
    Last Post: September 11th, 2009, 01:58 AM