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