Netbeans imagej图像类型转换

Netbeans imagej图像类型转换,netbeans,imagej,Netbeans,Imagej,我是java编程新手。 我正在尝试使用netbeans编写一个java应用程序,该应用程序使用imagejjar打开dicom映像并对其进行处理。我可以使用以下java代码实现这一点: public class user_interface extends java.awt.Frame { /** Creates new form user_interface */ public user_interface() { initComponents(); } private void i

我是java编程新手。 我正在尝试使用netbeans编写一个java应用程序,该应用程序使用imagejjar打开dicom映像并对其进行处理。我可以使用以下java代码实现这一点:

public class user_interface extends java.awt.Frame {
/** Creates new form user_interface */
public user_interface() {
    initComponents();
}

private void initComponents() {

    btn_open_image = new java.awt.Button();
    btn_invert_image = new java.awt.Button();
    slbl_display = new javax.swing.JLabel();

    setBackground(java.awt.Color.orange);
    addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosing(java.awt.event.WindowEvent evt) {
            exitForm(evt);
        }
    });
    setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

    btn_open_image.setLabel("Open Image");
    btn_open_image.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            btn_open_imageMouseClicked(evt);
        }
    });
    btn_open_image.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btn_open_imageActionPerformed(evt);
        }
    });
    add(btn_open_image, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 40, 80, -1));

    btn_invert_image.setLabel("Invert Image");
    btn_invert_image.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            btn_invert_imageMouseClicked(evt);
        }
    });
    add(btn_invert_image, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 150, 80, -1));

    slbl_display.setBackground(new java.awt.Color(51, 51, 51));
    add(slbl_display, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 60, -1, -1));

    pack();
}// </editor-fold>                        

/**
 * Exit the Application
 */
private void exitForm(java.awt.event.WindowEvent evt) {                          
    System.exit(0);
}                         

    private ImagePlus IPL_image;
    private ImageJ ImageJ_image;
    private ImageJ CovImageJ_image;
    private ImageProcessor ip;
    private Image AWT_image;
    private ImageIcon AWT_icon;

private void btn_open_imageMouseClicked(java.awt.event.MouseEvent evt) {                                            
    // TODO add your handling code here:
    String MacroName ="C:\\Program Files\\ImageJ\\macros\\RadFz\\DrawGraticule(Worksfine).txt";
    String ImgName = "G:\\PV-QA Images\\01-31-2016\\6MV-FS-OF\\RI\\5x5-6MV-MLC.dcm";        
    //(01) open image
           IPL_image = IJ.openImage(ImgName);


    int ImgType = IPL_image.getType();
    System.out.println("Image Type = " + ImgType);
           //IJ.runMacroFile(MacroName);
    //(02) pass it to processor to acess each pixel
          // ip.convertToColorProcessor();
           ip = IPL_image.getProcessor();

    //(03) reset the image window & level
          ip.resetMinAndMax();             

    //get width & height
    int imgWdth = ip.getWidth();
    int imgHgth = ip.getHeight();

    // set line color and width
    ip.setColor(Color.red);
    ip.setLineWidth(3);
    ip.drawLine(0, imgHgth/2, imgWdth, imgHgth/2);
    ip.drawLine(imgWdth/2, 0, imgWdth/2, imgHgth);

    //IPL_image.show();   // Display image in imagej window
    //String IIP =  IJ.runMacroFile(MacroName);

    //convert image from imagej format to one that you can
    //display in image container
    AWT_image = ip.createImage();
    AWT_icon = new ImageIcon(AWT_image);
    slbl_display.setIcon(AWT_icon);     

    System.out.println("Width = " + imgWdth + "  pixels");
    System.out.println("Height = " + imgHgth + "  pixels");

    GetDICOMTagVal("300A,012C");

}                                           

private void btn_invert_imageMouseClicked(java.awt.event.MouseEvent evt) {                                              
    // TODO add your handling code here:

    ip.invert();
    AWT_image = ip.createImage();
    AWT_icon = new ImageIcon(AWT_image);
    slbl_display.setIcon(AWT_icon);

}                                             

private void btn_open_imageActionPerformed(java.awt.event.ActionEvent evt) {                                               
    // TODO add your handling code here:
}                                              


private void GetDICOMTagVal(String DICOMTag) {

    String imgInfoStr = IPL_image.getInfoProperty();
    //"0002,0003"   "300A,012C"

    System.out.println("imgInfoStr = \n"+ imgInfoStr );        
    String InfoLines[];
    InfoLines = split(imgInfoStr, "\n");
    //System.out.println(" Number of lines = " + InfoLines.length);
    int i;
    for (i =0; i<InfoLines.length; i++){
        //System.out.println(i+" -->" + InfoLines[i].startsWith(DICOMTag));
        if(InfoLines[i].startsWith(DICOMTag)) {
            String Tag;
            Tag = InfoLines[i].substring(DICOMTag.length());

            System.out.println(DICOMTag + " = " + Tag);
        } else {
        }             
    } 
}    


/**
 * @param args the command line arguments
 */
public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new user_interface().setVisible(true);
        }
    });
}


