Biomod/2011/HKBU/NBgamers:Programming

From OpenWetWare
Jump to: navigation, search

<html>

<body>

<table border="0" align="center" width="100%" cellspacing="0">

<tr> <td bgcolor="#fcec00"> <table border="0" align="center" cellpadding="20" cellspacing="0"> <tr bgcolor="#fcec00">

 <td align="center" height="50">
 <a href="http://openwetware.org/wiki/Biomod/2011/HKBU/NBgamers" style="color:black; font-size:20px;" onmouseover="this.style.color='white';" onmouseout="this.style.color='black';">
 Home
 </a>
 </td>
 <td align="center" height="50">
 <a href="http://openwetware.org/wiki/Biomod/2011/HKBU/NBgamers:Mission" style="color:black; font-size:20px;" onmouseover="this.style.color='white';" onmouseout="this.style.color='black';">
 Mission
 </a>
 </td>
 <td align="center" height="50">
 <a href="http://openwetware.org/wiki/Biomod/2011/HKBU/NBgamers:Project" style="color:white; font-size:20px;" onmouseover="this.style.color='white';" onmouseout="this.style.color='white';">
 Project
 </a>
 </td>
 <td align="center" height="50">
 <a href="http://openwetware.org/wiki/Biomod/2011/HKBU/NBgamers:Results" style="color:black; font-size:20px;" onmouseover="this.style.color='white';" onmouseout="this.style.color='black';">
 Results
 </a>
 </td>
 <td align="center" height="50">
 <a href="http://openwetware.org/wiki/Biomod/2011/HKBU/NBgamers:Video" style="color:black; font-size:20px;" onmouseover="this.style.color='white';" onmouseout="this.style.color='black';">
 Video
 </a>
 </td>
 <td align="center" height="50">
 <a href="http://openwetware.org/wiki/Biomod/2011/HKBU/NBgamers:Team" style="color:black; font-size:20px;" onmouseover="this.style.color='white';" onmouseout="this.style.color='black';">
 Team
 </a>
 </td>
 <td align="center" height="50">
 <a href="http://openwetware.org/wiki/Biomod/2011/HKBU/NBgamers:Resources" style="color:black; font-size:20px;" onmouseover="this.style.color='white';" onmouseout="this.style.color='black';">
 Resources
 </a>
 </td>

</tr> </table> </td> </tr>

<tr> <td bgcolor="#fcec00" align="center"> <img src="http://openwetware.org/images/5/53/NBgamers_team_logo.png" width="453" height="143" alt="NBgamers (Team of NanoBiotechnology)" title="NBgamers (Team of NanoBiotechnology)"> </td> </tr>

<tr> <td bgcolor="#fcec00" height="50"> &nbsp; </td> </tr>

<tr> <td bgcolor="#232323" align="center"> <h3 align="center" style="color:white; font-size:20px;" >Programming</h3> </td> </tr>

<tr> <td bgcolor="#fcec00"> <table align="center" width="85%" cellpadding="20"> <td>

<h3>Contents</h3> <ol>

 <li><a href="#Intensity Measurement">Intensity Measurement</a></li>

</ol>

<h1><a name="Intensity Measurement">Intensity Measurement</a></h1> <p> 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. </p> <p> 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): </p> <p align="center"> <a href="http://openwetware.org/images/4/40/Compare_QD_YOYO.png"> <img src="http://openwetware.org/images/4/40/Compare_QD_YOYO.png" width="492" height="270" alt="Compare: fluorescence signal from QD and fluorescence signal from YOYO (Clikc to enlarge.)" title="Compare: fluorescence signal from QD and fluorescence signal from YOYO (Clikc to enlarge.)"> </a> </p> <p> 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. </p> <p>Programming code:</p> <pre> % 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); </pre> <br />

</td> </table> </td> </tr>

</td> </table>

</body>

</html>