Biomod/2011/HKBU/NBgamers:Programming

From OpenWetWare

Jump to: navigation, search

Home Mission Project Results Video Team Resources
NBgamers (Team of NanoBiotechnology)
 

Programming

Contents

  1. Intensity Measurement

Intensity Measurement

When our sensor detects the DNA target, the fluorescence signal from YOYO will be dramatically enhanced. The intensity measured from the signal emitted by YOYO is propotional to the concentration of the DNA target. Measuring the fluorescence signal intensity is crucial. Hence, we developed an computer algorithm to measure the intensity of the fluorescence signal from the caputured image.

The intensity of the signal is refected on each pixel of the image in a grayscale of 16-bit, i.e. 0~65535. To measure the intensity of the fibrils, we use two images: One for fibril location identification, and one for intensity measurement. The two images are captured at the same place (they capture the same fibrils), but at different signal wavelengnths (one from quantum dots, and one from YOYO):

Compare: fluorescence signal from QD and fluorescence signal from YOYO (Clikc to enlarge.)

Quantum dots' fluorescence signal is used for identifying the location of each fibril, while the signal from YOYO is the one we are interested for intensity measurement (we may be also interested in measuring the intensity from QD signal, then we simply relpace the image of YOYO by the image of QD). Then, we can take the grayscale value on the fibrils and get the absolute intensity per pixel for each fibril. However, the absolute intensity may not reflect the real situation very well. Because the incidence laser beam may not shine the sample uniformly. What we are more interested in is the relative intensity. By relative, we mean the intensity difference between the fibril and the nearby background.

Programming code:

% I_ref is the image for identifying fibril location
% I_int is the image for intensity measurement
function intensity_measurement(I_ref, I_int)

% Load original images
I_ref_origin = imread(I_ref);
I_int_origin = imread(I_int);
figure(1); imshow(I_ref_origin);
figure(2); imshow(I_int_origin);

% Binarize the reference original image
level = (mean2(I_ref_origin) + 2*std2(I_ref_origin)) / 65535;
I_ref_binary = im2bw(I_ref_origin, level);
figure(3); imshow(I_ref_binary);

% Label connected components in the reference binary image
[L_b, num_b] = bwlabel(I_ref_binary, 8);

% Get information of each individual connected component
for i = 1:num_b
    [row, column] = find(L_b == i);
    most_left_b(i) = min(column);
    most_right_b(i) = max(column);
    most_up_b(i) = min(row);
    most_down_b(i) = max(row);
    width_b(i) = most_right_b(i) - most_left_b(i) + 1;
    height_b(i) = most_down_b(i) - most_up_b(i) + 1;
    area_b(i) = length(row);
end

% Eliminate dots
for i = 1:num_b
    if(width_b(i) < 2) & (height_b(i) < 2)
        [row_b, column_b] = find(L_b == i);
        for j = 1:length(row_b)
            L_b(row_b(j), column_b(j)) = 0;
        end
    end
end

% Reference treated image
I_ref_treated = mat2gray(L_b, [0, 1]);
figure(4); imshow(I_ref_treated);

% Label connected components in the reference treated image
[L_t, num_t] = bwlabel(I_ref_treated, 8);

% Get information of each individual connected component
for i = 1:num_t
    [row, column] = find(L_t == i);
    most_left_t(i) = min(column);
    most_right_t(i) = max(column);
    most_up_t(i) = min(row);
    most_down_t(i) = max(row);
    width_t(i) = most_right_t(i) - most_left_t(i) + 1;
    height_t(i) = most_down_t(i) - most_up_t(i) + 1;
    area_t(i) = length(row);
end

% Compute absolute intensity
for i = 1:num_t
    intensity_abs(i) = 0;
    [row, column] = find(L_t == i);
    for j = 1:length(row)
        intensity_abs(i) = intensity_abs(i) + int32(I_int_origin(row(j), column(j)));
    end
    intensity_abs(i) = intensity_abs(i)/length(row);
end

% Compute background intensity
[im_row, im_column] = size(I_ref_binary);
for i = 1:num_t
    intensity_bg(i) = 0;
    bg_pixel_num(i) = 0;
    % Region of interest
    for j = (most_up_t(i)-50):(most_down_t(i)+50)
        for k = (most_left_t(i)-50):(most_right_t(i)+50)
            % Check if (j, k) is a qualified background pixel (Within 3*3 grid, no shining point)
            signal = 0;
            if (j >= 1) & (j <= im_row) & (k >= 1) & (k <= im_column)
                for m = -2:2
                    for n = -2:2
                        if (j+m >= 1) & (j+m <= im_row) & (k+n >= 1) & (k+n <= im_column)
                            if I_ref_binary(j+m, k+n) == 1
                                signal = 1;
                            end
                        end
                    end
                end
            else
                signal = -1;
            end
            
            % (j, k) is qualified
            if signal == 0
                intensity_bg(i) = intensity_bg(i) + int32(I_int_origin(j, k));
                bg_pixel_num(i) = bg_pixel_num(i) + 1;
            end
        end
    end
    
    intensity_bg(i) = intensity_bg(i)/bg_pixel_num(i);
end

% Compute relative intensity
intensity_rel = intensity_abs - intensity_bg;

% Compute average
intensity_abs_avg = sum(intensity_abs.*area_t)/sum(area_t);
intensity_bg_avg = sum(intensity_bg.*bg_pixel_num)/sum(bg_pixel_num);
intensity_rel_avg = sum(intensity_rel.*area_t)/sum(area_t);

% Create data file
fp = fopen(strcat('intensity_', I_int, '.dat'), 'w');
    
for i = 1:num_t
    fprintf(fp, '%f %f %f\r\n', intensity_abs(i), intensity_bg(i), intensity_rel(i));
end
fprintf(fp, '\r\n%f %f %f\r\n', intensity_abs_avg, intensity_bg_avg, intensity_rel_avg);

% Close the file
fclose(fp);

Personal tools