Results 1 to 4 of 4
  1. #1
    tenis_09 is offline Member
    Join Date
    May 2010
    Posts
    4
    Rep Power
    0

    Default Pixels and Color

    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 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 do find the color value for adjacent pixels and how do I color one of them black?
    Also, what data type are pixels? (int, double, etc)


    This is the pixel grabbing part of my code:
    Java 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);

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,318
    Rep Power
    25

    Default

    How do I do find the color value for adjacent pixels
    You need to convert the single index to x,y values and then vary the x and y by one to get the adjacent values.
    I don't have the algorithm at hand but it involves using the width of the image to compute which row and column the single dim index is at.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Cross-post: Java Programming - Why does my grayscale image appear black?
    Please do not cross-post without notification.

    The problem is that you're asking unpaid volunteers to help you here, not paid consultants, and most of us mind if we take time away from work/lives/play to try to help someone only to find that we've provided a solution that was already provided in a cross-post hours ago. The proper thing to do is that if you feel you must cross-post, at least provide links in each cross-post to the other, so that folks don't waste time answering something already answered and so that folks can review all discussions that have already occurred.

  4. #4
    tenis_09 is offline Member
    Join Date
    May 2010
    Posts
    4
    Rep Power
    0

    Default

    @Furbarable- I'm sorry...I didn't think of it that way =\ In the future, I will be sure if I do cross post, I will remember to cross-link. I really do appreciate all the help and tips you and other users have given me!! THANK YOU!

    @Norm- thank you!

Similar Threads

  1. Image to pixels
    By Deva in forum New To Java
    Replies: 6
    Last Post: 04-01-2010, 08:35 PM
  2. [COLOR="Navy"]execute .bat file in mysql [/COLOR]
    By msankar.ravi in forum Networking
    Replies: 0
    Last Post: 02-24-2010, 04:27 AM
  3. Modified Pixels
    By monkey04 in forum Java 2D
    Replies: 1
    Last Post: 03-12-2009, 08:15 AM
  4. Blurring pixels
    By tim in forum New To Java
    Replies: 0
    Last Post: 01-01-2008, 02:06 PM
  5. Counting Pixels
    By shaungoater in forum Java 2D
    Replies: 5
    Last Post: 11-29-2007, 05:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •