Skip to content

Commit

Permalink
debug color
Browse files Browse the repository at this point in the history
debug color
  • Loading branch information
NSLog0 committed Oct 23, 2012
1 parent 18c4049 commit e86b73c
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 55 deletions.
Binary file modified build/classes/image2d/EdgeDetector.class
Binary file not shown.
Binary file modified build/classes/image2d/EdgeOperator.class
Binary file not shown.
Binary file modified build/classes/image2d/ImageProcessor.class
Binary file not shown.
6 changes: 4 additions & 2 deletions src/image2d/EdgeDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ public static BufferedImage findEdgeSobel(BufferedImage _image) {
double vertical[][] = new EdgeOperator().edgeVertical();
// copy image form original
BufferedImage imageOutput = new Unitys().copyImg(_image);

// get result
return ImageProcessor.convolution(_image, horizontal, vertical);
return new EdgeOperator().sobelOperation(_image, horizontal, vertical);

}


}
61 changes: 61 additions & 0 deletions src/image2d/EdgeOperator.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package image2d;

import java.awt.Color;
import java.awt.image.BufferedImage;

/**
Expand Down Expand Up @@ -35,4 +36,64 @@ public double[][] edgeVertical() {
return sobel;
}
// ----------------------------- end sobel ---------------------------------



public BufferedImage sobelOperation(BufferedImage _image, double horizon[][], double vertical[][]) {
BufferedImage imageOutput = new Unitys().copyImg(_image); // Set initial BufferedImage
int pixel[][] = doPixels.getPixel(_image); //use to store pixels

int kernelXY = horizon.length / 2;
// calculate image
for (int i = 0 + kernelXY; i < imageOutput.getWidth() - kernelXY - 1; i++) {
for (int j = 0 + kernelXY; j < imageOutput.getHeight() - kernelXY - 1; j++) {
int a = 0, r = 0, g = 0, b = 0; // store RGB
int horiz = 0, verti = 0;
// horizontal
for (int k = -(kernelXY); k < kernelXY + 1; k++) {
for (int l = -(kernelXY); l < kernelXY + 1; l++) {

// calculate a RGB by chip bit
a += RGB.alpha(pixel, i - k, j - l) * horizon[k + kernelXY][l + kernelXY];
r += RGB.red(pixel, i - k, j - l) * horizon[k + kernelXY][l + kernelXY];
g += RGB.green(pixel, i - k, j - l) * horizon[k + kernelXY][l + kernelXY];
b += RGB.blue(pixel, i - k, j - l) * horizon[k + kernelXY][l + kernelXY];

} //end k
}//end j
horiz += ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff);



// vertical
for (int k = -(kernelXY); k < kernelXY + 1; k++) {
for (int l = -(kernelXY); l < kernelXY + 1; l++) {

// calculate a RGB by chip bit
a += RGB.alpha(pixel, i - k, j - l) * vertical[k + kernelXY][l + kernelXY];
r += RGB.red(pixel, i - k, j - l) * vertical[k + kernelXY][l + kernelXY];
g += RGB.green(pixel, i - k, j - l) * vertical[k + kernelXY][l + kernelXY];
b += RGB.blue(pixel, i - k, j - l) * vertical[k + kernelXY][l + kernelXY];

} //end k
}//end j
verti += ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff);

// add x-coordinate,y-coordinate form (diff) wiht sqrt(x.diff^2)+sqrt(y.diff^2)+
double rgb = Math.sqrt(Math.pow(horiz, 2.0)) + Math.sqrt(Math.pow(verti, 2.0));
// set color 0-255
if (rgb > 255) {
rgb = 255;
}
if (rgb < 0) {
rgb = 0;
}
Color c = new Color((int) rgb, (int) rgb, (int) rgb);
//set RGB revert to image
imageOutput.setRGB(i, j, (int) c.getRGB());
}// end i
} //end j

return imageOutput;
}
}
54 changes: 1 addition & 53 deletions src/image2d/ImageProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,59 +39,7 @@ public static BufferedImage load_image(String url) {
//---------------------------------end--------------------------------------

// -----------------------------Convolution --------------------------------
public static BufferedImage convolution(BufferedImage _image, double horizon[][], double vertical[][]) {
BufferedImage imageOutput = new Unitys().copyImg(_image); // Set initial BufferedImage
int pixel[][] = doPixels.getPixel(_image); //use to store pixels

int kernelXY = horizon.length / 2;
// calculate image
for (int i = 0 + kernelXY; i < imageOutput.getWidth() - kernelXY - 1; i++) {
for (int j = 0 + kernelXY; j < imageOutput.getHeight() - kernelXY - 1; j++) {
int a = 0, r = 0, g = 0, b = 0; // store RGB
int horiz = 0, verti = 0;
// horizontal
for (int k = -(kernelXY); k < kernelXY + 1; k++) {
for (int l = -(kernelXY); l < kernelXY + 1; l++) {

// calculate a RGB by chip bit
a += RGB.alpha(pixel, i - k, j - l) * horizon[k + kernelXY][l + kernelXY];
r += RGB.red(pixel, i - k, j - l) * horizon[k + kernelXY][l + kernelXY];
g += RGB.green(pixel, i - k, j - l) * horizon[k + kernelXY][l + kernelXY];
b += RGB.blue(pixel, i - k, j - l) * horizon[k + kernelXY][l + kernelXY];

} //end k
}//end j
horiz += ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff);


// vertical
for (int k = -(kernelXY); k < kernelXY + 1; k++) {
for (int l = -(kernelXY); l < kernelXY + 1; l++) {

// calculate a RGB by chip bit
a += RGB.alpha(pixel, i - k, j - l) * vertical[k + kernelXY][l + kernelXY];
r += RGB.red(pixel, i - k, j - l) * vertical[k + kernelXY][l + kernelXY];
g += RGB.green(pixel, i - k, j - l) * vertical[k + kernelXY][l + kernelXY];
b += RGB.blue(pixel, i - k, j - l) * vertical[k + kernelXY][l + kernelXY];

} //end k
}//end j
verti += ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff);

// add x-coordinate,y-coordinate form (diff) wiht sqrt(x.diff^2)+sqrt(y.diff^2)+
double rgb = Math.sqrt(Math.pow(horiz, 2.0)) + Math.sqrt(Math.pow(verti, 2.0));
// set color 0-255
if (rgb > 255)rgb = 255;
if (rgb < 0)rgb = 0;

//set RGB revert to image
imageOutput.setRGB(i, j, (int)rgb);
}// end i
} //end j

return imageOutput;
}


public static BufferedImage convolution(BufferedImage _image, double kernel[][], int wigth, int height, int sizeKernel, int kernelXY) {
BufferedImage imageOutput = new Unitys().copyImg(_image); // Set initial BufferedImage
int pixel[][] = doPixels.getPixel(_image); //use to store pixels
Expand Down

0 comments on commit e86b73c

Please sign in to comment.