Quantifying Charcoal in Microscope Images Using MATLAB, Part 1

Quantifying the composition of substances in geosciences, such as the mineral composition of a rock in thin sections, or the amount of charcoal in sieved sediment samples, is facilitated by the use of image processing methods. Thresholding provides a simple solution to segmenting objects within an image that have different coloration or grayscale values. As an example we use thresholding to separate the dark charcoal particles and count the pixels of these particles after segmentation.

The script provided here is a modified version of the one of Chapter 8.11 of MRES to quantify charcoal in samples from the Suguta Valley, northern Kenya Rift. Anne Papenfuss, co-advised by Annett Junginger (U Tübingen) and myself during her bachelors project, processed the sample to isolated particles in the microscope. In contrast to the example explained in MRES we took two photos of each sample, with transmitted and with reflected light.

The analysis of both photos in the following MATLAB script combines the advantage of both microcope images. The photo taken with transmitted light shows a white background, which can easily be distinguished from the grains. The reflected light photo, on the other hand, shows clear colors for distinguishing different materials. We read the two images image from the zipped archive charcoal_images.zip :

I1 = imread('charcoal_1.tif');
imshow(I1), axis off

I2 = imread('charcoal_2.tif');
imshow(I2), axis off

Then we decompose images into three channels

I1A = I1(:,:,1); I1B = I1(:,:,2); I1C = I1(:,:,3);
I2A = I2(:,:,1); I2B = I2(:,:,2); I2C = I2(:,:,3);

Then we weplace all values >240 by 255 (true white)

I1A(I1A > 240) = 255;
I1B(I1B > 240) = 255;
I1C(I1C > 240) = 255;

Next we concatenate the images to create a single RGB image

I1N = cat(3,I1A,I1B,I1C);
imshow(I1N), axis off

Then we use the white background of the first image (taken with transmitted light) to eliminate the background in the second image (taken with reflected light).

I2A(I1A==255) = 255;
I2B(I1B==255) = 255;
I2C(I1C==255) = 255;

Then we concatenate the images again.

I2N = cat(3,I2A,I2B,I2C);
imshow(I2N), axis off

The RGB color image is converted to a grayscale image.

I3 = rgb2gray(I2N);
imshow(I3), axis off

The function im2bw converts an image to a binary image by thresholding. If the threshold is 1.0 the image is all black corresponding to the pixel value of 0. If the threshold is 0.0 the image is all white equivalent to a pixel value of 1. We manually change the threshold value until we get a reasonable result. In our example, a threshold of 0.03 gives good results to locate charcoal fragments.

I4 = im2bw(I3,0.305);

Then we use a threshold of 0.95 to count all objects.

I5 = im2bw(I3,0.95);

Finally we calculate the percent charcoal, which is about 1.7% in our example.

100 * sum(sum(I4==0))/sum(sum(I5==0))