Ignore:
Timestamp:
12/20/11 18:45:53 (8 years ago)
Author:
aivar
Message:

UI panel now has noise model, fitted images, and chi square target

Location:
trunk/projects/slim-plugin/src/main/java/loci/slim
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/projects/slim-plugin/src/main/java/loci/slim/SLIMProcessor.java

    r7839 r7842  
    122122    private static final boolean USE_LAMBDA = false; 
    123123 
    124     // this affects how lifetimes are colorized: //TODO get rid of this 
    125     private static final double MAXIMUM_LIFETIME = 0.075; // for fitting fake with Jaolho // for fitting brian with barber triple integral 100.0f X tau vs lambda issue here 
    126  
    127124    // this affects how many pixels we process at once 
    128125    private static final int PIXEL_COUNT = 128; //32;//16; 
     
    272269        uiPanel.setStop(m_timeBins - 1, false); 
    273270        uiPanel.setThreshold(100); 
     271        uiPanel.setChiSquareTarget(1.5); 
    274272        uiPanel.setFunctionParameters(0, DEFAULT_SINGLE_EXP_PARAMS); 
    275273        uiPanel.setFunctionParameters(1, DEFAULT_DOUBLE_EXP_PARAMS); 
     
    10101008        //TODO new style code starts only here: 
    10111009        FLIMImageFitter imageFitter = new FLIMImageFitter(); 
    1012         int components = 1; 
     1010        int components = 0; 
    10131011        boolean stretched = false; 
    10141012        switch (uiPanel.getFunction()) { 
    10151013            case SINGLE_EXPONENTIAL: 
     1014                components = 1; 
    10161015                break; 
    10171016            case DOUBLE_EXPONENTIAL: 
     
    10251024                break; 
    10261025        } 
    1027         String outputs = uiPanel.getImages(); 
     1026        String outputs = uiPanel.getFittedImages(); 
    10281027        OutputImageParser parser = new OutputImageParser(outputs, components, stretched); 
    10291028         
    10301029        OutputImage[] outputImages = parser.getOutputImages(); 
    1031         imageFitter.setUpFit(outputImages, new int[] { m_width, m_height }, 1); 
     1030        imageFitter.setUpFit(outputImages, new int[] { m_width, m_height }, components); 
    10321031        imageFitter.beginFit();        
    10331032 
     
    10891088    } 
    10901089 
     1090    /* 
     1091     * Helper function that processes an array of pixels.  Histogram and images 
     1092     * are updated at the end of this function. 
     1093     */ 
    10911094    private void processPixels(ICurveFitData[] data, ChunkyPixel[] pixels, FLIMImageFitter imageFitter) { 
    10921095        if (null == _fittingEngine) { 
     
    10991102        globalFitParams.setFitAlgorithm(loci.curvefitter.ICurveFitter.FitAlgorithm.RLD_LMA); 
    11001103        globalFitParams.setFitFunction(loci.curvefitter.ICurveFitter.FitFunction.SINGLE_EXPONENTIAL); 
     1104        globalFitParams.setNoiseModel(loci.curvefitter.ICurveFitter.NoiseModel.MAXIMUM_LIKELIHOOD); 
    11011105        globalFitParams.setXInc(m_timeRange); 
    11021106        globalFitParams.setPrompt(null); 
     
    11081112 
    11091113        boolean[] free = { true, true, true }; 
    1110         globalFitParams.setFree(free); //TODO BAD! 
     1114        globalFitParams.setFree(free); //TODO BAD! s/n/b hardcoded here 
    11111115      //TODO KLUDGE  globalFitParams.setFree(translateFree(uiPanel.getFunction(), uiPanel.getFree())); 
    11121116 
     
    11431147     * Results of the fit go to VisAD for analysis. 
    11441148     */ 
     1149    //TODO this is the old version 
    11451150    private Image<DoubleType> fitEachPixelX(IUserInterfacePanel uiPanel) { 
    11461151        long start = System.nanoTime(); 
  • trunk/projects/slim-plugin/src/main/java/loci/slim/ui/IUserInterfacePanel.java

    r7839 r7842  
    114114     * @return 
    115115     */ 
    116     public String getImages(); 
     116    public String getFittedImages(); 
    117117 
    118118    /** 
     
    174174     */ 
    175175    public void setThreshold(int threshold); 
     176  
     177    /** 
     178     * Gets chi square target for fit. 
     179     *  
     180     * @return  
     181     */ 
     182    public double getChiSquareTarget(); 
     183 
     184    /** 
     185     * Sets chi square target for fit. 
     186     *  
     187     * @param chiSqTarget  
     188     */ 
     189    public void setChiSquareTarget(double chiSqTarget);    
    176190 
    177191    /** 
     
    181195     */ 
    182196    public String getBinning(); 
    183  
    184     public double getChiSquareTarget(); 
    185197 
    186198    /** 
  • trunk/projects/slim-plugin/src/main/java/loci/slim/ui/UserInterfacePanel.java

    r7839 r7842  
    103103    private static final String POISSON_FIT = "Poisson Fit"; 
    104104    private static final String POISSON_DATA = "Poisson Data"; 
    105     private static final String MAXIMUM_LIKELIHOOD = "Maximum Likelihood"; 
    106  
    107     private static final String A_T_H_Z_X2 = "A " + TAU + " H Z " + CHI + SQUARE; 
    108     private static final String A_T_H_X2 = "A " + TAU + " H " + CHI +  SQUARE; 
    109     private static final String A_T_H = "A " + TAU + " H"; 
    110     private static final String T_H_X2 = TAU + " H " + CHI + SQUARE; 
    111     private static final String T_H = TAU + " H"; 
    112     private static final String T = "" + TAU; 
    113     private static final String F_UPPER = "F"; 
    114     private static final String F_LOWER = "f"; 
     105    private static final String MAXIMUM_LIKELIHOOD = "Max. Likelihood Est."; 
    115106 
    116107    private static final String CHI_SQ_TARGET = "" + CHI + SQUARE + " Target"; 
     
    130121    private static final String FUNCTION_ITEMS[] = { SINGLE_EXPONENTIAL, DOUBLE_EXPONENTIAL, TRIPLE_EXPONENTIAL, STRETCHED_EXPONENTIAL }; 
    131122    private static final String NOISE_MODEL_ITEMS[] = { GAUSSIAN_FIT, POISSON_FIT, POISSON_DATA, MAXIMUM_LIKELIHOOD }; 
    132     private static final String FITTED_IMAGE_ITEMS[] = { A_T_H_Z_X2, A_T_H_X2, A_T_H, T_H_X2, T_H, T, F_UPPER, F_LOWER }; 
    133  
     123     
     124    private static final String A_T_Z_X2 = "A " + TAU + " Z " + CHI + SQUARE; 
     125    private static final String A_T_X2 = "A " + TAU + " " + CHI + SQUARE; 
     126    private static final String A_T = "A " + TAU; 
     127    private static final String T_X2 = TAU + " " + CHI + SQUARE; 
     128    private static final String T = "" + TAU; 
     129    private static final String A_T_H_Z_X2 = "A " + TAU + " H Z " + CHI + SQUARE; 
     130    private static final String A_T_H_X2 = "A " + TAU + " H " + CHI + SQUARE; 
     131    private static final String A_T_H = "A " + TAU + " H"; 
     132    private static final String T_H_X2 = TAU + " H " + CHI + SQUARE; 
     133    private static final String T_H = TAU + " H"; 
     134    private static final String F_UPPER = "F"; 
     135    private static final String F_LOWER = "f"; 
     136     
     137    private static final String SINGLE_FITTED_IMAGE_ITEMS[] = { A_T_Z_X2, A_T_X2, A_T, T_X2, T }; 
     138    private static final String DOUBLE_FITTED_IMAGE_ITEMS[] = { A_T_Z_X2, A_T_X2, A_T, T_X2, T, F_UPPER, F_LOWER }; 
     139    private static final String TRIPLE_FITTED_IMAGE_ITEMS[] = { A_T_Z_X2, A_T_X2, A_T, T_X2, T, F_UPPER, F_LOWER };     
     140    private static final String STRETCHED_FITTED_IMAGE_ITEMS[] = { A_T_H_Z_X2, A_T_H_X2, A_T_H, T_H_X2, T_H, T };     
     141     
    134142    private static final String EXCITATION_ITEMS[] = { EXCITATION_NONE, EXCITATION_FILE, EXCITATION_CREATE }; 
    135143     
     
    337345        fitPanel.add(regionLabel); 
    338346        m_regionComboBox = new JComboBox(REGION_ITEMS); 
    339      m_regionComboBox.setSelectedItem(ALL_REGION); // for demo 
     347        m_regionComboBox.setSelectedItem(ALL_REGION); 
    340348        fitPanel.add(m_regionComboBox); 
    341349 
     
    344352        fitPanel.add(algorithmLabel); 
    345353        m_algorithmComboBox = new JComboBox(ALGORITHM_ITEMS); 
    346      m_algorithmComboBox.setSelectedItem(SLIM_CURVE_RLD_LMA_ALGORITHM); 
     354        m_algorithmComboBox.setSelectedItem(SLIM_CURVE_RLD_LMA_ALGORITHM); 
    347355        fitPanel.add(m_algorithmComboBox); 
    348356 
     
    354362            new ItemListener() { 
    355363                public void itemStateChanged(ItemEvent e) { 
    356                     CardLayout cl = (CardLayout)(m_cardPanel.getLayout()); 
    357                     cl.show(m_cardPanel, (String)e.getItem()); 
    358                     reconcileStartParam(); 
     364                    if (e.getStateChange() == ItemEvent.SELECTED) { 
     365                        String item = (String) e.getItem(); 
     366                        CardLayout cl = (CardLayout)(m_cardPanel.getLayout()); 
     367                        cl.show(m_cardPanel, item); 
     368                        reconcileStartParam(); 
     369                        updateFittedImagesComboBox(FUNCTION_ITEMS, item); 
     370                    } 
    359371                } 
    360372            } 
     
    366378        fitPanel.add(noiseModelLabel); 
    367379        m_noiseModelComboBox = new JComboBox(NOISE_MODEL_ITEMS); 
     380        m_noiseModelComboBox.setSelectedItem(MAXIMUM_LIKELIHOOD); 
    368381        fitPanel.add(m_noiseModelComboBox); 
    369382 
     
    371384        fittedImagesLabel.setHorizontalAlignment(SwingConstants.RIGHT); 
    372385        fitPanel.add(fittedImagesLabel); 
    373         m_fittedImagesComboBox = new JComboBox(FITTED_IMAGE_ITEMS); 
     386        m_fittedImagesComboBox = new JComboBox(SINGLE_FITTED_IMAGE_ITEMS); 
    374387        fitPanel.add(m_fittedImagesComboBox); 
    375388 
     
    402415        panel.add("South", m_fitAllChannels); 
    403416        return panel; 
     417    } 
     418 
     419    /** 
     420     * Used to build an appropriate list of fitted images, according to the 
     421     * fit function selected. 
     422     *  
     423     * @param items 
     424     * @param selectedItem  
     425     */ 
     426    private void updateFittedImagesComboBox(String[] items, String selectedItem) { 
     427        if (SINGLE_EXPONENTIAL.equals(selectedItem)) { 
     428            updateComboBox(m_fittedImagesComboBox, SINGLE_FITTED_IMAGE_ITEMS); 
     429        } 
     430        else if (DOUBLE_EXPONENTIAL.equals(selectedItem)) { 
     431            updateComboBox(m_fittedImagesComboBox, DOUBLE_FITTED_IMAGE_ITEMS);             
     432        } 
     433        else if (TRIPLE_EXPONENTIAL.equals(selectedItem)) { 
     434            updateComboBox(m_fittedImagesComboBox, TRIPLE_FITTED_IMAGE_ITEMS);            
     435        } 
     436        else if (STRETCHED_EXPONENTIAL.equals(selectedItem)) { 
     437            updateComboBox(m_fittedImagesComboBox, STRETCHED_FITTED_IMAGE_ITEMS);   
     438        } 
     439    } 
     440  
     441    /* 
     442     * Updates a combo box with a new list of items. 
     443     */ 
     444    private void updateComboBox(JComboBox comboBox, String[] items) { 
     445        // Had problems with "comboBox.removeAll()": 
     446        for (int i = comboBox.getItemCount() - 1; i >= 0; --i) { 
     447            comboBox.removeItemAt(i); 
     448        } 
     449        for (String item : items) { 
     450            comboBox.addItem(item); 
     451        } 
     452        comboBox.setSelectedIndex(0); 
    404453    } 
    405454 
     
    548597        expPanel.add(nullLabel1); 
    549598 
     599        //TODO: 
    550600        // SLIMPlotter look & feel: 
    551601        //Color fixColor = m_a1Param1.getBackground(); 
     
    637687        expPanel.add(nullLabel2); 
    638688 
     689        //TODO: 
    639690        // From SLIMPlotter 
    640691        //Color fixColor = m_a1Param2.getBackground(); 
     
    748799        expPanel.add(nullLabel3); 
    749800 
     801        //TODO: 
    750802        // SLIMPlotter look & feel: 
    751803        //Color fixColor = m_a1Param3.getBackground(); 
     
    830882        expPanel.add(nullLabel1); 
    831883 
     884        //TODO: 
    832885        // SLIMPlotter look & feel: 
    833886        //Color fixColor = m_a1Param1.getBackground(); 
     
    10361089     * @return 
    10371090     */ 
    1038     public String getImages() { 
     1091    public String getFittedImages() { 
    10391092        String selected = (String) m_fittedImagesComboBox.getSelectedItem(); 
    10401093        return selected; 
     
    10971150 
    10981151    public double getChiSquareTarget() { 
    1099         return 1.0; 
     1152        return Double.valueOf(m_chiSqTargetField.getText()); 
     1153    } 
     1154     
     1155    public void setChiSquareTarget(double chiSqTarget) { 
     1156        m_chiSqTargetField.setText("" + chiSqTarget); 
    11001157    } 
    11011158 
Note: See TracChangeset for help on using the changeset viewer.