Class AlgorithmColocalizationRegression

  • All Implemented Interfaces:
    UpdateVOISelectionListener, java.awt.event.ActionListener, java.awt.event.WindowListener, java.lang.Runnable, java.util.EventListener

    public class AlgorithmColocalizationRegression
    extends AlgorithmBase
    implements UpdateVOISelectionListener
    This algorithm creates a 2D histogram from 2 colors of a single image or from 2 black and white images and uses an orthogonal line fit of the histogram data to generate a correlation line thru the histogram. Upper right region rectangles with lower left corners on the correlation line are used as colocalization regions, regions where both of the 2 colors are significantly above background. The colocalization frame is tied to a version of the source image or images, so that only pixels located in the colocalization region are displayed. When not in free range mode, a user movable point along the correlation line allows for the display of source image pixels and statistics associated with different upper right colocalization regions. In free range mode, the point can be moved anywhere in the histogram buffer.

    If neither registration or background subtraction are selected, then the original source image or images are used in the histogram buffer. If registration is selected and background subtraction is not selected, then the registered image or images are used in the histogram buffer. If registration is not selected and background subtraction is selected, then the subtracted image or images are used in the histogram buffer. If both registration and subtraction are selected, then the background averages are obtained from the original source image or images. Next, registration is performed. Finally, background subtraction is performed on the registered image or images and the subtracted image or images are used for the histogram buffer. If the maximum data range is decreased, then bin1 or bin2 will be decreased if necessary so as not to exceed the actual number of channels in the data range.

    Note that the background selection voi is always blue and the voi to limit analysis to a region of the image is assumed to be a different color.

    An optional registration may be performed before colocalization. In this registration both images or colors are moved halfway to a common center point. The registration is always done on an entire image. AlgorithmRegOAR2D is used with the cost function being the only registration parameter the user can vary in the dialog box. Correlation ratio is the default, but the user can also select least squares, normalized cross correlation, or normalized mutual information. The colocalization will be performed on the registered image or images rather than on the original image.

    The amount of colocalization can be measured with the linear correlation coefficient. Let the 2 channels be R and G, the average values be Rav and Gav. Then the linear correlation coefficient = num/denom with num = sum over i of ((R(i) - Rav) * (G(i) - Gav)) denom = square root[(sum over i of (R(i) - Rav)*(R(i) - Rav)) * (sum over i of (G(i) - Gav)* (G(i) - Gav))] This is equivalent to the more traditional form of the equation: with num = Nsum(R(i)G(i)) - sum(R(i))sum(G(i)) denom = sqrt[Nsum(R(i)*R(i)) - (sumR(i))*(sumR(i))] * sqrt[Nsum(G(i)*G(i)) - (sumG(i))*(sumG(i))] The linear correlation coefficient ranges from -1 to 1 with 0 the value for random patterns and 1 the value for 100% colocalization. Negative values of the coefficient are not used for colocalization since that would indicate an anticolocalized situation with a bright pixel in one channel implying a dim pixel in another channel. Note that the medical literature on colocalization refers to the traditional linear correlation coefficient as Pearson's coefficient.

    The P-value statistic measures the portion of the linear correlation coefficient values of images with 1 randomly scrambled channel whose values are less than the linear correlation coefficient value of the unscrambled image. 200 randomizations are performed resulting in a fairly accurate significance test with a maximum P-value of 0.995. A P-value of 0.95 or more is somewhat arbitrarily used to indicate the existence of true colocalization. The P-value option was not found to be useful and is currently disabled.

    Pixel intensity values are spatially correlated because of the point spread function. Therefore, the number of independent samples in an image is not the number of pixels in the image but rather the number of objects the size of a point spread function that will fit into the image. A normalized autocovariance is calculated for each channel(although much of the medical literature erroneously calls it an autocorrelation). The channel whose autocovariance is smallest is divided up into squares or cubes with sides equal to the full width at half maximum of the smallest autocovariance. These squares or cubes are randomly placed in forming 200 randomly colocalized images.

    Use linear least squares to calculate the best line fit for secondBuffer = a*firstBuffer + b. Use an orthogonal line fit where the minimized distance measurements are orthgonal to the proposed line. This is an orthogonal regression as opposed to a traditional direct regression of dependent y variable green on independent red variable x which would minimize the vertical distances between the points and the fitted line. An inverse regression of red on green would minimize the horizontal distances between the points and the fitted line. All 3 lines pass through the point (averagex, averagey), but the 3 lines only coincide if the correlation coefficient equals -1 or 1. Use of a direct regression only makes sense if one variable is dependent and one variable is independent. Since red and green dyes used in colocalization are best thought of as 2 independent variables, the orthogonal regression is most appropriate. Note that orthogonal regression is also called total least squares.

    In the first iteration points which have a dataless background in both images are excluded from the regression line calculations. If buffer[i]

    In the dialog the user can select to use points from the entire image or only points from the VOI region or only points allowed by a mask file. If VOI region is selected, then when a mouseReleased is performed on the VOI, the calculation is performed again. This allows the calculation to be performed with the same contour VOI in different positions. If the mask file radio button is selected, then the Choose mask file button will be enabled. When the Choose mask file button is pressed, a dialog for selecting a mask file will appear.

    The second iteration thresholding works the same as the first iteration thresholding except for the line determination. In the first line determination iteration points are only excluded if they are below both background1 and background2, but in the second iteration line determination points are excluded if they are below either latPositive1 or lastPositive2. (lastPositive1,lastPositive2) is the last point going from top to bottom on the first iteration regression line before a L shaped subthreshold region with a zero or negative linear correlation coefficient is found. In the second iteration the L shaped subthreshold region determined from the first iteration is excluded from the regression line calculations. The default is to not perform a second iteration. The second iteration thresholding is not applied to the linear correlation coefficients, % colocalization area, % first color colocalization, or the % second color colocalization. The second iteration thresholding is just used for line generation with exclusion of points in the L shaped region.

    The slope and offset of the orthogonal regression line can be obtained from the eigenvector of the smallest eigenvalue of the matrix: (count-1)*sample y variance -(count-1)*sample xy covariance -(count-1)*sample xy covariance (count-1)*sample x variance The eigenvector has the components (directionx, directiony), where the slope of the line equals = directiony/directionx offset = averagey - slope*averagex However, the method used here is to obtain the slope from the equation: slope = num/denom num = vary - varx + sqrt((vary - varx)*(vary - varx) + 4*covarxy*covarxy) denom = 2*covarxy Again offset = averagey - slope*averagex

    Let n be the normal vector to the orthogonal regression line and let theta be the angle from the x axis to the normal. theta = arctan(slope) n = averagex*cos(theta) + averagey*sin(theta) The minimized residue, the mean square error, is given by MSE = varx*cos(theta)*cos(theta) + covarxy*sin(2*theta) + vary*sin(theta)*sin(theta) = (varx + 2*slope*covarxy + slope*slope*vary)/(1 + slope*slope)

    To avoid including outliers in the regression line the intital regression line calculation may be iterated using only points whose distance from the line is is within +-2 times the square root of the mean square error. This will include 95% of the points. The iteration is performed until the fractional changes in the slope and offsets are

    Note that there are 2 different types of regression line iterations. The first is the 1 or 2 iterations with the first iteration excluding only points with both buffer[i]

    A histogram buffer is generated with bin1 counts along the x axis and bin2 counts along the y axis. bin1 and bin2 are user selectable in the dialog. leftPad, rightPad, bottomPad, and topPad spaces are left around the data area in histBuffer to allow room for axis lines and labels. For bin1 and bin2 in color images the default bin number = color max - color min + 1.

    Calculate the linear correlation coefficients for all pixels whose values are either below threshold in buffer or are below a*threshold + b in secondBuffer. The values in buffer range from min1 to max1 and in secondBuffer range from min2 to max2. Calculate along the color that has the greatest range along the line segment. The line segment's (color1,color2) point just above the point where the linear correlation coefficient becomes negative or zero is taken in a nonrigorous fashion as the threshold point separating colocalized data from noncolocalized data.

    Originally every point along the color that has the greatest range along the line segment was included in the calculation. However, the time required was unacceptable for large images. Only those points necessary to find the transition point from negative to positive correlation coefficient are calculated. This is approximately the log to the base 2 of the number of points along the greatest color range. First the midpoint is calculated. If the midpoint linear correlation coefficient is positive, then the 1/4 point is calculated. If the midpoint linear correlation coefficient is negative, then the 3/4 point is calculated. Each new line segment increment to a new point is 1/2 the size of the previous line segment increment. The process stops when it finds a point with a negative or undefined linear correlation coefficient followed by a point with a positive correlation coefficient. When the mouse is dragged along the line, the histogram frame header display only changes when the mouse passes over a point for which the correlation and colocalizations have been calculated. On a mouse release the correlation and colocalizations will be performed at that point if they have not already been done.

    Calculate the percent colocalization area, the percent red colocalization, and the percent green colocalization for each point along the correlation line. Each point along the correlation line has a red value = threshold and a green value = secondThreshold. Thus, each point defines an upper right rectanglular region characterized by red >= threshold and green >= secondThreshold. The percent colocalization area is given by 100 times the number of pixels belonging to the upper right rectangular region divided by the number of pixels in the entire image or the selected voi. The percent red colocalization is given by 100 times the sum of the red values in the upper right rectangular region divided by the sum of the red values in the image or the selected voi. The percent green colocalization is given by 100 times the sum of the green values in the upper right rectangular region divided by the sum of the green values in the image or the selected voi. Note that only pixels which equal or exceed at least 1 of the 2 user specified thresholds are included in any of the above sums.

    In the default option for a color colocalization all pixel values > background are included in the sum in the denominator. In a user selected option only pixels whose values are >= the threshold for the color being colocalized will be included in the denominator sum. For example, in the threshold only option red colocalization is given by 100 times the sum of the red values in the upper right rectangular region divided by the sum of the red values >= red threshold in the image or selected voi.

    Pressing the free region toggle button on the histogram frame allows the user to take the VOI point off the least squares fit line. These correlation and colocalization values are only calculated in response to a mouse release.

    There are 2 nonrigorous aspects associated with this algorithm. First, a single line is likely derived from at least 4 populations - (no color1, no color2), (no color1, color2), (color1, no color2), (color1, color2) to describe the characteristics of only the (color1, color2) population. Second, a more traditional statistical approach would use data within a fixed perpindicular distance from the line as being validly described by the line.

    The calculated data is passed to ViewJFrameColocalization. References: 1.) Protein-protein interaction quantified by microscopic co-localization in live cells by Sylvain V. Costes, Dirk Daelemans, Edward H. Cho, George Pavlakis, and Stephen Lockett

    2.) Dynamics of three-dimensional replication patterns during the S-phase, analysed by double labelling of DNA and confocal microscopy by E.M.M.Manders, J.Stap, G.J.Brakenhoff, R.Van Driel, and J.A.Aten, Journal of Cell Science, Vol 103, 1992, pp. 857-862.

    3.) Measurement of co-localization of objects in dual-colour confocal images by E.M.M.Manders, F.J.Verbeek, and J.A.Aten, Journal of Microscopy, Vol. 169, Pt. 3, March, 1993, pp. 375-382.

    5.) Equations for slope and offset of the orthogonal least squares problem from A Critical Examination of Orthogonal Regression and an application to tests of firm size interchangeability by Gishan Dissanaike and Shiyun Wang

    6.) Equations for slope and mean square error of the orthogonal least squares from Straight Line Extraction Using Iterative Total Least Squares Methods by Jan A. Van Mieghem, Hadar I. Avi-Itzhak, and Roger D. Melen, Journal of Visual Communication and Image Representation, Vol. 6, No. 1, March, 1995, pp. 59-68.

    • Field Detail

      • a

        private float a
        generated with randomly scrambled blocks of pixels having a linear correlation coefficient less than that of the actual image.
      • b

        private float b
        generated with randomly scrambled blocks of pixels having a linear correlation coefficient less than that of the actual image.
      • background1

        private float background1
        The minimum values that are considered as data values.
      • background2

        private float background2
        DOCUMENT ME!
      • backgroundIndex

        private int backgroundIndex
        DOCUMENT ME!
      • backgroundIndex2

        private int backgroundIndex2
        DOCUMENT ME!
      • baseImage

        private ModelImage baseImage
        DOCUMENT ME!
      • bin1

        private int bin1
        DOCUMENT ME!
      • bin2

        private int bin2
        DOCUMENT ME!
      • bottomPad

        private int bottomPad
        DOCUMENT ME!
      • buffer

        private float[] buffer
        DOCUMENT ME!
      • colocIntensity1

        private float[] colocIntensity1
        DOCUMENT ME!
      • colocIntensity2

        private float[] colocIntensity2
        DOCUMENT ME!
      • colocSize

        private float[] colocSize
        for all pixels with values either below color1 for buffer or below a*color1 + b for secondBuffer.
      • color

        private int color
        DOCUMENT ME!
      • cost

        private int cost
        DOCUMENT ME!
      • doColocWithThresholds

        private boolean doColocWithThresholds
        DOCUMENT ME!
      • doP

        private boolean doP
        DOCUMENT ME!
      • doSecondIteration

        private boolean doSecondIteration
        If true, do second iteration excluded subtrhesholded region from first iteration.
      • doVOISubtraction

        private boolean doVOISubtraction
      • entireImage

        private boolean entireImage
        DOCUMENT ME!
      • freeRangeColocIntensity1

        private float[] freeRangeColocIntensity1
        DOCUMENT ME!
      • freeRangeColocIntensity2

        private float[] freeRangeColocIntensity2
        DOCUMENT ME!
      • freeRangeColocSize

        private float[] freeRangeColocSize
        DOCUMENT ME!
      • freeRangeRThreshold

        private float[] freeRangeRThreshold
        The linear correlation coefficients for all pixels with values either below color1 for buffer or below color2 for secondBuffer.
      • haveFreeRangeThreshold

        private boolean[] haveFreeRangeThreshold
        If true, the freeRangeRThreshold value has been calculated.
      • haveThreshold

        private boolean[] haveThreshold
        DOCUMENT ME!
      • hsb

        private float[] hsb
        DOCUMENT ME!
      • hue

        private float hue
        DOCUMENT ME!
      • imageFrame

        private ViewJFrameImage imageFrame
        on the contour VOI occurs.
      • inputMask

        private java.util.BitSet inputMask
        DOCUMENT ME!
      • leftPad

        private int leftPad
        Space padding around the histogram data area.
      • lineMin1

        private double lineMin1
        DOCUMENT ME!
      • lineMin2

        private double lineMin2
        DOCUMENT ME!
      • maskSupplied

        private boolean maskSupplied
        DOCUMENT ME!
      • min1

        private double min1
        DOCUMENT ME!
      • min2

        private double min2
        DOCUMENT ME!
      • scale1

        private double scale1
        DOCUMENT ME!
      • scale2

        private double scale2
        DOCUMENT ME!
      • nVOIs

        private int nVOIs
        DOCUMENT ME!
      • point1

        private float point1
        DOCUMENT ME!
      • point2

        private float point2
        DOCUMENT ME!
      • pointCalculation

        private boolean pointCalculation
        If pointCalculation is true, go to free range mode and set location at point1, point2.
      • PValue

        private float PValue
        DOCUMENT ME!
      • r

        private float r
        DOCUMENT ME!
      • redo

        private boolean redo
        DOCUMENT ME!
      • regionIndex

        private int regionIndex
        DOCUMENT ME!
      • register

        private boolean register
        DOCUMENT ME!
      • registeredBaseImage

        private ModelImage registeredBaseImage
        DOCUMENT ME!
      • registeredSrcImage

        private ModelImage registeredSrcImage
        DOCUMENT ME!
      • rightPad

        private int rightPad
        DOCUMENT ME!
      • rThreshold

        private float[] rThreshold
        fitted line to secondBuffer = a*buffer + b;.
      • secondBuffer

        private float[] secondBuffer
        DOCUMENT ME!
      • secondColor

        private int secondColor
        DOCUMENT ME!
      • shortMask

        private short[] shortMask
        DOCUMENT ME!
      • subtractedBaseImage

        private ModelImage subtractedBaseImage
        DOCUMENT ME!
      • subtractedSrcImage

        private ModelImage subtractedSrcImage
        DOCUMENT ME!
      • subtractionMask

        private short[] subtractionMask
        DOCUMENT ME!
      • subtractionMask2

        private short[] subtractionMask2
        DOCUMENT ME!
      • t1

        private float t1
        thresholds used in linear correlation calculations if doSecondIteration is true.
      • t2

        private float t2
        thresholds used in linear correlation calculations if doSecondIteration is true.
      • thirdColor

        private int thirdColor
        DOCUMENT ME!
      • thresholdOn1

        private boolean thresholdOn1
        DOCUMENT ME!
      • thrLength

        private int thrLength
        DOCUMENT ME!
      • topPad

        private int topPad
        DOCUMENT ME!
      • useBlue

        private boolean useBlue
        DOCUMENT ME!
      • useGreen

        private boolean useGreen
        DOCUMENT ME!
      • useRed

        private boolean useRed
        DOCUMENT ME!
      • voiIntensity1

        private float voiIntensity1
        DOCUMENT ME!
      • voiIntensity2

        private float voiIntensity2
        DOCUMENT ME!
      • voiSize

        private int voiSize
        DOCUMENT ME!
    • Constructor Detail

      • AlgorithmColocalizationRegression

        public AlgorithmColocalizationRegression​(ModelImage destImg,
                                                 ModelImage srcImg,
                                                 ModelImage baseImage,
                                                 java.util.BitSet mask,
                                                 int bin1,
                                                 int bin2,
                                                 float background1,
                                                 float background2,
                                                 int leftPad,
                                                 int rightPad,
                                                 int bottomPad,
                                                 int topPad,
                                                 boolean doColocWithThresholds,
                                                 boolean entireImage,
                                                 boolean register,
                                                 int cost,
                                                 boolean doSecondIteration,
                                                 boolean doVOISubtraction,
                                                 boolean pointCalculation,
                                                 float point1,
                                                 float point2)
        Constructor for images in which 2D histogram is placed in a predetermined destination image. Used for 2 black and white images
        Parameters:
        destImg - image model where result image is to stored
        srcImg - image for x axis of histogram
        baseImage - image for y axis of histogram
        mask - mask for image - use is optional
        bin1 - histogram x axis bin number
        bin2 - histogram y axis bin number
        background1 - minimum value for data in sourceImage
        background2 - minimum value for data in baseImage
        leftPad - space to the left of the histogram bin area
        rightPad - space to the right of the histogram bin area
        bottomPad - space to the bottom of the histogram bin area
        topPad - space to the top of the histogram bin area
        doColocWithThresholds - If true, calculate colocalization only using pixels >= threshold
        entireImage - If false, only use data from VOI region
        register - If true register 2 black and white images before colocalization
        cost - Cost function used in registration
        doSecondIteration - If true, do second iteration excluding subthresholded region from first iteration
        doVOISubtraction - If true, create a new image with the average VOI background level subtracted out
        pointCalculation - If true, go to free range mode and set position at point1, point2
        point1 - DOCUMENT ME!
        point2 - DOCUMENT ME!
      • AlgorithmColocalizationRegression

        public AlgorithmColocalizationRegression​(ModelImage destImg,
                                                 ModelImage srcImg,
                                                 java.util.BitSet mask,
                                                 int bin1,
                                                 int bin2,
                                                 float background1,
                                                 float background2,
                                                 int leftPad,
                                                 int rightPad,
                                                 int bottomPad,
                                                 int topPad,
                                                 boolean useRed,
                                                 boolean useGreen,
                                                 boolean useBlue,
                                                 boolean doColocWithThresholds,
                                                 boolean entireImage,
                                                 boolean register,
                                                 int cost,
                                                 boolean doSecondIteration,
                                                 boolean doVOISubtraction,
                                                 boolean pointCalculation,
                                                 float point1,
                                                 float point2)
        Constructor for images in which 2D histogram is placed in a predetermined destination image. Used for 1 color image.
        Parameters:
        destImg - image model where result image is to stored
        srcImg - source image model
        mask - mask for image - use optional
        bin1 - histogram x axis bin number
        bin2 - histogram y axis bin number
        background1 - minimum data value for first color
        background2 - minimum data value for second color
        leftPad - space to the left of the histogram bin area
        rightPad - space to the right of the histogram bin area
        bottomPad - space to the bottom of the histogram bin area
        topPad - space to the top of the histogram bin area
        useRed - DOCUMENT ME!
        useGreen - DOCUMENT ME!
        useBlue - DOCUMENT ME!
        doColocWithThresholds - If true, calculate colocalization only using pixels >= threshold
        entireImage - If false, use only data from VOI region
        register - If true, register 2 colors before colocalization
        cost - Cost function used in registration
        doSecondIteration - If true, do second iteration excluding subthresholded region from first iteration
        doVOISubtraction - If true, create a new image with the average VOI background level subtracted out
        pointCalculation - If true, go to free range mode and set position at point1, point2
        point1 - DOCUMENT ME!
        point2 - DOCUMENT ME!
    • Method Detail

      • calc2DBWStats

        public void calc2DBWStats()
        DOCUMENT ME!
      • calc2DColorStats

        public void calc2DColorStats()
        DOCUMENT ME!
      • calculateFreeRangeThreshold

        public void calculateFreeRangeThreshold​(int ch1,
                                                int ch2)
        DOCUMENT ME!
        Parameters:
        ch1 - the bin1 channel used
        ch2 - the bin2 channel used
      • calculateThreshold

        public void calculateThreshold​(int thresholdIndex)
        DOCUMENT ME!
        Parameters:
        thresholdIndex - the index along the line segment
      • createFreeRangeArrays

        public void createFreeRangeArrays()
        DOCUMENT ME!
      • finalize

        public void finalize()
        Prepares this class for destruction.
        Overrides:
        finalize in class AlgorithmBase
      • removeVOIUpdateListener

        public void removeVOIUpdateListener()
        DOCUMENT ME!
      • selectionChanged

        public void selectionChanged​(UpdateVOIEvent newVOIselection)
        responds to the volume of interest (VOI) change events.

        This method calls updateVOI using the UpdateVOIEvent changed VOI, and retrieves the runningInSeparateThread out of the current image's frame.

        Specified by:
        selectionChanged in interface UpdateVOISelectionListener
        Parameters:
        newVOIselection - DOCUMENT ME!
        See Also:
        UpdateVOIEvent, #updateVOI, ViewJFrameBase#getActiveImage
      • updateFileInfo

        public void updateFileInfo​(ModelImage image,
                                   ModelImage resultImage)
        Copy important file information to resultant image structure.
        Parameters:
        image - Source image.
        resultImage - Resultant image.
      • calc2D

        private void calc2D()
        This function produces a 2D histogram image with srcImage values represented across the x axis and baseImage values represented across the y axis. The total least squares line and a matrix of correlation coefficients for L shaped subthreshold regions are also generated.
      • calc3D

        private void calc3D()
        This function produces a 2D histogram image with srcImage values represented across the x axis and baseImage values represented across the y axis. The total least squares line and a matrix of correlation coefficients for L shaped subthreshold regions are also generated.
      • calcColor2D

        private void calcColor2D()
        This function produces a 2D histogram image with first color values represented across the x axis and second color values represented across the y axis. The total least squares line and a matrix of correlation coefficients for L shaped subthreshold regions are also generated.
      • calcColor3D

        private void calcColor3D()
        This function produces a 2D histogram image with first color values represented across the x axis and second color values represented across the y axis. The total least squares line and a matrix of correlation coefficients for L shaped subthreshold regions are also generated.