// Variables declaration - do not modify                     
private java.awt.Button btn_invert_image;
private java.awt.Button btn_open_image;
private javax.swing.JLabel slbl_display;
// End of variables declaration                   
}
公共类用户界面扩展了java.awt.Frame{
/**创建新表单用户界面*/
公共用户界面(){
初始化组件();
}
私有组件(){
btn_open_image=new java.awt.Button();
btn_invert_image=new java.awt.Button();
slbl_display=newjavax.swing.JLabel();
挫折背景(java.awt.Color.orange);
addWindowListener(新java.awt.event.WindowAdapter(){
公共无效窗口关闭(java.awt.event.WindowEvent evt){
出口形式(evt);
}
});
setLayout(neworg.netbeans.lib.awtextra.AbsoluteLayout());
btn_open_image.setLabel(“open image”);
btn_open_image.addMouseListener(new java.awt.event.MouseAdapter()){
public void mouseClicked(java.awt.event.MouseEvent evt){
btn_open_imageMouseClicked(evt);
}
});
btn_open_image.addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
btn_open_imageActionPerformed(evt);
}
});
添加(btn_open_image,neworg.netbeans.lib.awtextra.AbsoluteConstraints(10,40,80,-1));
btn_invert_image.setLabel(“invert image”);
btn_invert_image.addMouseListener(新java.awt.event.MouseAdapter()){
public void mouseClicked(java.awt.event.MouseEvent evt){
btn_反转_图像鼠标点击(evt);
}
});
添加(btn_invert_image,neworg.netbeans.lib.awtextra.AbsoluteConstraints(1015080,-1));
slbl_display.setBackground(新java.awt.Color(51,51,51));
添加(slbl_display,neworg.netbeans.lib.awtextra.AbsoluteConstraints(120,60,-1,-1));
包装();
}//                         
/**
*退出应用程序
*/
私有void exitForm(java.awt.event.WindowEvent evt){
系统出口(0);
}                         
私人图像加IPL_图像;
私人影像j影像j_影像;
私人影像;
专用图像处理器ip;
私有映像AWT_映像;
专用图像图标AWT_图标;
私有void btn_open_imageMouseClicked(java.awt.event.MouseEvent evt){
//TODO在此处添加您的处理代码:
String MacroName=“C:\\Program Files\\ImageJ\\macros\\RadFz\\drawgracile(Worksfine).txt”;
字符串ImgName=“G:\\PV-QA Images\\01-31-2016\\6MV-FS-OF\\RI\\5x5-6MV-MLC.dcm”;
//(01)开放式图像
IPL_image=IJ.openImage(ImgName);
int ImgType=IPL_image.getType();
System.out.println(“图像类型=“+ImgType”);
//IJ.runMacroFile(宏名称);
//(02)将其传递给处理器以访问每个像素
//ip.convertToColorProcessor();
ip=IPL_image.getProcessor();
//(03)重置图像窗口和级别
ip.resetMinAndMax();
//获取宽度和高度
int imgWdth=ip.getWidth();
int imgHgth=ip.getHeight();
//设置线条颜色和宽度
ip.setColor(颜色为红色);
ip.设置线宽(3);
ip.抽绳(0,imgHgth/2,imgWdth,imgHgth/2);
ip.拉线(imgWdth/2,0,imgWdth/2,imgHgth);
//IPL_image.show();//在imagej窗口中显示图像
//字符串IIP=IJ.runMacroFile(宏名称);
//将图像从imagej格式转换为您可以使用的格式
//在图像容器中显示
AWT_image=ip.createImage();
AWT_图标=新图像图标(AWT_图像);
slbl_显示设置图标(AWT_图标);
System.out.println(“Width=“+imgWdth+”像素”);
System.out.println(“Height=“+imgHgth+”像素”);
GetDICOMTagVal(“300A,012C”);
}                                           
私有void btn_invert_imageMouseClicked(java.awt.event.MouseEvent evt){
//TODO在此处添加您的处理代码:
ip.invert();
AWT_image=ip.createImage();
AWT_图标=新图像图标(AWT_图像);
slbl_显示设置图标(AWT_图标);
}                                             
私有void btn_open_imageActionPerformed(java.awt.event.ActionEvent evt){
//TODO在此处添加您的处理代码:
}                                              
私有void GetDICOMTagVal(字符串DICOMTag){
字符串imgInfoStr=IPL_image.getInfoProperty();
//“00020003”“300A,012C”
System.out.println(“imgInfoStr=\n”+imgInfoStr);
字符串信息行[];
InfoLines=split(imgInfoStr,“\n”);
//System.out.println(“行数=“+InfoLines.length”);
int i;

对于(i=0;i,正如您所说,抽象类ImageProcessor有一个方法convertorGB():

它正是您所需要的:将ByteProcessor(8位)转换为ColorProcessor(24位)

public ImageProcessor convertToRGB()
    {
    if ( type == RGB ) return ip ;
    ImageProcessor ip2 = ip.convertToByte(doScaling) ;
    return new ColorProcessor(ip2.createImage()) ;
    }