2016-04-27 11 views
0

我在ImageJ中編寫了一個插件,我需要一些想法。 我有一個爲堆棧中的每個圖像生成圖的插件。所以如果我在一個堆棧中有4個圖像,它將從矢量生成4個圖。 但我需要用4條曲線繪製一條曲線。請幫幫我。 `在ImageJ中的一個圖中的向量(Java)

這是代碼。

public void run(String arg){  
     openImage(); 
     if (cancel==false){ 
      options();  
     } 
     if (cancel==false){ 
      for (int k=0;k<imp.getStackSize();k++){ 
       imp.setSlice(k+1); 
       generateESFArray("ESF Plot",imp,roi); 
       generateLSFArray("LSF Plot",ESFArray); 
       calculateMax(); 

       ESFArrayF=alignArray(ESFArray); 

       if (cancel==false){ 
        LSFArrayF=alignArray(LSFArray); 

       } 
       if (cancel==false){ 
        ESFVector=averageVector(ESFArrayF); 
       } 

       if (cancel==false){ 
        LSFVector=averageVector(LSFArrayF); 
        int aura = (LSFVector.length * 2); 
        LSFDVector = new double [aura]; 
        int j = 0; 
        int aura2 = (LSFVector.length); 

        for(i=0;i<(LSFDVector.length-3); i++){ 

         if(i % 2 == 0) { 
          LSFDVector[i]= LSFVector[j]; 
          j=j+1; 
         }else { 
          LSFDVector[i]= ((0.375*LSFVector[(j-1)]) + (0.75*LSFVector[(j)]) - (0.125*LSFVector[(j+1)])); 

         } 

        } 

          LSFDVector[i] = ((LSFVector[j-1] + LSFVector[j])*0.5); 
          LSFDVector[i+1] = LSFVector[j]; 
          LSFDVector[i+2] = LSFVector[j]; 


           int indexMax = 0; 
           double valorMax = LSFDVector[0]; 
           for(int i=0;i<LSFDVector.length;i++){ 
            if(valorMax < LSFDVector[i]){ 
             indexMax = i; 
             valorMax = LSFDVector[i]; 
            } 
           } 

             i=indexMax; 
             LSFDVector[i-1]=((LSFDVector[i-2] + LSFDVector[i])*0.5); 

             MTFVector=fftConversion(LSFDVector, "MTF"); 


             Max=obtenerMax(); 
             SPPVector=fftConversion(Max,"SPP"); 
             LSFArrayF=alignArray(LSFArray); 


     if (MTFButton.isSelected()){ 
              generatePlot (MTFVector,"MTF"); 
... 
    }  

void generatePlot(double[] Vector, String plot){ 

     double[]xValues; 
     String ejeX="pixel"; 
     String ejeY=""; 
     String allTitle=""; 
     ImageProcessor imgProc; 

     xValues=calculateXValues(Vector,plot); 

     //plot titles  
     if (plot=="ESF"){ 
      ejeY="Grey Value"; 
     ... 

     allTitle=plot + "_" + title;   
     plotResult = new Plot(allTitle, ejeX, ejeY, xValues, Vector); 

     //plot limits 
     if (plot=="ESF"){ 
      plotResult.setLimits(1,Vector.length,0,yMax); 
     } 

     plotResult.draw(); 
     plotResult.show(); 

    } 
     ` 

回答

1

ij.gui.Plot classaddPoints方法讓你多數據系列添加到一個陰謀。下面的腳本Groovy說明了它的用法。只需將代碼粘貼到ImageJ的script editor中,選擇語言> Groovy並按運行即可嘗試。

import ij.gui.Plot 

plot = new Plot("Multiple Line Plot", "x values", "y values", (double[])[0,1,2,3,4], (double[])[0.1,0.3,0.5,0.6,0.7]) 
plot.addPoints((double[])[0,1,2,3,4], (double[])[0.2,0.15,0.1,0.05,0.05], Plot.LINE) 
plot.setLimits(0, 4, 0, 1) 
plot.draw() 
plot.show() 

有關的ImageJ的API的使用有任何疑問,你可能會在ImageJ forum更好的幫助。

+0

非常感謝!這是一個愚蠢的想法! – Ludanyi

+0

我想添加到一個空的雙[] []一些向量(雙[])在Java與for循環。因爲我需要一個2D矢量,但我有double []值。 用add方法我可以做到嗎? 你能幫我嗎? – Ludanyi

+0

您可以預先分配適當大小的double [] []向量,然後填充其元素,或者簡單地使用'ArrayList <>'和它的'append'方法。 –