Changeset 7133


Ignore:
Timestamp:
10/25/10 22:30:53 (9 years ago)
Author:
aivar
Message:

Added image stack support for multiple channels. Support for multiple exponential fit. Added some odd adjustments to photon counts and time intervals to make the data correspond with TRI2's view of the data for 'brian\gpl1.sdt'. Better starting values for single, double, triple fits.

File:
1 edited

Legend:

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

    r7112 r7133  
    3737import ij.IJ; 
    3838import ij.ImagePlus; 
     39import ij.ImageStack; 
    3940import ij.gui.GenericDialog; 
    4041import ij.gui.ImageWindow; 
     
    5556import java.awt.event.MouseEvent; 
    5657import java.awt.event.MouseListener; 
     58import java.awt.image.ColorModel; 
    5759import java.util.ArrayList; 
    5860import java.util.HashMap; 
     
    124126    private static final Character SUB_3  = '\u2083'; 
    125127 
    126     private static final double[] DEFAULT_SINGLE_EXP_PARAMS = { 5000.0, 0.005, 0.5 }; 
    127     private static final double[] DEFAULT_DOUBLE_EXP_PARAMS = { 0.0 }; 
    128     private static final double[] DEFAULT_TRIPLE_EXP_PARAMS = { 0.0 }; 
     128    private static final double[] DEFAULT_SINGLE_EXP_PARAMS = { 100.0, 0.5, 0.5 }; 
     129    private static final double[] DEFAULT_DOUBLE_EXP_PARAMS = { 50.0, 0.5, 50, 0.25, 0.5 }; 
     130    private static final double[] DEFAULT_TRIPLE_EXP_PARAMS = { 40.0, 0.5, 30.0, 0.25, 30, 0.10, 0.5 }; 
    129131 
    130132    private Object m_synchFit = new Object(); 
     
    214216            uiPanel.setThreshold(100); 
    215217            uiPanel.setFunctionParameters(0, DEFAULT_SINGLE_EXP_PARAMS); 
    216             //uiPanel.setFunctionParameters(1, DEFAULT_DOUBLE_EXP_PARAMS); 
    217             //uiPanel.setFunctionParameters(2, DEFAULT_TRIPLE_EXP_PARAMS); 
     218            uiPanel.setFunctionParameters(1, DEFAULT_DOUBLE_EXP_PARAMS); 
     219            uiPanel.setFunctionParameters(2, DEFAULT_TRIPLE_EXP_PARAMS); 
    218220            uiPanel.setListener( 
    219221                    new IUserInterfacePanelListener() { 
     
    317319            uiPanel.setX(0); 
    318320            uiPanel.setY(0); 
    319             uiPanel.setStart(0); 
     321            uiPanel.setStart(m_timeBins / 2); 
    320322            uiPanel.setStop(m_timeBins - 1); 
    321323            uiPanel.setThreshold(100); 
    322324            uiPanel.setFunctionParameters(0, DEFAULT_SINGLE_EXP_PARAMS); 
    323             //uiPanel.setFunctionParameters(1, DEFAULT_DOUBLE_EXP_PARAMS); 
    324            // uiPanel.setFunctionParameters(2, DEFAULT_TRIPLE_EXP_PARAMS); 
     325            uiPanel.setFunctionParameters(1, DEFAULT_DOUBLE_EXP_PARAMS); 
     326            uiPanel.setFunctionParameters(2, DEFAULT_TRIPLE_EXP_PARAMS); 
    325327            uiPanel.setListener( 
    326328                new IUserInterfacePanelListener() { 
     
    434436    
    435437    private boolean newLoadData(Image<T> image) { 
     438        System.out.println("Image is " + image); 
    436439        int[] dimensions = image.getDimensions(); 
    437440        System.out.println("dimensions size is " + dimensions.length); 
     
    492495                        cursor.moveTo(dimensions); 
    493496                        m_data[channel][y][x][bin] = (int) cursor.getType().getRealFloat(); 
     497                        m_data[channel][y][x][bin] /= 10.0f; //TODO in accordance with TRI2 
    494498                    } 
    495499                } 
     
    505509 
    506510        // patch things up 
    507         m_timeRange = 10.0f; 
     511        m_timeRange = 10.0f / 64.0f; //TODO ARG this patches things up in accord with TRI2 for brian/gpl1.sdt; very odd value here 
    508512        m_minWave = 400; 
    509513        m_waveStep = 10; 
     
    745749    private boolean createGlobalGrayScale(String name, final IUserInterfacePanel uiPanel) { 
    746750        int[][] pixels = new int[m_width][m_height]; 
    747  
     751        byte[] outPixels = new byte[m_width * m_height]; 
     752 
     753 
     754        ImageStack imageStack = new ImageStack(m_width, m_height, ColorModel.getRGBdefault(), null); 
     755        for (int c = 0; c < m_channels; ++c) { 
     756            // sum photon counts 
     757            int maxPixel = 0; 
     758            for (int x = 0; x < m_width; ++x) { 
     759                for (int y = 0; y < m_height; ++y) { 
     760                    pixels[x][y] = 0; 
     761                    for (int b = 0; b < m_timeBins; ++b) { 
     762                        pixels[x][y] += m_data[c][y][x][b]; 
     763                    } 
     764                    if (pixels[x][y] > maxPixel) { 
     765                        maxPixel = pixels[x][y]; 
     766                    } 
     767                } 
     768            } 
     769 
     770            // convert to grayscale 
     771            for (int x = 0; x < m_width; ++x) { 
     772                for (int y = 0; y < m_height; ++y) { 
     773                    // flip y axis to correspond with Slim Plotter image 
     774                    outPixels[y * m_width + x] = (byte) (pixels[x][m_height - y - 1] * 255 / maxPixel); 
     775                } 
     776            } 
     777 
     778            // add a slice 
     779            imageStack.addSlice("" + c, true, outPixels); 
     780        } 
     781        ImagePlus imagePlus = new ImagePlus(name + " GrayScale", imageStack); 
     782        imagePlus.show(); 
     783        m_grayscaleImageProcessor = imagePlus.getChannelProcessor(); 
     784        /* 
    748785        int maxPixel = 0; 
    749786        for (int x = 0; x < m_width; ++x) { 
     
    773810        imagePlus.show(); 
    774811        m_grayscaleImageProcessor = imageProcessor; //TODO for now 
    775  
     812*/ 
    776813        // hook up mouse listener 
    777814        ImageWindow imageWindow = imagePlus.getWindow(); 
     
    12021239        for (int b = 0; b < m_timeBins; ++b) { 
    12031240            yCount[b] = m_data[m_channel][m_height - y - 1][x][b]; 
     1241            //System.out.println("" + b + " " + yCount[b]); 
    12041242        } 
    12051243        curveFitData.setYCount(yCount); 
     
    12511289                ++pixelCount; 
    12521290                if (m_cancel) { 
     1291                    IJ.showProgress(0, 0); //TODO kludgy to have this here and also below 
     1292                    dataColorizer.quit(); 
    12531293                    return; 
    12541294                } 
     
    12801320                processPixels(uiPanel, dataColorizer, m_height, curveFitDataList.toArray(new ICurveFitData[0]), pixelList.toArray(new ChunkyPixel[0])); 
    12811321            } 
     1322        } 
     1323        if (m_cancel) { 
     1324            IJ.showProgress(0, 0); //TODO the code below s/b showing progress also 
     1325           // dataColorizer.quit(); //TODO no longer visible in this code 
     1326            return; 
    12821327        } 
    12831328  
     
    15351580     * @param dataArray array of data to fit 
    15361581     */ 
     1582    //TODO shouldn't be creating many curveFitters for each chunk of pixels. 
    15371583    //TODO s/b a mechanism to add these curve fit libraries? 
    15381584    private void doFit(IUserInterfacePanel uiPanel, ICurveFitData dataArray[]) { 
     
    15691615        } 
    15701616        curveFitter.setXInc(m_timeRange); 
    1571         curveFitter.setFree(m_free); 
     1617        curveFitter.setFree(uiPanel.getFree()); 
    15721618        curveFitter.fitData(dataArray, m_startBin, m_stopBin); 
    15731619    } 
Note: See TracChangeset for help on using the changeset viewer.