Home > detect > WBCdetect.m

WBCdetect

PURPOSE ^

SYNOPSIS ^

function WBCdetect(iFolder,bg,amask,bloodFlowDir,thresh_rm,thresh_temp_diff)

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function WBCdetect(iFolder,bg,amask,bloodFlowDir,thresh_rm,thresh_temp_diff)
0002 if (nargin ==1)
0003     bg = imread('BG.png');
0004     amask = imread('amask.png');
0005     load _bloodFlowDir;
0006     load _detectionParameters;
0007 end
0008 
0009 cd(strcat(path,iFolder,'/MN'));
0010 iFiles = dir('*.mn.png');
0011 
0012 % numFile = length(iFiles);
0013 numFile = 1;
0014 % date = datestr(now,'mm-dd-HH.MM.SS');
0015 % mkdir(strcat('../DT/', date));
0016 mkdir('../DT');
0017 
0018 %% THRESHOLD INPUT
0019 % thresh_rm = .365;
0020 thresh_i  = 50;
0021 % thresh_temp_diff = 75;
0022 k = 21;
0023 tArea = 30;
0024 %% INITIALIZATION %%
0025 kh = floor(k/2);
0026 k2 = 2*k-1;
0027 kh2= floor(k2/2);
0028 rm_layer = 2; % number layer of radial kernel
0029 
0030 % create filter kernels
0031 [rm_k] = create_radial_mean_kernel(k,rm_layer);
0032 % compute 3 pixels region and its total number of pixels
0033 reg1 = rm_k == 0;
0034 reg2 = (rm_k == 1);
0035 reg3 = (rm_k == 2);
0036 sum_pix1 = sum(reg1(:));
0037 sum_pix2 = sum(reg2(:));
0038 sum_pix3 = sum(reg3(:));
0039 
0040 %% ITERATE EACH IMAGE FRAME
0041 for frameID = 1:numFile
0042     % read the image and create a 3 layer version of that image
0043     im = imread (iFiles(frameID).name);
0044     % noise reduction technique
0045     im = medfilt2(im, [5 5]);
0046     imRGB = gray_to_rgb(im);
0047     [R, C] = size ( im );
0048 
0049     %initialize the list of detected coordinates. (n X 2)
0050     list= zeros(0,2);
0051 
0052     %     bg = im;
0053     %     mask = zeros(size(bg));
0054 
0055     im_subtract = imsubtract(im, bg);
0056     im_subtract = medfilt2(im_subtract);
0057     disp(['Frame: ' num2str(frameID)]);
0058     %% FOR EACH IMAGE
0059     for r = kh2+1:(R-kh2-1)
0060 
0061         % for each col
0062         for c = kh2+1:(C-kh2-1)
0063             if (amask(r,c)==0)
0064                 % crop the image within [sr0:sr1, sc0:sc1]
0065                 r0 = max ( 1, r-kh );
0066                 c0 = max ( 1, c-kh );
0067                 r1 = min ( R, r+kh );
0068                 c1 = min ( C, c+kh );
0069 
0070                 im_sub = im ( r0:r1, c0:c1 );
0071 
0072                 % compute radial mean
0073                 radial_mean1 = sum(im_sub(reg1(:))) / sum_pix1;
0074                 radial_mean2 = sum(im_sub(reg2(:))) / sum_pix2;
0075                 radial_mean3 = sum(im_sub(reg3(:))) / sum_pix3;
0076                 %normalized
0077                 radial_mean = radial_mean1 / ...
0078                     (radial_mean1 + radial_mean2+ radial_mean3);
0079 
0080                 % Thresholding
0081                 if (radial_mean > thresh_rm) ...
0082                         && (im(r,c)> thresh_i) ...
0083                         || (im_subtract(r,c) > thresh_temp_diff)
0084                     %             imRGB(r-1,c-1,:)= [255 0 0];
0085                     %             imRGB(r-1,c,:)= [255 0 0];
0086                     %             imRGB(r,c-1,:)= [255 0 0];
0087                     imRGB(r,c,:)= [255 0 0];
0088                     list = [list; r c];
0089                 end 
0090             end
0091         end
0092 
0093         postfix = iFiles(frameID).name(1:end-7);
0094         imOut = ['../DT/',postfix,'.dt.png'];
0095         imwrite ( imRGB, imOut );
0096     end
0097 end

Generated on Thu 17-Mar-2011 14:45:51 by m2html © 2005