Skip to content

Commit

Permalink
new file update
Browse files Browse the repository at this point in the history
new file update
  • Loading branch information
NSLog0 committed Jun 15, 2012
1 parent 694c707 commit 155f5f1
Show file tree
Hide file tree
Showing 14 changed files with 205 additions and 23 deletions.
19 changes: 0 additions & 19 deletions Image2D/src/image2d/Image2D.java

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
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
2 changes: 2 additions & 0 deletions nbproject/private/private.properties
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
4 changes: 4 additions & 0 deletions nbproject/private/private.xml
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>
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ javac.compilerargs=
javac.deprecation=false
javac.processorpath=\
${javac.classpath}
javac.source=1.7
javac.target=1.7
javac.source=1.6
javac.target=1.6
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
Expand Down
File renamed without changes.
32 changes: 32 additions & 0 deletions src/image2d/Image2D.java
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();
}
}
30 changes: 30 additions & 0 deletions src/image2d/ImagePanel.java
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);
}
}
}
97 changes: 97 additions & 0 deletions src/image2d/ImageProcessor.java
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

}
}
36 changes: 36 additions & 0 deletions src/image2d/RGB.java
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;
}
}
Binary file added test.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 155f5f1

Please sign in to comment.