forked from warmflasha/CellTracker60X
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsapnaScript.m
executable file
·58 lines (53 loc) · 1.64 KB
/
sapnaScript.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
%% read file
ff=readAndorDirectory('.');
%nuc = andorMaxIntensity(ff,0,0,1);
fn=getAndorFileName(ff,9,0,0,0);
nuc = imread(fn);
nuc_o = nuc;
%% preprocess
global userParam;
userParam.gaussRadius = 1;
userParam.gaussSigma = 1;
userParam.small_rad = 3;
userParam.presubNucBackground = 1;
userParam.backdiskrad = 300;
nuc = imopen(nuc,strel('disk',userParam.small_rad)); % remove small bright stuff
nuc = smoothImage(nuc,userParam.gaussRadius,userParam.gaussSigma); %smooth
nuc =presubBackground_self(nuc);
%% Normalize image
diskrad = 100;
low_thresh = 500;
nuc(nuc < low_thresh)=0;
norm = imdilate(nuc,strel('disk',diskrad));
normed_img = im2double(nuc)./im2double(norm);
normed_img(isnan(normed_img))=0;
%% gradient image
hy = fspecial('sobel');
hx = hy';
Iy = imfilter(double(normed_img), hy, 'replicate');
Ix = imfilter(double(normed_img), hx, 'replicate');
gradmag = sqrt(Ix.^2 + Iy.^2);
%% circle find and display
%[cc, rr, met]=imfindcircles(gradmag,[20 40],'Method','TwoStage','Sensitivity',0.95);
[cc, rr, met]=imfindcircles(gradmag,[20 40],'Method','TwoStage','Sensitivity',0.95);
%throw out circles with nothing inside
cavg = zeros(length(rr),1);
for ii=1:length(rr)
[cavg(ii), mm]=averageImageInCircle(nuc,floor(cc(ii,:)),rr(ii));
end
badinds = cavg < 1000;
cc(badinds,:)=[]; rr(badinds,:)=[];
% convert circlees to cells (will merge close circles)
cen = circles2cells(cc,rr);
%% display results
figure;
imshow(nuc_o,[]);hold on; %plot(cen(:,1),cen(:,2),'r*');
title('Original Image with cells identified');
%
% figure;
% imshow(gradmag,[]);
% hold on;
% for ii=1:length(rr)
% drawcircle(cc(ii,:),rr(ii),'m');
% end
% title('gradient image with circles');