import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.lang.Math;
public class CTHead extends JFrame {
JButton mip_button; //an example button to switch to MIP mode
JToggleButton pic_button;
JButton nearest_button;
JButton bilinear_button;
JButton nearestmip_button;
JButton bilinearmip_button;
JLabel image_icon1; //using JLabel to display an image
JLabel image_icon2; //using JLabel to display an image
JLabel image_icon3;
JLabel image_icon4;
JSlider zslice_slider, yslice_slider, xslice_slider; //sliders to step through the slices
BufferedImage image1, image2, image3, image4; //storing the image in memory
short cthead[][][]; //store the 3D volume data set
short min, max; //min/max value in the 3D volume data set
int slidernum = 56, slidernum1 = 125, slidernum2 = 125;
/*
This function sets up the GUI and reads the data set
*/
public void CTHead() throws IOException {
//File name is hardcoded here - much nicer to have a dialog to select it and capture the size from the user
File file = new File("CThead");
//Create a BufferedImage to store the image data
image1=new BufferedImage(256, 256, BufferedImage.TYPE_3BYTE_BGR);
image2=new BufferedImage(256, 256, BufferedImage.TYPE_3BYTE_BGR);
image3=new BufferedImage(256, 256, BufferedImage.TYPE_3BYTE_BGR);
image4=new BufferedImage(512, 512, BufferedImage.TYPE_3BYTE_BGR);
//Read the data quickly via a buffer (in C++ you can just do a single fread - I couldn't find the equivalent in Java)
DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
int i, j, k; //loop through the 3D data set
min=Short.MAX_VALUE; max=Short.MIN_VALUE; //set to extreme values
short read; //value read in
int b1, b2; //data is wrong Endian (check wikipedia) for Java so we need to swap the bytes around
cthead = new short[113][256][256]; //allocate the memory - note this is fixed for this data set
//loop through the data reading it in
for (k=0; k<113; k++) {
for (j=0; j<256; j++) {
for (i=0; i<256; i++) {
//because the Endianess is wrong, it needs to be read byte at a time and swapped
b1=((int)in.readByte()) & 0xff; //the 0xff is because Java does not have unsigned types (C++ is so much easier!)
b2=((int)in.readByte()) & 0xff; //the 0xff is because Java does not have unsigned types (C++ is so much easier!)
read=(short)((b2<<8) | b1); //and swizzle the bytes around
if (read<min) min=read; //update the minimum
if (read>max) max=read; //update the maximum
cthead[k][j][i]=read; //put the short into memory (in C++ you can replace all this code with one fread)
}
}
}
System.out.println(min+" "+max); //diagnostic - for CThead this should be -1117, 2248
//(i.e. there are 3366 levels of grey (we are trying to display on 256 levels of grey)
//therefore histogram equalization would be a good thing
// Set up the simple GUI
// First the container:
Container container = getContentPane();
setTitle("CThead - Heng Liu");
container.setLayout(new FlowLayout(FlowLayout.LEADING));
Panel pan = new Panel();
pan.setLayout(new GridLayout(2,2,5,5));
container.add(pan);
Panel pan2 = new Panel();
pan2.setLayout(new GridLayout(4,1,0,5));
pan.add(pan2);
Panel pan3 = new Panel();
pan3.setLayout(new GridLayout(2,3,0,5));
pan2.add(pan3);
// Then our image (as a label icon)
image_icon1=new JLabel(new ImageIcon(image1));
pan.add(image_icon1);
image_icon2=new JLabel(new ImageIcon(image2));
pan.add(image_icon2);
image_icon3=new JLabel(new ImageIcon(image3));
pan.add(image_icon3);
pan.add(pan2);
image_icon4=new JLabel(new ImageIcon(image4));
container.add(image_icon4);
// Then the invert button
pic_button = new JToggleButton("Pic");
pan3.add(pic_button);
mip_button = new JButton("MIP");
pan3.add(mip_button);
nearest_button = new JButton("Nearest");
pan3.add(nearest_button);
bilinear_button = new JButton("Bilinear");
pan3.add(bilinear_button);
nearestmip_button = new JButton("NearMIP");
pan3.add(nearestmip_button);
bilinearmip_button = new JButton("BiliMIP");
pan3.add(bilinearmip_button);
//Zslice slider
zslice_slider = new JSlider(0,112);
pan2.add(zslice_slider);
zslice_slider.setMajorTickSpacing(10);
zslice_slider.setMinorTickSpacing(10);
zslice_slider.setPaintTicks(true);
zslice_slider.setPaintLabels(true);
yslice_slider = new JSlider(0,255);
pan2.add(yslice_slider);
//Add labels (y slider as example)
yslice_slider.setMajorTickSpacing(50);
yslice_slider.setMinorTickSpacing(10);
yslice_slider.setPaintTicks(true);
yslice_slider.setPaintLabels(true);
xslice_slider = new JSlider(0,255);
pan2.add(xslice_slider);
//Add labels (y slider as example)
xslice_slider.setMajorTickSpacing(50);
xslice_slider.setMinorTickSpacing(10);
xslice_slider.setPaintTicks(true);
xslice_slider.setPaintLabels(true);
// Now all the handlers class
GUIEventHandler handler = new GUIEventHandler();
// associate appropriate handlers
mip_button.addActionListener(handler);
pic_button.addActionListener(handler);
nearest_button.addActionListener(handler);
bilinear_button.addActionListener(handler);
nearestmip_button.addActionListener(handler);
bilinearmip_button.addActionListener(handler);
yslice_slider.addChangeListener(handler);
zslice_slider.addChangeListener(handler);
xslice_slider.addChangeListener(handler);
// ... and display everything
pack();
setLocationRelativeTo(null);
setVisible(true);
}
/*
This is the event handler for the application
*/
private class GUIEventHandler implements ActionListener, ChangeListener {
public void stateChanged(ChangeEvent e) {
if(pic_button.isSelected()){
if(e.getSource()==zslice_slider){
slidernum = zslice_slider.getValue();
//System.out.println(slidernum);
image1=TOP(image1);
image_icon1.setIcon(new ImageIcon(image1));
}else if(e.getSource()==yslice_slider){
slidernum1 = yslice_slider.getValue();
image2 = FRONT(image2);
image_icon2.setIcon(new ImageIcon(image2));
}else if(e.getSource()==xslice_slider){
slidernum2 = xslice_slider.getValue();
image3 = SIDE(image3);
image_icon3.setIcon(new ImageIcon(image3));
}
}else if(!pic_button.isSelected()){
if(e.getSource()==zslice_slider){
slidernum = zslice_slider.getValue();
//System.out.println(slidernum);
image1=HE_TOP(image1);
image_icon1.setIcon(new ImageIcon(image1));
}else if(e.getSource()==yslice_slider){
slidernum1 = yslice_slider.getValue();
image2 = HE_FRONT(image2);
image_icon2.setIcon(new ImageIcon(image2));
}else if(e.getSource()==xslice_slider){
slidernum2 = xslice_slider.getValue();
image3 = HE_SIDE(image3);
image_icon3.setIcon(new ImageIcon(image3));
}
}
}
public void actionPerformed(ActionEvent event) {
if (event.getSource()==mip_button) {
image1=MIP_TOP(image1);
image_icon1.setIcon(new ImageIcon(image1));
image2 = MIP_FRONT(image2);
image_icon2.setIcon(new ImageIcon(image2));
image3 = MIP_SIDE(image3);
image_icon3.setIcon(new ImageIcon(image3));
} else if (event.getSource()==nearestmip_button){
image4 = MIP_NEAREST(image4);
image_icon4.setIcon(new ImageIcon(image4));
} else if (event.getSource()==bilinearmip_button){
image4 = MIP_BILINEAR(image4);
image_icon4.setIcon(new ImageIcon(image4));
} else if (event.getSource()==nearest_button){
image4 = NEAREST(image4);
i
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
CTHead.zip (2个子文件)
CThead 14.13MB
CTHead.java 23KB
共 2 条
- 1
资源评论
- 待七2015-05-02基本上还可以,但是我感觉老师的课上没用上
- 囧囧有神2013-07-15想问一下那个医学图像CTHead文件是怎么生成的
- 意志2014-01-27分值太高,感觉不实用,有点后悔被扣分
liu363325971
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 课程设计-基于SpringBoot + Mybatis+python爬虫NBA球员数据爬取可视化+源代码+文档+sql+效果图
- 软件品质管理系列二项目策划规范.doc
- 基于TensorFlow+PyQt+GUI的酒店评论情感分析,支持分析本地数据文件和网络爬取数据分析+源代码+文档说明+安装教程
- 软件定义无线电中的模拟电路测试技术.pptx
- 软件开发协议(作为技术开发合同附件).doc
- 软件开发和咨询行业技术趋势分析.pptx
- 软件测试题详解及答案.doc
- 软件漏洞生命周期管理策略.pptx
- 毕业设计-基于Python实现的的简易气温爬虫,可以爬取全国各市的近7日气温数据
- 软件系统测试报告(实用版).doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功