Changeset 7829 for trunk/projects/slim-plugin/src/main/java
- Timestamp:
- 12/09/11 18:51:19 (8 years ago)
- Location:
- trunk/projects/slim-plugin/src/main/java/imagej/slim
- Files:
-
- 3 added
- 2 deleted
- 3 edited
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/projects/slim-plugin/src/main/java/imagej/slim/fitting/AbstractBaseFittedImage.java
r7828 r7829 6 6 package imagej.slim.fitting; 7 7 8 import ij.process.MyFloatProcessor; //TODO IJ hack; update to IJ2 ImgLib 9 8 10 import imagej.slim.histogram.HistogramData; 11 import imagej.slim.histogram.HistogramDataChannel; 9 12 10 13 /** … … 14 17 abstract public class AbstractBaseFittedImage implements IFittedImage { 15 18 private String _title; 19 private double _values[][]; 16 20 private HistogramData _histogramData; 21 private MyFloatProcessor _image; 17 22 18 public void setTitle(String title) {23 public AbstractBaseFittedImage(String title, int[] dimension) { 19 24 _title = title; 25 int x = dimension[0]; 26 int y = dimension[1]; 27 _values = new double[x][y]; 28 HistogramDataChannel histogramDataChannel = new HistogramDataChannel(_values); 29 HistogramDataChannel[] histogramDataChannels = new HistogramDataChannel[] { histogramDataChannel }; 30 _histogramData = new HistogramData(title, histogramDataChannels); 31 _image = new MyFloatProcessor(x, y); 20 32 } 21 33 34 /** 35 * Gets the title of the fitted image. 36 * 37 * @return 38 */ 22 39 public String getTitle() { 23 40 return _title; 24 41 } 25 26 /** 27 * Sets the histogram data object associated with this fitted image. 28 * 29 * @param histogramData 30 */ 31 public void setHistogramData(HistogramData histogramData) { 32 _histogramData = histogramData; 33 } 34 42 35 43 /** 36 44 * Gets the associated histogram data object. … … 45 53 */ 46 54 public void beginFit() { 55 // clear the 2D slice 56 clear(_values); 47 57 48 58 } … … 51 61 */ 52 62 public void endFit() { 53 54 }55 56 /**57 * Updates the fitted parameters for a pixel.58 *59 * @param location60 * @param parameters61 */62 abstract public void updatePixel(int[] location, double[] parameters);63 64 /**65 * Updates the fitted parameters for a pixel. The pixel is drawn66 * outsized at first.67 *68 * @param location69 * @param dimension70 * @param parameters71 */72 abstract public void updateChunkyPixel(int[] location, int[] dimension, double[] parameters);73 74 private void updatePixel(int[] location, double value) {75 }76 77 private void updateChunkyPixel(int location[], double value) {78 63 79 64 } … … 87 72 // etc. 88 73 } 74 75 /** 76 * Updates the fitted parameters for a pixel. 77 * 78 * @param location 79 * @param parameters 80 */ 81 public void updatePixel(int[] location, double[] parameters) { 82 double value = getValue(parameters); 83 int x = location[0]; 84 int y = location[1]; 85 _values[x][y] = value; 86 _image.setValue(value); 87 _image.drawPixel(x, y); 88 } 89 90 /** 91 * Updates the fitted parameters for a pixel. The pixel is drawn 92 * outsized at first. 93 * 94 * @param location 95 * @param dimension 96 * @param parameters 97 */ 98 public void updateChunkyPixel 99 (int[] location, int[] dimension, double[] parameters) 100 { 101 //TODO for now, draw w/o chunkiness: 102 updatePixel(location, parameters); 103 } 104 105 /** 106 * Given the array of fitted parameters, get the value for this image. 107 * 108 * @param parameters 109 * @return 110 */ 111 abstract public double getValue(double[] parameters); 112 113 private void clear(double[][] values) { 114 for (int y = 0; y < values[0].length; ++y) { 115 for (int x = 0; x < values.length; ++x) { 116 values[x][y] = Double.NaN; 117 } 118 } 119 } 89 120 } -
trunk/projects/slim-plugin/src/main/java/imagej/slim/fitting/FLIMFittedImageFactory.java
r7825 r7829 5 5 package imagej.slim.fitting; 6 6 7 import imagej.slim.fitting. ImageFitter.OutputImage;7 import imagej.slim.fitting.FLIMImageFitter.OutputImage; 8 8 9 9 /** … … 11 11 * @author aivar 12 12 */ 13 public class OutputImageFactory {14 private static OutputImageFactory INSTANCE = null;13 public class FLIMFittedImageFactory { 14 private static FLIMFittedImageFactory INSTANCE = null; 15 15 16 private OutputImageFactory() {16 private FLIMFittedImageFactory() { 17 17 } 18 18 19 public static synchronized OutputImageFactory getInstance() {19 public static synchronized FLIMFittedImageFactory getInstance() { 20 20 if (null == INSTANCE) { 21 INSTANCE = new OutputImageFactory();21 INSTANCE = new FLIMFittedImageFactory(); 22 22 } 23 23 return INSTANCE; 24 24 } 25 25 26 public IOutputImage createImage(OutputImage outputImage) { 26 public IFittedImage createImage(OutputImage outputImage, int[] dimension, int components) { 27 IFittedImage fittedImage = null; 27 28 switch (outputImage) { 28 case A:29 case T:30 29 case A1: 30 fittedImage = new FittedImage("A1", dimension, FLIMImageFitter.A1_INDEX); 31 break; 31 32 case T1: 33 fittedImage = new FittedImage("T1", dimension, FLIMImageFitter.T1_INDEX); 34 break; 32 35 case A2: 36 fittedImage = new FittedImage("A2", dimension, FLIMImageFitter.A2_INDEX); 37 break; 33 38 case T2: 39 fittedImage = new FittedImage("T2", dimension, FLIMImageFitter.T2_INDEX); 40 break; 41 case A3: 42 fittedImage = new FittedImage("A3", dimension, FLIMImageFitter.A2_INDEX); 43 break; 44 case T3: 45 fittedImage = new FittedImage("T3", dimension, FLIMImageFitter.T2_INDEX); 46 break; 34 47 case H: 48 fittedImage = new FittedImage("H", dimension, FLIMImageFitter.H_INDEX); 49 break; 35 50 case Z: 36 case F0: 51 fittedImage = new FittedImage("Z", dimension, FLIMImageFitter.Z_INDEX); 52 break; 53 case CHISQ: 54 fittedImage = new FittedImage("ChiSquare", dimension, FLIMImageFitter.CHISQ_INDEX); 55 break; 37 56 case F1: 57 fittedImage = new FractionalIntensityImage("F1", dimension, 0, components); 58 break; 59 case F2: 60 fittedImage = new FractionalIntensityImage("F2", dimension, 1, components); 61 break; 62 case F3: 63 fittedImage = new FractionalIntensityImage("F3", dimension, 2, components); 64 break; 65 case f1: 66 fittedImage = new FractionalContributionImage("f1", dimension, 0, components); 67 break; 68 case f2: 69 fittedImage = new FractionalContributionImage("f2", dimension, 1, components); 70 break; 71 case f3: 72 fittedImage = new FractionalContributionImage("f3", dimension, 2, components); 73 break; 38 74 } 39 75 return null; -
trunk/projects/slim-plugin/src/main/java/imagej/slim/fitting/FLIMImageFitter.java
r7825 r7829 4 4 */ 5 5 package imagej.slim.fitting; 6 7 import java.util.ArrayList; 8 import java.util.List; 6 9 7 10 import imagej.slim.fitting.engine.IFittingEngine; … … 12 15 * @author aivar 13 16 */ 14 public class ImageFitter { 15 public enum OutputImage { A, T, A1, T1, A2, T2, A3, T3, H, Z, CHISQ, F0, F1 }; 17 public class FLIMImageFitter { 18 public enum OutputImage { A1, T1, A2, T2, A3, T3, H, Z, CHISQ, F1, F2, F3, f1, f2, f3 }; 19 public static final int A1_INDEX = 2; 20 public static final int T1_INDEX = 3; 21 public static final int A2_INDEX = 4; 22 public static final int T2_INDEX = 5; 23 public static final int A3_INDEX = 6; 24 public static final int T3_INDEX = 7; 25 public static final int H_INDEX = 4; 26 public static final int Z_INDEX = 1; 27 public static final int CHISQ_INDEX = 0; 28 private List<IFittedImage> _fittedImages; 16 29 private IFittingEngine _fittingEngine; 17 30 18 public ImageFitter() { 31 public FLIMImageFitter() { 32 _fittedImages = new ArrayList<IFittedImage>(); 33 //TODO s/b configurable which fitting engine to use: 19 34 _fittingEngine = new ThreadedFittingEngine(); 20 35 } 21 36 22 public void fit(OutputImage[] images) { 23 37 public void setUpFit(OutputImage[] images, int[] dimension, int components) { 38 _fittedImages.clear(); 39 for (OutputImage image : images) { 40 IFittedImage fittedImage = FLIMFittedImageFactory.getInstance().createImage(image, dimension, components); 41 _fittedImages.add(fittedImage); 42 } 24 43 } 44 45 /** 46 * Begins a fit. 47 */ 48 public void beginFit() { 49 for (IFittedImage fittedImage : _fittedImages) { 50 fittedImage.beginFit(); 51 } 52 } 53 54 /** 55 * Ends a fit. 56 */ 57 public void endFit() { 58 for (IFittedImage fittedImage : _fittedImages) { 59 fittedImage.beginFit(); 60 } 61 62 } 63 64 /** 65 * Updates the fitted parameters for a pixel. 66 * 67 * @param location 68 * @param parameters 69 */ 70 public void updatePixel(int[] location, double[] parameters) { 71 for (IFittedImage fittedImage : _fittedImages) { 72 fittedImage.updatePixel(location, parameters); 73 } 74 } 75 76 /** 77 * Updates the fitted parameters for a pixel. The pixel is drawn 78 * outsized at first. 79 * 80 * @param location 81 * @param dimension 82 * @param parameters 83 */ 84 public void updateChunkyPixel(int[] location, int[] dimension, double[] parameters) { 85 for (IFittedImage fittedImage : _fittedImages) { 86 fittedImage.updateChunkyPixel(location, dimension, parameters); 87 } 88 } 89 /** 90 * Recalculates the image histogram and resets the palette. Called 91 * periodically during the fit. 92 */ 93 public void recalcHistogram() { 94 for (IFittedImage fittedImage : _fittedImages) { 95 fittedImage.recalcHistogram(); 96 } 97 } 98 25 99 } -
trunk/projects/slim-plugin/src/main/java/imagej/slim/fitting/IFittedImage.java
r7828 r7829 13 13 */ 14 14 public interface IFittedImage { 15 16 /**17 * Sets the histogram data object associated with this fitted image.18 *19 * @param histogramData20 */21 public void setHistogramData(HistogramData histogramData);22 15 23 16 /** … … 60 53 */ 61 54 public void recalcHistogram(); 55 56 /** 57 * Given the array of fitted parameters, get the value for this image. 58 * 59 * @param parameters 60 * @return 61 */ 62 public double getValue(double[] parameters); 62 63 } -
trunk/projects/slim-plugin/src/main/java/imagej/slim/histogram/HistogramData.java
r7825 r7829 12 12 */ 13 13 public class HistogramData { 14 private HistogramChannelData[] _channel;15 14 private String _title; 15 private HistogramDataChannel[] _channel; 16 16 private int _channelIndex; 17 17 private boolean _auto; 18 18 private boolean _combine; 19 19 private boolean _showAll; 20 private float_minView;21 private float_maxView;22 private float_minLUT;23 private float_maxLUT;20 private double _minView; 21 private double _maxView; 22 private double _minLUT; 23 private double _maxLUT; 24 24 25 25 /** … … 28 28 * @param channel 29 29 */ 30 public HistogramData(HistogramChannelData[] channel, String title) { 30 public HistogramData(String title, HistogramDataChannel[] channel) { 31 _title = title; 31 32 _channel = channel; 32 _title = title;33 33 _channelIndex = 0; 34 34 _minView = _maxView = 0.0f; … … 105 105 * @return 106 106 */ 107 public float[] getMinMaxView() {108 return new float[] { _minView, _maxView };107 public double[] getMinMaxView() { 108 return new double[] { _minView, _maxView }; 109 109 } 110 110 … … 114 114 * @return 115 115 */ 116 public float[] getMinMaxLUT() {117 return new float[] { _minLUT, _maxLUT };116 public double[] getMinMaxLUT() { 117 return new double[] { _minLUT, _maxLUT }; 118 118 } 119 119 … … 125 125 //TODO s/b setting both view and lut min/max if automatic, o'wise no change 126 126 //TODO who is calling this???? 127 public float[] getMinMax() {128 float[] minMax = null;127 public double[] getMinMax() { 128 double[] minMax = null; 129 129 130 130 if (_auto) { 131 131 if (_combine) { 132 float min = Float.MAX_VALUE;133 float max = Float.MIN_VALUE;132 double min = Double.MAX_VALUE; 133 double max = Double.MIN_VALUE; 134 134 135 135 // calculate actual minimum and maximum for all channels … … 143 143 } 144 144 } 145 minMax = new float[] { min, max };145 minMax = new double[] { min, max }; 146 146 } 147 147 else { -
trunk/projects/slim-plugin/src/main/java/imagej/slim/histogram/HistogramDataChannel.java
r7825 r7829 11 11 * @author aivar 12 12 */ 13 public class Histogram ChannelData{14 private float[][] _values;15 private float_actualMin;16 private float_actualMax;13 public class HistogramDataChannel { 14 private double[][] _values; 15 private double _actualMin; 16 private double _actualMax; 17 17 18 18 /** … … 21 21 * @param values 22 22 */ 23 public Histogram ChannelData(float[][] values) {23 public HistogramDataChannel(double[][] values) { 24 24 _values = values; 25 25 _actualMin = _actualMax = 0.0f; … … 32 32 * @return array of { min, max } 33 33 */ 34 public float[] resetActualMinMax() {35 _actualMin = Float.MAX_VALUE;36 _actualMax = Float.MIN_VALUE;34 public double[] resetActualMinMax() { 35 _actualMin = Double.MAX_VALUE; 36 _actualMax = Double.MIN_VALUE; 37 37 for (int i = 0; i < _values.length; ++i) { 38 38 for (int j = 0; j < _values[0].length; ++j) { 39 if (_values[i][j] != Float.NaN) {39 if (_values[i][j] != Double.NaN) { 40 40 if (_values[i][j] < _actualMin) { 41 41 _actualMin = _values[i][j]; … … 50 50 } 51 51 52 public float[] getActualMinMax() {53 return new float[] { _actualMin, _actualMax };52 public double[] getActualMinMax() { 53 return new double[] { _actualMin, _actualMax }; 54 54 } 55 55 … … 63 63 * @return histogram array with counts per bin 64 64 */ 65 public int[] binValues(int bins, float nominalMin, floatnominalMax) {65 public int[] binValues(int bins, double nominalMin, double nominalMax) { 66 66 int[] results = new int[bins]; 67 67 for (int i = 0; i < bins; ++i) { 68 68 results[i] = 0; 69 69 } 70 floatbinWidth = bins / (nominalMax - nominalMin);70 double binWidth = bins / (nominalMax - nominalMin); 71 71 for (int i = 0; i < _values.length; ++i) { 72 72 for (int j = 0; j < _values[0].length; ++j) { 73 floatvalue = _values[i][j];73 double value = _values[i][j]; 74 74 if (value >= nominalMin && value <= nominalMax) { 75 75 // assign each value to a bin
Note: See TracChangeset
for help on using the changeset viewer.