Ignore:
Timestamp:
02/08/12 19:08:00 (8 years ago)
Author:
aivar
Message:

SLIM Plugin: Got multiple channel fitting working.

Location:
trunk/projects/slim-plugin/src/main/java/imagej/slim
Files:
12 edited

Legend:

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

    r7875 r7887  
    44 */ 
    55package imagej.slim.fitting; 
     6 
     7import java.awt.image.IndexColorModel; 
    68 
    79import loci.curvefitter.ICurveFitter.FitAlgorithm; 
     
    2224    private NoiseModel _noiseModel; 
    2325    private String _fittedImages; 
     26    private IndexColorModel _indexColorModel; 
    2427    private String[] _analysisList; 
    2528    private boolean _fitAllChannels; 
     
    178181    public void setFittedImages(String fittedImages) { 
    179182        _fittedImages = fittedImages; 
     183    } 
     184     
     185    /** 
     186     * Returns color model for fitted images. 
     187     *  
     188     * @return 
     189     */ 
     190    public IndexColorModel getIndexColorModel() { 
     191        return _indexColorModel; 
     192    } 
     193 
     194    /** 
     195     * Sets color model for fitted images. 
     196     *  
     197     * @param indexColorModel  
     198     */ 
     199    public void setIndexColorModel(IndexColorModel indexColorModel) { 
     200        _indexColorModel = indexColorModel; 
    180201    } 
    181202 
  • trunk/projects/slim-plugin/src/main/java/imagej/slim/fitting/IDecayImage.java

    r7867 r7887  
    5050     * @return  
    5151     */ 
    52     public boolean fitThisPixel(int x, int y, int channel); 
     52    public boolean fitThisPixel(int[] location); 
    5353    
    5454    /** 
     
    6060     * @return  
    6161     */ 
    62     public double[] getPixel(int x, int y, int channel); 
     62    public double[] getPixel(int[] location); 
    6363 
    6464    /** 
  • trunk/projects/slim-plugin/src/main/java/imagej/slim/fitting/IFittedImage.java

    r7866 r7887  
    6262     * @param value 
    6363     */ 
    64     public void setPixel(int[] location, double[] value); 
    65  
    66     /** 
    67      * Gets fitted pixel value. 
    68      * 
    69      * @param x 
    70      * @param y 
    71      * @param channel 
    72      * @return 
    73      */ 
    74     public double[] getPixel(int x, int y, int channel); 
    75  
    76     /** 
    77      * Puts fitted pixel value. 
    78      *  
    79      * @param x 
    80      * @param y 
    81      * @param channel 
    82      * @param value 
    83      */ 
    84     public void setPixel(int x, int y, int channel, double[] value); 
    85      
     64    public void setPixel(int[] location, double[] value);    
    8665 
    8766    /** 
  • trunk/projects/slim-plugin/src/main/java/imagej/slim/fitting/images/AbstractBaseColorizedImage.java

    r7879 r7887  
    99import java.awt.event.FocusListener; 
    1010import java.awt.image.IndexColorModel; 
     11import java.util.ArrayList; 
     12import java.util.List; 
    1113 
    1214import ij.ImagePlus; 
     15import ij.ImageStack; 
    1316import ij.process.FloatProcessor; 
    1417 
     
    1720import imagej.slim.histogram.HistogramTool; 
    1821import imagej.slim.histogram.PaletteFix; 
     22 
     23import loci.slim.MyStackWindow; 
    1924 
    2025/** 
     
    2328 */ 
    2429abstract public class AbstractBaseColorizedImage implements IColorizedImage { 
     30    private static final int UNKNOWN_CHANNEL = -1; 
    2531    private String _title; 
     32    private int _width; 
     33    private int _height; 
     34    private int _channels; 
     35    private int _channel; 
     36    private ImageStack _imageStack; 
     37    private ImagePlus _imagePlus; 
     38    private MyStackWindow _stackWindow; 
    2639    private double _values[][]; 
     40    private HistogramDataChannel[] _histogramDataChannels; 
    2741    private HistogramData _histogramData; 
    28     private FloatProcessor _image; 
    29     private ImagePlus _imagePlus; 
    30      
    31     public AbstractBaseColorizedImage(String title, int[] dimension) { 
     42    private FloatProcessor _imageProcessor; 
     43     
     44    public AbstractBaseColorizedImage(String title, int[] dimension, 
     45            IndexColorModel indexColorModel) { 
    3246        _title = title; 
    33         int x = dimension[0]; 
    34         int y = dimension[1]; 
    35         _values = new double[x][y]; 
    36         //TODO need to handle multiple channels: 
    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, 
    38         // so better to keep _values around for each channel 
    39         HistogramDataChannel histogramDataChannel = new HistogramDataChannel(_values); 
    40         HistogramDataChannel[] histogramDataChannels = new HistogramDataChannel[] { histogramDataChannel }; 
    41         _histogramData = new HistogramData(this, title, histogramDataChannels); 
    42         _image = new FloatProcessor(x, y); 
    43         _image.setColorModel(imagej.slim.histogram.HistogramTool.getIndexColorModel()); 
    44         // fill the image with a value that will be out of LUT range and paint black. 
    45         _image.setValue(Float.NaN); 
    46         _image.fill(); 
    47         _imagePlus = new ImagePlus(title, _image); 
    48         _imagePlus.show(); 
    49         _imagePlus.getWindow().addFocusListener(new FocusListener() { 
     47        _width = dimension[0]; 
     48        _height = dimension[1]; 
     49        _channels = dimension[2]; 
     50        _channel = UNKNOWN_CHANNEL; 
     51         
     52        // building an image stack 
     53        _imageStack = new ImageStack(_width, _height); 
     54         
     55        // building a list of HistogramDataChannels 
     56        List<HistogramDataChannel> list = new ArrayList<HistogramDataChannel>(); 
     57         
     58        for (int c = 0; c < _channels; ++c) { 
     59            // build the actual displayed image 
     60            FloatProcessor imageProcessor = new FloatProcessor(_width, _height); 
     61            imageProcessor.setColorModel(indexColorModel); 
     62             
     63            // fill the image with a value that will be out of LUT range and 
     64            // paint black 
     65            imageProcessor.setValue(Float.NaN); 
     66            imageProcessor.fill(); 
     67             
     68            _imageStack.addSlice("" + c, imageProcessor); 
     69             
     70            // build the histogram data 
     71            _values = new double[_width][_height]; 
     72            clear(_values); 
     73            HistogramDataChannel histogramDataChannel = new HistogramDataChannel(_values); 
     74            list.add(histogramDataChannel);            
     75        } 
     76         
     77        _imagePlus = new ImagePlus(title, _imageStack); 
     78        _stackWindow = new MyStackWindow(_imagePlus); 
     79        _stackWindow.setVisible(true); 
     80        _stackWindow.addFocusListener(new FocusListener() { 
    5081            public void focusGained(FocusEvent e) { 
    5182                HistogramTool.getInstance().setHistogramData(_histogramData); 
     
    5485            public void focusLost(FocusEvent e) { } 
    5586        });   
     87         
     88        _histogramDataChannels 
     89                = list.toArray(new HistogramDataChannel[0]); 
     90        _histogramData = new HistogramData(this, title, _histogramDataChannels);  
    5691    } 
    5792 
     
    71106     */    
    72107    public void setColorModel(IndexColorModel colorModel) { 
    73         _image.setColorModel(colorModel); 
     108        _imageProcessor.setColorModel(colorModel); 
    74109    }     
    75110     
     
    86121     */ 
    87122    public void beginFit() { 
    88         // clear the 2D slice 
    89         clear(_values); 
    90     } 
     123    } 
     124     
    91125    /** 
    92126     * Ends a fit. 
     
    129163    private void redisplay(double[] minMaxLUT) { 
    130164        minMaxLUT = PaletteFix.adjustMinMax(minMaxLUT[0], minMaxLUT[1]); 
    131         System.out.println("***** REDISPLAY 256-COLOR SPECS ***** " + minMaxLUT[0] + " " + minMaxLUT[1]); 
    132         _image.setMinAndMax(minMaxLUT[0], minMaxLUT[1]); 
    133         _imagePlus.setProcessor(_image.duplicate()); 
     165        _imageProcessor.setMinAndMax(minMaxLUT[0], minMaxLUT[1]); 
     166        _imagePlus.setProcessor(_imageProcessor.duplicate()); //TODO ARG OUCH!  This ImagePlus holds an ImageStack - maybe update(ImageProcessor ip) Updates this stack so its attributes such as min max calibration table and color model, are the same as 'ip' 
    134167    } 
    135168 
     
    142175     */ 
    143176    public void updatePixel(int[] location, double[] parameters) { 
     177        // compute our displayable value from params 
    144178        double value = getValue(parameters); 
    145         int x = location[0]; 
    146         int y = location[1]; 
     179         
     180        int x       = location[0]; 
     181        int y       = location[1]; 
     182        int channel = location[2]; 
     183        System.out.println("updatePixel(" + x + " " + y + " " + channel + " prev channel is " + _channel); 
     184         
     185        if (_channel != channel) { 
     186            _channel = channel; 
     187            _stackWindow.showSlice(channel + 1); 
     188            _values = _histogramDataChannels[channel].getValues(); 
     189             
     190            System.out.println("values is " + _values + " " + _values.hashCode()); 
     191             
     192            _imageProcessor = (FloatProcessor) _imageStack.getProcessor(channel + 1); 
     193            System.out.println("ImageProc for " + channel + " is " + _imageProcessor.toString() + " hash " + _imageProcessor.hashCode()); 
     194        } 
     195         
    147196        _values[x][y] = value; 
    148         _image.setValue(value); 
    149         _image.drawPixel(x, y); 
     197        _imageProcessor.setValue(value); 
     198        _imageProcessor.drawPixel(x, y); 
    150199    } 
    151200 
  • trunk/projects/slim-plugin/src/main/java/imagej/slim/fitting/images/ColorizedImage.java

    r7865 r7887  
    44 */ 
    55package imagej.slim.fitting.images; 
     6 
     7import java.awt.image.IndexColorModel; 
    68 
    79import imagej.slim.fitting.images.AbstractBaseColorizedImage; 
     
    2224     * @param parameterIndex 
    2325     */ 
    24     public ColorizedImage(String title, int[] dimension, int parameterIndex) { 
    25         super(title, dimension); 
     26    public ColorizedImage(String title, int[] dimension, 
     27            IndexColorModel indexColorModel, int parameterIndex) { 
     28        super(title, dimension, indexColorModel); 
    2629        _parameterIndex = parameterIndex; 
    2730    } 
  • trunk/projects/slim-plugin/src/main/java/imagej/slim/fitting/images/ColorizedImageFactory.java

    r7865 r7887  
    44 */ 
    55package imagej.slim.fitting.images; 
     6 
     7import java.awt.image.IndexColorModel; 
    68 
    79import imagej.slim.fitting.images.IColorizedImage; 
     
    2830    } 
    2931     
    30     public IColorizedImage createImage(ColorizedImageType outputImage, int[] dimension, int components) { 
     32    public IColorizedImage createImage(ColorizedImageType outputImage, 
     33            int[] dimension, IndexColorModel indexColorModel, int components) { 
    3134        IColorizedImage fittedImage = null; 
    3235        String title; 
     
    3437            case A1: 
    3538                title = (1 == components) ? "A" : "A1"; 
    36                 fittedImage = new ColorizedImage(title, dimension, ColorizedImageFitter.A1_INDEX); 
     39                fittedImage = new ColorizedImage(title, dimension, 
     40                        indexColorModel, ColorizedImageFitter.A1_INDEX); 
    3741                break; 
    3842            case T1: 
    3943                title = (1 == components) ? "T" : "T1"; 
    40                 fittedImage = new ColorizedImage(title, dimension, ColorizedImageFitter.T1_INDEX); 
     44                fittedImage = new ColorizedImage(title, dimension, 
     45                        indexColorModel, ColorizedImageFitter.T1_INDEX); 
    4146                break; 
    4247            case A2: 
    43                 fittedImage = new ColorizedImage("A2", dimension, ColorizedImageFitter.A2_INDEX); 
     48                fittedImage = new ColorizedImage("A2", dimension, 
     49                        indexColorModel, ColorizedImageFitter.A2_INDEX); 
    4450                break; 
    4551            case T2: 
    46                 fittedImage = new ColorizedImage("T2", dimension, ColorizedImageFitter.T2_INDEX); 
     52                fittedImage = new ColorizedImage("T2", dimension, 
     53                        indexColorModel, ColorizedImageFitter.T2_INDEX); 
    4754                break; 
    4855            case A3: 
    49                 fittedImage = new ColorizedImage("A3", dimension, ColorizedImageFitter.A2_INDEX); 
     56                fittedImage = new ColorizedImage("A3", dimension, 
     57                        indexColorModel, ColorizedImageFitter.A2_INDEX); 
    5058                break; 
    5159            case T3: 
    52                 fittedImage = new ColorizedImage("T3", dimension, ColorizedImageFitter.T2_INDEX); 
     60                fittedImage = new ColorizedImage("T3", dimension, 
     61                        indexColorModel, ColorizedImageFitter.T2_INDEX); 
    5362                break; 
    5463            case H: 
    55                 fittedImage = new ColorizedImage("H", dimension, ColorizedImageFitter.H_INDEX); 
     64                fittedImage = new ColorizedImage("H", dimension, 
     65                        indexColorModel, ColorizedImageFitter.H_INDEX); 
    5666                break; 
    5767            case Z: 
    58                 fittedImage = new ColorizedImage("Z", dimension, ColorizedImageFitter.Z_INDEX); 
     68                fittedImage = new ColorizedImage("Z", dimension, 
     69                        indexColorModel, ColorizedImageFitter.Z_INDEX); 
    5970                break; 
    6071            case CHISQ: 
    61                 fittedImage = new ColorizedImage("ChiSquare", dimension, ColorizedImageFitter.CHISQ_INDEX); 
     72                fittedImage = new ColorizedImage("ChiSquare", dimension, 
     73                        indexColorModel, ColorizedImageFitter.CHISQ_INDEX); 
    6274                break; 
    6375            case F1: 
    64                 fittedImage = new FractionalIntensityImage("F1", dimension, 0, components); 
     76                fittedImage = new FractionalIntensityImage("F1", dimension, 
     77                        indexColorModel, 0, components); 
    6578                break; 
    6679            case F2: 
    67                 fittedImage = new FractionalIntensityImage("F2", dimension, 1, components); 
     80                fittedImage = new FractionalIntensityImage("F2", dimension, 
     81                        indexColorModel, 1, components); 
    6882                break; 
    6983            case F3: 
    70                 fittedImage = new FractionalIntensityImage("F3", dimension, 2, components); 
     84                fittedImage = new FractionalIntensityImage("F3", dimension, 
     85                        indexColorModel, 2, components); 
    7186                break; 
    7287            case f1: 
    73                 fittedImage = new FractionalContributionImage("f1", dimension, 0, components); 
     88                fittedImage = new FractionalContributionImage("f1", dimension, 
     89                        indexColorModel, 0, components); 
    7490                break; 
    7591            case f2: 
    76                 fittedImage = new FractionalContributionImage("f2", dimension, 1, components); 
     92                fittedImage = new FractionalContributionImage("f2", dimension, 
     93                        indexColorModel, 1, components); 
    7794                break; 
    7895            case f3: 
    79                 fittedImage = new FractionalContributionImage("f3", dimension, 2, components); 
     96                fittedImage = new FractionalContributionImage("f3", dimension, 
     97                        indexColorModel, 2, components); 
    8098                break; 
    8199        } 
  • trunk/projects/slim-plugin/src/main/java/imagej/slim/fitting/images/ColorizedImageFitter.java

    r7865 r7887  
    55package imagej.slim.fitting.images; 
    66 
     7import java.awt.image.IndexColorModel; 
    78import java.util.ArrayList; 
    89import java.util.List; 
     
    3132    } 
    3233     
    33     public void setUpFit(ColorizedImageType[] images, int[] dimension, int components) { 
     34    public void setUpFit(ColorizedImageType[] images, int[] dimension, 
     35            IndexColorModel indexColorModel, int components) { 
    3436        _fittedImages.clear(); 
    3537        for (ColorizedImageType image : images) { 
    36             IColorizedImage fittedImage = ColorizedImageFactory.getInstance().createImage(image, dimension, components); 
     38            IColorizedImage fittedImage = 
     39                    ColorizedImageFactory.getInstance().createImage 
     40                            (image, dimension, indexColorModel, components); 
    3741            _fittedImages.add(fittedImage); 
    3842        } 
     
    4145        int lastIndex = images.length - 1; 
    4246        if (lastIndex >= 0) { 
    43             HistogramTool.getInstance().setHistogramData(_fittedImages.get(lastIndex).getHistogramData()); 
     47            HistogramTool.getInstance().setHistogramData 
     48                    (_fittedImages.get(lastIndex).getHistogramData()); 
    4449        } 
    4550    } 
     
    5055    public void beginFit() { 
    5156        for (IColorizedImage fittedImage : _fittedImages) { 
    52             //fittedImage.setColorModel(HistogramTool.getLUT()); //TODO getIndexColorModel()); //TODO all the same really as far as I can tell, i.e. broken 
    5357            fittedImage.beginFit(); 
    5458        } 
  • trunk/projects/slim-plugin/src/main/java/imagej/slim/fitting/images/FractionalContributionImage.java

    r7865 r7887  
    44 */ 
    55package imagej.slim.fitting.images; 
     6 
     7import java.awt.image.IndexColorModel; 
    68 
    79import imagej.slim.fitting.images.AbstractBaseColorizedImage; 
     
    2830     * @param components  
    2931     */ 
    30     public FractionalContributionImage(String title, int[] dimension, int component, int components) { 
    31         super(title, dimension); 
     32    public FractionalContributionImage(String title, int[] dimension, 
     33            IndexColorModel indexColorModel, int component, int components) { 
     34        super(title, dimension, indexColorModel); 
    3235        _component = component; 
    3336        _components = components; 
  • trunk/projects/slim-plugin/src/main/java/imagej/slim/fitting/images/FractionalIntensityImage.java

    r7865 r7887  
    44 */ 
    55package imagej.slim.fitting.images; 
     6 
     7import java.awt.image.IndexColorModel; 
    68 
    79import imagej.slim.fitting.images.AbstractBaseColorizedImage; 
     
    2830     * @param components  
    2931     */ 
    30     public FractionalIntensityImage(String title, int[] dimension, int component, int components) { 
    31         super(title, dimension); 
     32    public FractionalIntensityImage(String title, int[] dimension, 
     33            IndexColorModel indexColorModel, int component, int components) { 
     34        super(title, dimension, indexColorModel); 
    3235        _component = component; 
    3336        _components = components; 
  • trunk/projects/slim-plugin/src/main/java/imagej/slim/histogram/HistogramData.java

    r7879 r7887  
    6161        _listener = listener; 
    6262    } 
    63      
     63      
    6464    /** 
    6565     * Gets a descriptive title to display on histogram UI for this data. 
  • trunk/projects/slim-plugin/src/main/java/imagej/slim/histogram/HistogramDataChannel.java

    r7845 r7887  
    3030    public HistogramDataChannel(double[][] values) { 
    3131        _values = values; 
     32    } 
     33 
     34    /** 
     35     * Gets the values array. 
     36     *  
     37     * @return  
     38     */ 
     39    public double[][] getValues() { 
     40        return _values; 
    3241    } 
    3342 
  • trunk/projects/slim-plugin/src/main/java/imagej/slim/histogram/UIPanel.java

    r7879 r7887  
    121121            } 
    122122        ); 
    123         if (hasChannels) { 
     123        /** 
     124         * IJ1 uses the same LUT for the entire stack.  It might be possible for 
     125         * the histogram tool to set the appropriate LUT for the current channel 
     126         * but there is no listener or event for the histogram tool to know when 
     127         * the channel changes. 
     128         *  
     129         * Perhaps this can change with IJ2. 
     130         *  
     131         * ARG 2/8/12 
     132         */ 
     133        if (false && hasChannels) { 
    124134            add(_combineChannelsCheckBox); 
    125135        } 
     
    137147            } 
    138148        ); 
    139         if (hasChannels) { 
     149        /** 
     150         * Now that we're down to one extra checkbox for channels, lets always 
     151         * display it.  (See above.) 
     152         *  
     153         * ARG 2/8/12 
     154         */ 
     155        if (true || hasChannels) { 
    140156            add(_displayChannelsCheckBox); 
    141157        } 
     
    176192     */ 
    177193    public void dragMinMaxLUT(double min, double max) { 
    178         System.out.println("UIPanel.dragMinMaxLUT " + min + " " + max); 
     194//        System.out.println("UIPanel.dragMinMaxLUT " + min + " " + max); 
    179195        showMinMaxLUT(min, max); 
    180196    } 
     
    187203     */ 
    188204    public void setMinMaxLUT(double min, double max) { 
    189         System.out.println("UIPanel.setMinMaxLUT " + min + " " + max); 
     205//        System.out.println("UIPanel.setMinMaxLUT " + min + " " + max); 
    190206        showMinMaxLUT(min, max); 
    191207        //TODO anything else?  if not combine these two methods 
Note: See TracChangeset for help on using the changeset viewer.