forked from FernandoPalazuelos/Displasias
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprueba_clus2.m
57 lines (40 loc) · 1.16 KB
/
prueba_clus2.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
nr = 10;
nc = 50;
ng1 = 15;
ng2 = 20;
delta = 0.0;
nperms = 1000;
pthresh = 0.05;
conn = 4; % bwlabel connectivity
npermsclus = nperms;
A = rand(nr,nc,ng1);
B = rand(nr,nc,ng2) + delta;
AB = cat(3,A,B);
rA = reshape(A,nr*nc,ng1);
rB = reshape(B,nr*nc,ng2);
rAB = cat(2,rA,rB);
rDIFF = mean(rA,2) - mean(rB,2);
DIFF = reshape(rDIFF,[nr nc]);
permDIFF = zeros(nr*nc,nperms);
for perm = 1 : nperms
permutation = randperm(size(rAB,2));
idx1 = permutation(1:ng1);
idx2 = permutation(ng1+1:end);
% dividing into two samples
randomSample1 = rAB(:,idx1);
randomSample2 = rAB(:,idx2);
thisrandomdiff = mean(randomSample2,2) - mean(randomSample1,2);
permDIFF(:,perm) = thisrandomdiff;
end
rp = 1 - ( (sum(abs(permDIFF) < abs(repmat(rDIFF,1,nperms)),2)) ./ nperms );
p = reshape(rp,[nr nc]);
permDIFF2D = reshape(permDIFF,[nr nc perm]);
clustersizes = zeros(npermsclus,1);
for perm = 1 : npermsclus
CC = bwconncomp(abs(DIFF) > abs(permDIFF2D(:,:,perm)),conn);
numPixels = cellfun(@numel,CC.PixelIdxList);
[biggest,idx] = max(numPixels);
if isempty(biggest); biggest=0;end
clustersizes(perm) = biggest;
end
histogram(clustersizes);