-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCAMind.m
83 lines (73 loc) · 1.76 KB
/
CAMind.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
function IND = CAMind(im,CAM,Threshold,Dmat,FIG)
if nargin <3
Threshold=0.5;
Dmat = 'R';
FIG=0;
elseif nargin <4
Dmat = 'R';
FIG=0;
elseif nargin <5
FIG=0;
end
imSize = size(im);
CAM = imresize(CAM,imSize(1:2));
CAM = normalizeImage(CAM);
CAM(CAM<0.2) = 0;
cmap = jet(255).*linspace(0,1,255)';
CAM = ind2rgb(uint8(CAM*255),cmap)*255;
combinedImage = double(rgb2gray(im))/2 + CAM;
combinedImage = normalizeImage(combinedImage)*255;
if strcmp('r',lower(Dmat))==1
H=combinedImage(:,:,1); %let it do for 'R' or Red
DmatStr='Red';
elseif strcmp('g',lower(Dmat))==1
H=combinedImage(:,:,2); %let it do for 'G' or Green
DmatStr='Green';
elseif strcmp('b',lower(Dmat))==1
H=combinedImage(:,:,3); %let it do for 'B' or Blue
DmatStr='Blue';
else
disp('Error: 2Dmat not defined, use string R, G or B');
end
%## Find which pixels are expressed #### (by Alok)
% H=combinedImage(:,:,1); %let it do for 'R' only
R=H/255;
% to fix the genes selected, added on 17-Feb-2022
% if Parm.AutoSelectGenes==1
% Th=0.5;
% ThNew=Th;
% nIter=1000;
% for j=1:nIter
% [rowj,colj]=ind2sub(size(R),find(R>Th));
% if size(rowj,1)<Parm.DesiredGenes
% ThNew=Th;
% break;
% end
% Th=0.5+j/(2*nIter);
% end
% row=rowj;
% col=colj;
% clear rowj colj
%##########################################
%else
[row,col]=ind2sub(size(R),find(R>Threshold));
%end
if FIG==1
figure; imshow(R);
title(['2D matrix used is ',DmatStr]);
end
IND=sub2ind(size(R),row,col);
if FIG==1
B=ones(size(R));
B(IND)=R(IND);
figure;
subplot(1,2,1); imshow(B);
title('Area by activation')
C=uint8(ones(size(R))*255);
im2=im(:,:,1);
C(IND)=im2(IND);
subplot(1,2,2); imshow(C)
title('Genes selected')
end
%##################################################
end