import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.ColorConvertOp;
import java.awt.image.ColorModel;
import java.awt.image.MemoryImageSource;
import java.awt.image.PixelGrabber;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Component.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.MemoryImageSource;
import java.awt.image.PixelGrabber;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class sharp extends /*Component*/ JFrame {
public static int[] histgray = new int[256*256];
public static int[] histsharp =new int[256*256];
public static int[] histbalance =new int[256*256];
public int[] grayImage() throws IOException{
File file = new File("1.jpg");
// File file = new File("D:\\学习\\数字图像处理\\homework1\\1.jpg");
BufferedImage image = ImageIO.read(file);
int width = image.getWidth();
int height = image.getHeight();
int[] pix = new int[width*height];
PixelGrabber pg=null;
try{
pg = new PixelGrabber(image, 0, 0, width, height, pix, 0, width);
if(pg.grabPixels()!=true)
try{
throw new java.awt.AWTException("pg error"+pg.status());
}catch(Exception eq){
eq.printStackTrace();
}
} catch(Exception ex){
ex.printStackTrace();
}
int[]grayArray=new int[height*width];
ColorModel colorModel=ColorModel.getRGBdefault();
int i ,j,k,r,g,b;
for(i = 0; i < height;i++){
for(j = 0;j < width;j++){
k = i*width+j;
r = colorModel.getRed(pix[k]);
g = colorModel.getGreen(pix[k]);
b = colorModel.getBlue(pix[k]);
int gray=(int)(r*0.3+g*0.59+b*0.11);
r=g=b=gray;
// System.out.println(r);
grayArray[i*width+j]= (255 << 24) | (r << 16) | (g << 8 )| b;
histgray[i*width+j] = gray;
}
}
return grayArray;
/* BufferedImage grayImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
for(int ii= 0 ; ii < width ; ii++){
for(int jj = 0 ; jj < height; jj++){
//int rgb = image.getRGB(i, j);
grayImage.setRGB(ii, jj, grayArray[ii*width+jj]);
}
}
File newFile = new File("D:\\1.bmp");
ImageIO.write(grayImage, "bmp", newFile);
} */
}
private void showImage(int[] srcPixArray){
int width=256;
int height=256;
final Image pic=createImage(new MemoryImageSource(width,height,srcPixArray,0,width));
ImageIcon ic=new ImageIcon(pic);
// final String title1 = "灰度图像";
SwingUtilities.invokeLater(new Runnable(){
public void run(){
new ShowImage(pic).setVisible(true);
}
});
}
public static int[] sharpFiltering(int pix[],int hist[]) {
int w=256;
int h=256;
int newpix[] = new int[w*h];
int[] temp = new int[9];
ColorModel cm = ColorModel.getRGBdefault();
int r=0;
for(int y=0; y<h; y++) {
for(int x=0; x<w; x++) {
if(x!=0 && x!=w-1 && y!=0 && y!=h-1) {
//g = median[(x-1,y-1) + f(x,y-1)+ f(x+1,y-1)
// + f(x-1,y) + f(x,y) + f(x+1,y)
// + f(x-1,y+1) + f(x,y+1) + f(x+1,y+1)]
temp[0] = cm.getRed(pix[x-1+(y-1)*w]);
temp[1] = cm.getRed(pix[x+(y-1)*w]);
temp[2] = cm.getRed(pix[x+1+(y-1)*w]);
temp[3] = cm.getRed(pix[x-1+(y)*w]);
temp[4] = cm.getRed(pix[x+(y)*w]);
temp[5] = cm.getRed(pix[x+1+(y)*w]);
temp[6] = cm.getRed(pix[x-1+(y+1)*w]);
temp[7] = cm.getRed(pix[x+(y+1)*w]);
temp[8] = cm.getRed(pix[x+1+(y+1)*w]);
r = (int)(9.0/(1.0/temp[0]+1.0/temp[1]+1.0/temp[2]+1.0/temp[3]+1.0/temp[4]+1.0/temp[5]+1.0/temp[6]+1.0/temp[7]+1.0/temp[8]));
if (r>255)
r=255;
temp[4] = r;
newpix[y*w+x] = 255<<24 | r<<16 | r<<8 |r;
histbalance[y*w+x] =(int) r;
// System.out.println( histmedian[y*w+x]+"sdfsdf");
} else {
newpix[y*w+x] = pix[y*w+x];
histbalance[y*w+x] =hist[y*w+x];
// System.out.println( histmedian[y*w+x]);
}
}
}
return newpix;
}
private Histogram histogram=new Histogram();
private JFrame histogramFrame=new JFrame();
// private JTextArea jta;
public int[] laplace2DFileter(int []data, int[] hist){
int width = 256;
int height = 256;
int r=0;
int filterData[]=new int[data.length];
int min=10000;
int max=-10000;
ColorModel cm = ColorModel.getRGBdefault();
int[] temp = new int[9];
for(int i=0;i<height;i++){
for(int j=0;j<width;j++){
if(i==0 || i==height-1 || j==0 || j==width-1){
filterData[i*width+j]=hist[i*width+j];
histsharp[i*width+j] = hist[i*width+j];
}
else
{
temp[0] = cm.getRed(data[j-1+(i-1)*width]);
temp[1] = cm.getRed(data[j+(i-1)*width]);
temp[2] = cm.getRed(data[j+1+(i-1)*width]);
temp[3] = cm.getRed(data[j-1+(i)*width]);
temp[4] = cm.getRed(data[j+(i)*width]);
temp[5] = cm.getRed(data[j+1+(i)*width]);
temp[6] = cm.getRed(data[j-1+(i+1)*width]);
temp[7] = cm.getRed(data[j+(i+1)*width]);
temp[8] = cm.getRed(data[j+1+(i+1)*width]);
r = 8*temp[4]-temp[0]-temp[1]-temp[2]-temp[3]-temp[5]-temp[6]-temp[7]-temp[8];
filterData[i*width+j] = r+20*temp[4];
histsharp[i*width+j] = r+temp[4];
}
if(filterData[i*width+j]<min)
min=filterData[i*width+j];
if(filterData[i*width+j]>max)
max=filterData[i*width+j];
}
}
// System.out.println("max: "+max);
// System.out.println("min: "+min);
for(int i=0;i<width*height;i++){
filterData[i]=(filterData[i]-min)*255/(max-min);
histsharp[i] = filterData[i];
}
for(int i=0;i<width*height;i++){
filterData[i]=255<<24 | filterData[i]<<16 | filterData[i]<<8 | filterData[i];
}
return filterData;
}
public void MultipelWindowsDemo(int[] count){
// JScrollPane scrollPane=new JScrollPane(jta=new JTextArea());
// scrollPane.setPreferredSize(new Dimension(300,200));
// jta.setWrapStyleWord(true);
// jta.setLineWrap(true);
// this.getContentPane().add(scrollPane,BorderLayout.CENTER);
// this.getContentPane().add(jbtShowHistogram,BorderLayout.SOUTH);
// jbtShowHistogram.addActionListener(this);
没有合适的资源?快使用搜索试试~ 我知道了~
图像处理基本算法 java代码
共44个文件
class:16个
java:12个
project:4个
需积分: 10 17 下载量 154 浏览量
2014-07-20
23:03:39
上传
评论
收藏 826KB RAR 举报
温馨提示
该java代码实现了直方图均衡化,中值滤波,谐波均值滤波;拉普拉斯锐化,使用的验证图像为经典的lena
资源推荐
资源详情
资源评论
收起资源包目录
java代码.rar (44个子文件)
java代码
中值滤波
Median filter
.project 390B
bin
ShowImage.class 697B
median$1.class 657B
median.class 5KB
Histogram.class 1KB
.settings
org.eclipse.jdt.core.prefs 598B
2.jpg 204KB
src
median.java 9KB
Histogram.java 1KB
ShowImage.java 487B
.classpath 301B
直方图均衡化
qq
.project 378B
bin
ShowImage.class 697B
hist.class 5KB
hist$1.class 645B
Histogram.class 1KB
.settings
org.eclipse.jdt.core.prefs 598B
LenaRGBLow1.bmp 768KB
src
hist.java 8KB
Histogram.java 1KB
ShowImage.java 487B
.classpath 301B
谐波均值滤波+拉普拉斯锐化
sharp
.project 381B
bin
ShowImage.class 697B
sharp$1.class 651B
sharp.class 6KB
Histogram.class 1KB
.settings
org.eclipse.jdt.core.prefs 598B
src
sharp.java 11KB
Histogram.java 1KB
ShowImage.java 487B
1.jpg 11KB
.classpath 301B
幂变换
mean filter
.project 387B
bin
mean$1.class 645B
ShowImage.class 697B
Histogram.class 1KB
mean.class 4KB
.settings
org.eclipse.jdt.core.prefs 598B
src
Histogram.java 1KB
mean.java 8KB
ShowImage.java 487B
LenaRGBLow2.bmp 768KB
.classpath 301B
共 44 条
- 1
资源评论
R零度轨迹
- 粉丝: 0
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功