Welcome to the web page 
of Peter Nagy

Quantification of metachromasia

Evaluation of metachromasia is based on the color of a pixel or an area. In a typical microscpic image of a sample stained with a metachromatic dye, the observed colors range between gray and purple, and the more purple a pixel is, the more metachromasia it displays. Therefore, quantitative analysis of metachromasia is based on determining how close the color of a certain pixel is to the most purple color. This imaginary distance will have to be normalized, and the RGB cube presents a useful tool for achieving this aim. 

In the RGB color model, each color is represented by a number triplet characterizing the intensity of Red, Green and Blue colors. The range of these numbers is 0-255.

Since pure red, green and blue contain only red, green or blue intensities, they are represented by [255, 0, 0], [0, 255, 0] and [0, 0, 255], respectively. Black is the complete absence of any of these base colors, while white contains full intensities of each of them. An arbitrary color can be generated by additively mixing the base colors, e.g., yellow is the additive mixture of red and green. For metachromasia, the two most important colors are gray and purple. Gray is an equal mixture of red, green and blue, and its shade is determined by how much of each color is added. Purple, on the other hand, is a mixture of red and blue. 
Since the three colors can be thought of as the three spatial dimensons, their intensities can be plotted on the X, Y and Z axes. Consequently, each color can be represented in the RGB cube shown on the left.

For the calculation of metachromasia indices, the user has to pick two colors in the metachromatic images (see the figure on the left):

  • The most purple pixel corresponding to the most metachromatic area in a certain experiment.
  • The gray color of the background.

The first index is defined according to the following equation:

Since the main diagonal of the cube is 

and the distance between the color of a pixel of interest and the most purple pixel in the RGB cube is  d , index1 characterizes how close the color of a certain pixel is to the most metachromatic color relative to the largest possible distance in the RGB cube.
The second index is defined according to the following equation:

where dmax is the distance between the gray background and the most metachromatic color in the RGB cube. Therefore, this index expresses how close the color of a certain pixel is to the most purple color normalized to the distance between the most gray and the most purple pixels in the RGB cube.
The third index is calculated according to the following equation:

This parameter characterizes the distance between the color of the most purple area and the projection of the color of the pixel of interest on the line connecting the most gray and the most purple colors (d1). In other words, the thick blue line in the figure on the left represents a continuous transition between the most gray and the most purple colors in a certain experiment in the RGB space. The third index characterizes how much the color of a certain pixel resembles the color of the most purple area in the continuum of colors between the most gray and the most purple.

Installation of the program

There are two options for running the program:

  1. If you have MATLAB installed on your computer, download the metachromasiaIndex.m file, and run it from the command prompt by typing "metachromasiaIndex". You may need to place to file in folder on the MATLAB path, or you have to navigate within MATLAB to the folder where the program was saved.
  2. If you don't have MATLAB installed on your computer, you have to install the MATLAB runtime environment from this page:
    https://www.mathworks.com/products/compiler/matlab-runtime.html
    The MATLAB runtime environment is free, and it can run EXE files compiled in MATLAB on computers not having MATLAB installed. 
    Choose the Windows, Linux or Mac version of R2022a.
    After installing the MATLAB runtime environment, download and unzip the following compressed file:
    https://peternagyweb.hu/Matlab/Metachromasia/metachromasiaIndex_EXE.zip
    Double click the file "
    metachromasiaIndex.exe" to run the program.
Using the program

Use of the program is demonstrated in figure A above:

  1. Click on Open image, and select the image you would like to analyze.
  2. Circumsribe the area you would like to evalute. This area is your region of interest (ROI). Instructions on how to do it appear in the light blue field in the upper right corner. You can draw regions of interest of three different kinds of shape:
    - Polygon: click on vertices of the polygon. Finish the polygon by a double-click.
    - Square: hold down the SHIFT key, click on a vertex of the square, and drag the mouse.
    - Rectangle: hold down the CTRL key, click on a vertex of the rectangle, and drag the mouse.
    Right-click on a corner of the ROI to delete it.
    Click on the corner of a ROI to move the selected corner.
    Quit the ROI drawing cycle by a double-click. You can make sure that you have quit the ROI drawing cycle by checking that the light blue instruction area becomes empty. If you draw multiple ROIs, their union constitutes the evaluated part of the image. An example ROI is shown in figure B above.
  3. Click on the Pick purple and Pick gray buttons, and click a maximally purple (metachromatic) and gray (background) area in the image. Their RGB values will be shown in the text boxes above. You can also manually define the most purple and gray areas by entering RGB values in the text boxes. The color is shown in the box right of the numerical values. When evaluating the images of an experiment, it makes sense to define the most purple color using the image having the most purple color according to visual inspection. The same holds for defining the gray background. Otherwise, negative metachromasia indices may be calculated.
  4. Click on calculate, and the metachromasia indices will be evaluated in the defined ROI. Three images will be shown corresponding to the pixelwise values of the three different metachromasia indices. Such a gray-scale image is shown in figure C above. A histogram of the distribution of the three different kinds of indices is generated. The default number of histogram bins is 100, which can be modified by entering a different value into the "# of bins" text box. The means will also be calculated and displayed in the area marked by the red box. The mean of each metachromasia index is calculated in two different ways. (1) The mean red, green and blue intensities are calculated for the ROI, and this RGB triplet will be used for calculating the indices (Index from mean colors). (2) The metachromasia indices are calculated for every pixel in the ROI, and the mean of these individual values is calculated (Pixelwise mean).
  5. Copy to clipboard: the six mean metachromasia indices displayed in the red rectangle are copied to the clipboard.
  6. Save results: images containing the pixelwise values of the three different metachromasia indices are saved in three different files. You have to specify the file name in a dialog box, and the names are appended by "_1", "_2" and "_3" corresponding to the three indices in the three files. The images can be saved as JPG or TIFF. Furthermore, the histograms are also saved in a comma-delimited text file with the same name as the images.