Difference between revisions of "Team:Oxford/Measurement"

Line 31: Line 31:
 
                 <div id="find-collapse" class="panel-collapse collapse" role="tabpanel" aria-labelledby="find">
 
                 <div id="find-collapse" class="panel-collapse collapse" role="tabpanel" aria-labelledby="find">
 
                     <div class="panel-body">
 
                     <div class="panel-body">
 
+
<img class="img-responsive" src="https://static.igem.org/mediawiki/2017/1/1b/T--oxford--measurement--matlabcode.jpeg">
 
<p>imgname = ''; %input image name between quotes(e.g. 'img_name.tif')
 
<p>imgname = ''; %input image name between quotes(e.g. 'img_name.tif')
  

Revision as of 03:39, 2 November 2017

Measurement


We have developed a lightweight, user-friendly MatLab tool that is able to extract relative quantitative data from microscopy images. Current systems include software such as ImageJ which although more comprehensive, require further training for effective use. Specifically, most software suites only focus on cell segmentation in phase contrast images, with very little support for differential interference contrast (DIC) images. We have developed a MATLAB tool that can quickly and automatically pick out cells in a DIC image. We have tested this system with our microscopy data, and has saved us a large amount of time in data analysis.



imgname = ''; %input image name between quotes(e.g. 'img_name.tif') A = imread(imgname); fprintf('------ Image: %s ------\n', imgname); x_size = size(A,2); y_size = size(A,1); A = A * 30; phase = A(:,:,3); data = A(:,:,2); s_test = 0.52:0.005:0.575; results = zeros(1,length(s_test)); figure; for n = -1%[1:length(s_test) -1] if n ~= -1 s = s_test(n); else s = 0.55;%input('Enter best sensitivity: '); end a_thresh = adaptthresh(phase,s); cells = imbinarize(phase, a_thresh); cells = imerode(cells, strel('disk',2,4)); cells = imdilate(cells, strel('disk',6,8)); nw_line = zeros(5,5); nw_line(3,3) = 1; nw_line(4,4) = 1; nw_line( cells = conv2(cells, Remove extremely bright spots cells(data > 3000) = 0; Remove small "cells" cells = bwareaopen(cells,500); cells_red = zeros(y_size,x_size,3); cells_red(:,:,1) = cells; [gx, gy] = gradient(single(phase)); gmax = max(max(gx(:)),max(gy(:))); gmag = sqrt(gx.^2 + gy.^2); gmask = (gmag/gmax) > 0.05; gmask = bwareaopen(gmask, 800); gmask = imclose(gmask,strel('disk',5)); gmask = imerode(gmask,strel('disk',5)); gmask = imdilate(gmask,strel('disk',3)); gmask = imerode(gmask,strel('disk',10)); gmask = imdilate(gmask,strel('disk',10)); gmask = bwareaopen(gmask, 1000); gmask(data > 3000) = 0; gmask_green = zeros(y_size,x_size,3); gmask_green(:,:,2) = gmask; if n ~= -1 subplot(3,4,n); hold on; imagesc(phase); image('CData', cells_red, 'AlphaData', cells*0.3); axis ij; axis tight; title(sprintf('s = %5.3f', s)); colormap gray; end; end; clf; Auto-alignment didn't really work combined = logical(cells); crr_full = xcorr2(single(data), single(combined)); crr = crr_full(((1:y_size) + floor(y_size/2)), ((1:x_size) + floor(x_size/2))); [max_crr, max_crr_i] = max(crr(:)); [max_crr_y, max_crr_x] = ind2sub(size(crr),max_crr_i); x_offset = (max_crr_x) - (x_size/2); y_offset = (max_crr_y) - (y_size/2); x_sclip = (x_offset > 0) * abs(x_offset) + (x_offset <= 0); x_eclip = (x_offset < 0) * abs(x_offset) + (x_offset >= 0); y_sclip = (y_offset > 0) * abs(y_offset) + (y_offset <= 0); y_eclip = (y_offset < 0) * abs(y_offset) + (y_offset >= 0); mask_offset = zeros(y_size,x_size); mask_offset(y_sclip:(y_size-y_eclip),x_sclip:(x_size-x_eclip)) = ... combined(y_eclip:(y_size-y_sclip),x_eclip:(x_size-x_sclip)); mask_offset = combined; cells_green = zeros(y_size,x_size,3); cells_green(:,:,2) = cells_offset; cell_flr = mean(data(mask_offset == 1)); cell_flr_std = std(single(data(mask_offset == 1))); bg_flr = mean(data(mask_offset == 0)); bg_flr_std = std(single(data(mask_offset == 0))); fprintf('Cell Detection Sensitivity : %7.2f\n', s); fprintf('Automatic Mask Offset : (%+3d, %+3d)\n', x_offset, y_offset); fprintf('Cell Fluoresence : %7.2f +/- %7.2f\n', cell_flr, cell_flr_std); fprintf('Background Fluorescence : %7.2f +/- %7.2f\n', bg_flr, bg_flr_std); fprintf('Blank Adjusted Fluoresence : %7.2f +/- %7.2f\n', cell_flr - bg_flr, sqrt(cell_flr_std^2 + bg_flr_std^2)); hold on; subplot(3,2,[1 3]); imagesc(phase); image('CData', cells_red, 'AlphaData', cells*0.2); image('CData', gmask_green, 'AlphaData', gmask*0.2); axis ij; axis tight; title('Cells Image'); colormap gray; subplot(3,2,5); [cells_label, total_cells] = bwlabeln(cells); cell_area = zeros(1,total_cells); for c = 1:total_cells cell_area(c) = bwarea(cells_label == c); end histogram(cell_area,20,'EdgeColor','k','FaceColor','k'); title('"Cell" Size Histogram'); subplot(3,2,[2 4]); hold on; imagesc(data); image('CData', cells_red, 'AlphaData', cells*0.2); image('CData', gmask_green, 'AlphaData', gmask*0.2); axis ij; axis tight; title('Data Image'); set(gca, 'CLim', [800 1400]); colormap gray; subplot(3,2,6); hold on; histogram(data(logical((cells == 0) .* (gmask == 0))),50,'EdgeColor','k','FaceColor','k','Normalization','probability','BinLimits',[0 2000]); histogram(data(cells == 1),50,'EdgeColor','k','FaceColor','r','Normalization','probability','BinLimits',[0 2000]); histogram(data(gmask == 1),50,'EdgeColor','k','FaceColor','g','Normalization','probability','BinLimits',[0 2000]); histogram(data(logical((cells == 1) + (gmask == 1))),50,'EdgeColor','k','FaceColor','y','Normalization','probability','BinLimits',[0 2000]); title('Data Image Histogram'); colormap gray; subplot(3,3,[2 5]); hold on; imagesc(crr); plot([x_size/2 max_crr_x], [y_size/2 max_crr_y], 'r-'); axis ij; axis tight; title('2D Cross Correlation of Data with Cells Position'); colormap gray;