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
Files:
1 added
1 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/projects/slim-plugin/src/main/java/imagej/slim/fitting/AbstractBaseFittedImage.java

    r7838 r7842  
    3535        _values = new double[x][y]; 
    3636        //TODO need to handle multiple channels: 
    37         // _values c/b slice being drawn only; refer to Image for other slices 
     37        // _values c/b slice being drawn only; refer to Image for other slices; this scheme would fall apart if Image is colorized grayscale like SPCImage 
    3838        HistogramDataChannel histogramDataChannel = new HistogramDataChannel(_values); 
    3939        HistogramDataChannel[] histogramDataChannels = new HistogramDataChannel[] { histogramDataChannel }; 
     
    4141        _image = new FloatProcessor(x, y); 
    4242        _image.setColorModel(imagej.slim.histogram.HistogramTool.getIndexColorModel()); 
     43        //TODO fill the image with a color that will be out of LUT range and paint black!: 
     44        _image.setValue(Float.NaN); //TODO 
     45        _image.fill(); //TODO 
    4346        _imagePlus = new ImagePlus(title, _image); 
    4447        _imagePlus.show(); 
     
    4851            } 
    4952             
    50             public void focusLost(FocusEvent e) { 
    51                  
    52             } 
     53            public void focusLost(FocusEvent e) { } 
    5354        });   
    5455    } 
     
    8687        // clear the 2D slice 
    8788        clear(_values); 
    88  
    8989    } 
    9090    /** 
     
    118118        // etc. 
    119119        _imagePlus.setProcessor(_image.duplicate()); 
     120         
     121         
     122        System.out.println("RECALC " + numInvalid(_values)); 
    120123    } 
     124     
     125     
     126    private int numInvalid(double[][] values) { 
     127        int count = 0; 
     128        int num = 0; 
     129        for (int y = 0; y < values[0].length; ++y) { 
     130            for (int x = 0; x < values.length; ++x) { 
     131                if (InvalidDouble.isValue(values[x][y])) { 
     132                    ++num; 
     133                } 
     134                ++count; 
     135            } 
     136        } 
     137        System.out.println("checked " + count + " pixels,  found invalid " + num); 
     138        return num; 
     139    }    
     140     
     141     
     142     
    121143     
    122144    /** 
     
    158180    abstract public double getValue(double[] parameters);  
    159181 
     182    /* 
     183     * Clears the values for this slice. 
     184     *  
     185     * @param values  
     186     */ 
    160187    private void clear(double[][] values) { 
    161188        for (int y = 0; y < values[0].length; ++y) { 
    162189            for (int x = 0; x < values.length; ++x) { 
    163                 values[x][y] = Double.NaN; 
     190                values[x][y] = InvalidDouble.value(); 
    164191            } 
    165192        } 
  • trunk/projects/slim-plugin/src/main/java/imagej/slim/fitting/IFittedImage.java

    r7833 r7842  
    1212/** 
    1313 * 
    14  * @author aivar 
     14 * @author Sivar Grislis 
    1515 */ 
    1616public interface IFittedImage { 
  • trunk/projects/slim-plugin/src/main/java/imagej/slim/fitting/callable/FittingEngineCallable.java

    r7811 r7842  
    6868        _curveFitter.setFitAlgorithm(_globalParams.getFitAlgorithm()); 
    6969        _curveFitter.setFitFunction(_globalParams.getFitFunction()); 
     70        _curveFitter.setNoiseModel(_globalParams.getNoiseModel()); 
    7071        _curveFitter.setInstrumentResponse(_globalParams.getPrompt()); 
    7172        _curveFitter.setXInc(_globalParams.getXInc()); 
  • trunk/projects/slim-plugin/src/main/java/imagej/slim/fitting/params/GlobalFitParams.java

    r7811 r7842  
    3737import loci.curvefitter.ICurveFitter.FitAlgorithm; 
    3838import loci.curvefitter.ICurveFitter.FitFunction; 
     39import loci.curvefitter.ICurveFitter.NoiseModel; 
    3940 
    4041/** 
     
    4748    private FitAlgorithm _fitAlgorithm; 
    4849    private FitFunction _fitFunction; 
     50    private NoiseModel _noiseModel; 
    4951    private double _xInc; 
    5052    private double[] _prompt; 
     
    7476    public FitFunction getFitFunction() { 
    7577        return _fitFunction; 
     78    } 
     79 
     80    @Override 
     81    public void setNoiseModel(NoiseModel noiseModel) { 
     82        _noiseModel = noiseModel; 
     83    } 
     84 
     85    @Override 
     86    public NoiseModel getNoiseModel() { 
     87        return _noiseModel; 
    7688    } 
    7789     
  • trunk/projects/slim-plugin/src/main/java/imagej/slim/fitting/params/IGlobalFitParams.java

    r7811 r7842  
    3737import loci.curvefitter.ICurveFitter.FitAlgorithm; 
    3838import loci.curvefitter.ICurveFitter.FitFunction; 
     39import loci.curvefitter.ICurveFitter.NoiseModel; 
    3940 
    4041/** 
     
    5354     
    5455    public FitFunction getFitFunction(); 
     56     
     57    public void setNoiseModel(NoiseModel noiseModel); 
     58     
     59    public NoiseModel getNoiseModel(); 
    5560     
    5661    public void setXInc(double xInc); 
  • trunk/projects/slim-plugin/src/main/java/imagej/slim/histogram/HistogramDataChannel.java

    r7834 r7842  
    44 */ 
    55package imagej.slim.histogram; 
     6 
     7import imagej.slim.fitting.InvalidDouble; 
    68 
    79/** 
     
    6870        for (int i = 0; i < _values.length; ++i) { 
    6971            for (int j = 0; j < _values[0].length; ++j) { 
    70                 if (_values[i][j] != Double.NaN) { 
     72                if (InvalidDouble.isValue(_values[i][j])) { 
    7173                    if (_values[i][j] < _min) { 
    7274                        _min = _values[i][j]; 
  • 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.