-
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.
new file update
- Loading branch information
Showing
14 changed files
with
205 additions
and
23 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
Image2D/nbproject/genfiles.properties → nbproject/genfiles.properties
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,8 +1,8 @@ | ||
build.xml.data.CRC32=464b3301 | ||
build.xml.script.CRC32=87c50e73 | ||
build.xml.stylesheet.CRC32=[email protected].1.46 | ||
build.xml.stylesheet.CRC32=[email protected].2.46 | ||
# 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=[email protected].1.46 | ||
nbproject/build-impl.xml.stylesheet.CRC32=[email protected].2.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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
compile.on.save=true | ||
user.properties.file=C:\\Documents and Settings\\pratchaya\\.netbeans\\7.1\\build.properties |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?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"/> | ||
</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
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* To change this template, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package image2d; | ||
|
||
//import java.awt.Graphics2D; | ||
import java.awt.image.BufferedImage; | ||
import javax.swing.JFrame; | ||
import java.awt.BorderLayout; | ||
|
||
public class Image2D { | ||
|
||
public Image2D() { | ||
String url = "test.jpg"; | ||
BufferedImage image = ImageProcessor.load_image(url); | ||
image = ImageProcessor.gaussianFillter(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(image.getWidth(), image.getHeight()); | ||
frame.setVisible(true); | ||
|
||
} | ||
|
||
public static void main(String[] args) { | ||
Image2D i = new Image2D(); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* To change this template, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package image2d; | ||
|
||
import java.awt.Graphics; | ||
import java.awt.image.BufferedImage; | ||
import javax.swing.JPanel; | ||
|
||
/** | ||
* | ||
* @author atitp | ||
*/ | ||
public class ImagePanel extends JPanel { | ||
|
||
private BufferedImage image; | ||
|
||
public ImagePanel(BufferedImage _image) { | ||
image = _image; | ||
} | ||
|
||
@Override | ||
public void paintComponent(Graphics g) { | ||
super.paintComponent(g); | ||
if (image != null) { | ||
g.drawImage(image, 0, 0, this); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* To change this template, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package image2d; | ||
|
||
import java.awt.image.BufferedImage; | ||
import java.io.File; | ||
import javax.imageio.ImageIO; | ||
|
||
/** | ||
* | ||
* @author pratchaya | ||
*/ | ||
public class ImageProcessor { | ||
|
||
|
||
|
||
// get image form url to BufferedImage | ||
public static BufferedImage load_image(String url) { | ||
BufferedImage image = null; | ||
try { | ||
image = ImageIO.read(new File(url)); // read file form BufferedImage | ||
|
||
} catch (Exception e) { | ||
System.out.println(e.getMessage()); | ||
} | ||
return image; // return result | ||
} | ||
//---------------------------------end-------------------------------------- | ||
|
||
|
||
|
||
// -----------------------------Convolution -------------------------------- | ||
public static BufferedImage convolution(BufferedImage images, float kernel[][], int wigth, int height, int sizeKernel, int kernelXY) { | ||
BufferedImage imageOutput = images.getSubimage(0, 0, wigth, height); // Set initial BufferedImage | ||
int r = 0, g = 0, b = 0; // Store channel color RGB | ||
RGB c = new RGB(); // Chip bit RGB Class | ||
int pixels[][] = new int[wigth][height]; // Initial array Store image to array and size equal Image size | ||
|
||
|
||
// calculate imageInput -------------------- | ||
for (int i = 0; i < wigth; i++) { | ||
for (int j = 0; j < height; j++) { | ||
// get pixels to array | ||
pixels[i][j] = imageOutput.getRGB(i, j); | ||
for (int k = i; k < sizeKernel - 1; k++) { | ||
for (int l = j; l < sizeKernel - 1; l++) { | ||
int xloc = i + (k - kernelXY); | ||
int yloc = j + (l - kernelXY); | ||
if (xloc >= 0 && xloc < i && yloc >= 0 && yloc < j) { | ||
//try { | ||
|
||
r += c.red(pixels, xloc, yloc) * kernel[i - k + 1][j - l + 1] / 16; // calculate a RED and call red method | ||
g += c.green(pixels, xloc, yloc) * kernel[i - k + 1][j - l + 1] / 16; // calculate a GREEN and call green method | ||
b += c.blue(pixels, xloc, yloc) * kernel[i - k + 1][j - l + 1] / 16; // calculate a BLUE and call blue method | ||
|
||
int rgb = (r << 16) | (g << 8) | b; | ||
imageOutput.setRGB(i, j, rgb); | ||
// } catch (Exception e) { | ||
// System.out.println(e.getMessage()); | ||
// } | ||
|
||
} | ||
} | ||
} | ||
} | ||
} | ||
return imageOutput; | ||
|
||
} | ||
//----------------------------------end----------------------------------------- | ||
|
||
|
||
|
||
|
||
|
||
// -------------------------------Fillter -------------------------------------- | ||
public static BufferedImage gaussianFillter(BufferedImage img) { | ||
|
||
float gaussian[][] = { | ||
{7, 2, 7}, | ||
{2, 4, 2}, | ||
{7, 2, 7} | ||
}; | ||
|
||
// get size imageInput and kernel | ||
int wight = img.getWidth(); // image wight | ||
int heigth = img.getHeight(); // image hight | ||
int kernelSize = gaussian.length; // size kernel | ||
int kernelXY = kernelSize / 2; // find a center of kernel | ||
|
||
// make a result with convolution method | ||
return convolution(img, gaussian, wight, heigth, kernelSize, kernelXY); // call function get result | ||
|
||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* To change this template, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package image2d; | ||
|
||
public class RGB { | ||
|
||
// shift bit red color | ||
public int red(int pixels[][], int x, int y) { | ||
int r = 0; | ||
r = (pixels[x][y] >> 16) & 0x000000FF; | ||
return r; | ||
} | ||
// shift bit green color | ||
|
||
public int green(int pixels[][], int x, int y) { | ||
int g = 0; | ||
g = (pixels[x][y] >> 8) & 0x000000FF; | ||
return g; | ||
} | ||
// shift bit blue color | ||
|
||
public int blue(int pixels[][], int x, int y) { | ||
int b = 0; | ||
b = (pixels[x][y]) & 0x000000FF; | ||
return b; | ||
} | ||
// return bit RGB | ||
|
||
public int convertRGB(int pixels[][], int x, int y) { | ||
int r = 0, g = 0, b = 0; | ||
int rgb = (pixels[x][y] << 16) | (pixels[x][y] << 8) | pixels[x][y]; | ||
return rgb; | ||
} | ||
} |