-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update new edge compute
- Loading branch information
Showing
8 changed files
with
544 additions
and
199 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,5 @@ [email protected] | |
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. | ||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. | ||
nbproject/build-impl.xml.data.CRC32=464b3301 | ||
nbproject/build-impl.xml.script.CRC32=3250b5e9 | ||
nbproject/build-impl.xml.stylesheet.CRC32=fcddb364@1.50.2.46 | ||
nbproject/build-impl.xml.script.CRC32=2a31616b | ||
nbproject/build-impl.xml.stylesheet.CRC32=6ddba6b6@1.53.1.46 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project-private xmlns="http://www.netbeans.org/ns/project-private/1"> | ||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/> | ||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/> | ||
</project-private> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,91 @@ | ||
/* | ||
* To change this template, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package image2d; | ||
|
||
import java.awt.Color; | ||
import java.awt.image.BufferedImage; | ||
|
||
/** | ||
* | ||
* @author pratchaya | ||
*/ | ||
public class EdgeOperator { | ||
|
||
// ---------------------------- sobel -------------------------------------- | ||
// ** this template for sobel ** | ||
public static int[][] edgeHorizontal() { | ||
|
||
int sobel[][] = { | ||
{-1, -2, -1}, | ||
{0, 0, 0}, | ||
{1, 2, 1} | ||
}; | ||
|
||
return sobel; | ||
} | ||
|
||
public static int[][] edgeVertical() { | ||
int sobel[][] = { | ||
{-1, 0, 1}, | ||
{-2, 0, 2}, | ||
{-1, 0, 1} | ||
}; | ||
|
||
return sobel; | ||
} | ||
// ----------------------------- end sobel --------------------------------- | ||
|
||
public static BufferedImage sobelOperation(BufferedImage _image, int horizon[][], int vertical[][]) { | ||
BufferedImage imageOutput = new BufferedImage(_image.getWidth(), _image.getHeight(), BufferedImage.TYPE_3BYTE_BGR); // Set initial BufferedImage | ||
|
||
int kernelXY = horizon.length / 2; | ||
// calculate image | ||
for (int i = 0; i < imageOutput.getWidth(); i++) { | ||
for (int j = 0; j < imageOutput.getHeight(); j++) { | ||
int r = 0, g = 0, b = 0; // store RGB | ||
int horiz = 0, verti = 0; | ||
// int p = RGB.getRGBExtended(_image, i, j); | ||
// horizontal | ||
for (int k = -(kernelXY); k < kernelXY + 1; k++) { | ||
for (int l = -(kernelXY); l < kernelXY + 1; l++) { | ||
int p = RGB.getRGBW(_image, i + k, j + l); | ||
// calculate a RGB by chip bit | ||
|
||
r += ((p >> 16) & 0xff) * vertical[k + kernelXY][l + kernelXY]; | ||
g += ((p >> 8) & 0xff) * vertical[k + kernelXY][l + kernelXY]; | ||
b += (p & 0xff) * vertical[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++) { | ||
int p = RGB.getRGBW(_image, i + k, j + l); | ||
// calculate a RGB by chip bit | ||
|
||
r += ((p >> 16) & 0xff) * horizon[k + kernelXY][l + kernelXY]; | ||
g += ((p >> 8) & 0xff) * horizon[k + kernelXY][l + kernelXY]; | ||
b += (p & 0xff) * horizon[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; | ||
} | ||
} | ||
/* | ||
* To change this template, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package image2d; | ||
|
||
import java.awt.Color; | ||
import java.awt.image.BufferedImage; | ||
|
||
/** | ||
* | ||
* @author pratchaya | ||
*/ | ||
public class EdgeOperator { | ||
|
||
// ---------------------------- sobel -------------------------------------- | ||
// ** this template for sobel ** | ||
public static int[][] edgeHorizontal() { | ||
|
||
int sobel[][] = { | ||
{-1, -2, -1}, | ||
{0, 0, 0}, | ||
{1, 2, 1} | ||
}; | ||
|
||
return sobel; | ||
} | ||
|
||
public static int[][] edgeVertical() { | ||
int sobel[][] = { | ||
{-1, 0, 1}, | ||
{-2, 0, 2}, | ||
{-1, 0, 1} | ||
}; | ||
|
||
return sobel; | ||
} | ||
// ----------------------------- end sobel --------------------------------- | ||
|
||
public static BufferedImage sobelOperation(BufferedImage _image, int horizon[][], int vertical[][]) { | ||
BufferedImage imageOutput = new BufferedImage(_image.getWidth(), _image.getHeight(), BufferedImage.TYPE_3BYTE_BGR); // Set initial BufferedImage | ||
|
||
int kernelXY = horizon.length / 2; | ||
// calculate image | ||
for (int i = 0; i < imageOutput.getWidth(); i++) { | ||
for (int j = 0; j < imageOutput.getHeight(); j++) { | ||
int r = 0, g = 0, b = 0 , _r = 0 , _g = 0 , _b = 0; // store RGB | ||
int horiz = 0, verti = 0; | ||
// int p = RGB.getRGBExtended(_image, i, j); | ||
|
||
for (int k = -(kernelXY); k < kernelXY + 1; k++) { | ||
for (int l = -(kernelXY); l < kernelXY + 1; l++) { | ||
int p = RGB.getRGBW(_image, i + k, j + l); | ||
// calculate a RGB by ship bit | ||
// horizontal | ||
r += ((p >> 16) & 0xff) * vertical[k + kernelXY][l + kernelXY]; | ||
g += ((p >> 8) & 0xff) * vertical[k + kernelXY][l + kernelXY]; | ||
b += (p & 0xff) * vertical[k + kernelXY][l + kernelXY]; | ||
|
||
// verticel | ||
_r += ((p >> 16) & 0xff) * horizon[k + kernelXY][l + kernelXY]; | ||
_g += ((p >> 8) & 0xff) * horizon[k + kernelXY][l + kernelXY]; | ||
_b += (p & 0xff) * horizon[k + kernelXY][l + kernelXY]; | ||
|
||
} //end k | ||
}//end j | ||
horiz += ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); | ||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,50 @@ | ||
/* | ||
* To change this template, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package image2d; | ||
|
||
//import java.awt.Graphics2D; | ||
import java.awt.BorderLayout; | ||
import java.awt.Dimension; | ||
import java.awt.Toolkit; | ||
import java.awt.image.BufferedImage; | ||
import javax.swing.JFrame; | ||
|
||
public class Image2D { | ||
|
||
public Image2D() { | ||
Toolkit toolkit = Toolkit.getDefaultToolkit(); | ||
Dimension dim = toolkit.getScreenSize(); | ||
String url = "images/wl2.jpg"; // this program have 4 images : wr.png ,sh.jpg , ca.jpg , icon.jpg ,r1,r2,r3,r4.jpg | ||
BufferedImage image = ImageReader.load_image(url); | ||
image = Gaussian.apply(image, 7, 0.84089642); //.94089642 | ||
image = Grayscale.apply(image); | ||
// image = AutoBalance.apply(image); | ||
image = Threshold.apply(image); | ||
image = Opening.apply(image, 3); | ||
image = Opening.apply(image, 3); | ||
// image = NewClass.h(image, EdgeOperator.edgeVertical()); | ||
image = EdgeDetector.findEdgeSobel(image); | ||
|
||
JFrame frame = new JFrame("Display Image"); | ||
ImagePanel iPanel = new ImagePanel(image); | ||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
frame.getContentPane().setLayout(new BorderLayout()); | ||
frame.getContentPane().add("Center", iPanel); | ||
//frame.setSize(65, 134); | ||
frame.setSize(image.getWidth() + 8, image.getHeight() + 34); | ||
frame.setLocation((int) image.getWidth() / dim.width + 455, (int) image.getHeight() / dim.height); | ||
frame.setVisible(true); | ||
|
||
} | ||
|
||
public static void main(String[] args) { | ||
Image2D i = new Image2D(); | ||
|
||
|
||
} | ||
} | ||
/* | ||
* To change this template, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package image2d; | ||
|
||
//import java.awt.Graphics2D; | ||
import java.awt.BorderLayout; | ||
import java.awt.Dimension; | ||
import java.awt.Toolkit; | ||
import java.awt.image.BufferedImage; | ||
import javax.swing.JFrame; | ||
|
||
public class Image2D { | ||
|
||
public Image2D() { | ||
Toolkit toolkit = Toolkit.getDefaultToolkit(); | ||
Dimension dim = toolkit.getScreenSize(); | ||
String url = "images/wl2.jpg"; // this program have 4 images : wr.png ,sh.jpg , ca.jpg , icon.jpg ,r1,r2,r3,r4.jpg | ||
BufferedImage image = ImageReader.load_image(url); | ||
image = Gaussian.apply(image, 7, 0.84089642); //.94089642 | ||
image = Grayscale.apply(image); | ||
//image = AutoBalance.apply(image); | ||
image = Threshold.apply(image); | ||
image = Opening.apply(image, 3); | ||
image = Opening.apply(image, 3); | ||
image = Opening.apply(image, 3); | ||
image = Closing.apply(image, 2); | ||
image = EdgeDetector.findEdgeSobel(image); | ||
|
||
// swing for tester { | ||
JFrame frame = new JFrame("Display Image"); | ||
ImagePanel iPanel = new ImagePanel(image); | ||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
frame.getContentPane().setLayout(new BorderLayout()); | ||
frame.getContentPane().add("Center", iPanel); | ||
//frame.setSize(65, 134); | ||
frame.setSize(image.getWidth() + 8, image.getHeight() + 34); | ||
frame.setLocation((int) image.getWidth() / dim.width + 455, (int) image.getHeight() / dim.height); | ||
frame.setVisible(true); | ||
// } | ||
|
||
} | ||
|
||
public static void main(String[] args) { | ||
Image2D i = new Image2D(); | ||
|
||
|
||
} | ||
} |