annotate toolbox/PartitionOfImage.py @ 0:6bec4fef6b2e draft

"planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
author perssond
date Fri, 12 Mar 2021 00:17:29 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
1 import numpy as np
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
2 from toolbox.imtools import *
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
3 # from toolbox.ftools import *
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
4 # import sys
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
5
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
6 class PI2D:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
7 Image = None
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
8 PaddedImage = None
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
9 PatchSize = 128
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
10 Margin = 14
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
11 SubPatchSize = 100
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
12 PC = None # patch coordinates
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
13 NumPatches = 0
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
14 Output = None
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
15 Count = None
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
16 NR = None
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
17 NC = None
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
18 NRPI = None
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
19 NCPI = None
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
20 Mode = None
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
21 W = None
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
22
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
23 def setup(image,patchSize,margin,mode):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
24 PI2D.Image = image
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
25 PI2D.PatchSize = patchSize
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
26 PI2D.Margin = margin
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
27 subPatchSize = patchSize-2*margin
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
28 PI2D.SubPatchSize = subPatchSize
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
29
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
30 W = np.ones((patchSize,patchSize))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
31 W[[0,-1],:] = 0
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
32 W[:,[0,-1]] = 0
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
33 for i in range(1,2*margin):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
34 v = i/(2*margin)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
35 W[i,i:-i] = v
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
36 W[-i-1,i:-i] = v
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
37 W[i:-i,i] = v
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
38 W[i:-i,-i-1] = v
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
39 PI2D.W = W
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
40
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
41 if len(image.shape) == 2:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
42 nr,nc = image.shape
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
43 elif len(image.shape) == 3: # multi-channel image
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
44 nz,nr,nc = image.shape
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
45
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
46 PI2D.NR = nr
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
47 PI2D.NC = nc
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
48
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
49 npr = int(np.ceil(nr/subPatchSize)) # number of patch rows
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
50 npc = int(np.ceil(nc/subPatchSize)) # number of patch cols
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
51
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
52 nrpi = npr*subPatchSize+2*margin # number of rows in padded image
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
53 ncpi = npc*subPatchSize+2*margin # number of cols in padded image
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
54
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
55 PI2D.NRPI = nrpi
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
56 PI2D.NCPI = ncpi
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
57
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
58 if len(image.shape) == 2:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
59 PI2D.PaddedImage = np.zeros((nrpi,ncpi))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
60 PI2D.PaddedImage[margin:margin+nr,margin:margin+nc] = image
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
61 elif len(image.shape) == 3:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
62 PI2D.PaddedImage = np.zeros((nz,nrpi,ncpi))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
63 PI2D.PaddedImage[:,margin:margin+nr,margin:margin+nc] = image
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
64
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
65 PI2D.PC = [] # patch coordinates [r0,r1,c0,c1]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
66 for i in range(npr):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
67 r0 = i*subPatchSize
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
68 r1 = r0+patchSize
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
69 for j in range(npc):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
70 c0 = j*subPatchSize
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
71 c1 = c0+patchSize
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
72 PI2D.PC.append([r0,r1,c0,c1])
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
73
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
74 PI2D.NumPatches = len(PI2D.PC)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
75 PI2D.Mode = mode # 'replace' or 'accumulate'
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
76
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
77 def getPatch(i):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
78 r0,r1,c0,c1 = PI2D.PC[i]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
79 if len(PI2D.PaddedImage.shape) == 2:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
80 return PI2D.PaddedImage[r0:r1,c0:c1]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
81 if len(PI2D.PaddedImage.shape) == 3:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
82 return PI2D.PaddedImage[:,r0:r1,c0:c1]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
83
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
84 def createOutput(nChannels):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
85 if nChannels == 1:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
86 PI2D.Output = np.zeros((PI2D.NRPI,PI2D.NCPI),np.float16)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
87 else:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
88 PI2D.Output = np.zeros((nChannels,PI2D.NRPI,PI2D.NCPI),np.float16)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
89 if PI2D.Mode == 'accumulate':
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
90 PI2D.Count = np.zeros((PI2D.NRPI,PI2D.NCPI),np.float16)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
91
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
92 def patchOutput(i,P):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
93 r0,r1,c0,c1 = PI2D.PC[i]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
94 if PI2D.Mode == 'accumulate':
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
95 PI2D.Count[r0:r1,c0:c1] += PI2D.W
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
96 if len(P.shape) == 2:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
97 if PI2D.Mode == 'accumulate':
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
98 PI2D.Output[r0:r1,c0:c1] += np.multiply(P,PI2D.W)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
99 elif PI2D.Mode == 'replace':
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
100 PI2D.Output[r0:r1,c0:c1] = P
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
101 elif len(P.shape) == 3:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
102 if PI2D.Mode == 'accumulate':
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
103 for i in range(P.shape[0]):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
104 PI2D.Output[i,r0:r1,c0:c1] += np.multiply(P[i,:,:],PI2D.W)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
105 elif PI2D.Mode == 'replace':
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
106 PI2D.Output[:,r0:r1,c0:c1] = P
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
107
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
108 def getValidOutput():
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
109 margin = PI2D.Margin
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
110 nr, nc = PI2D.NR, PI2D.NC
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
111 if PI2D.Mode == 'accumulate':
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
112 C = PI2D.Count[margin:margin+nr,margin:margin+nc]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
113 if len(PI2D.Output.shape) == 2:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
114 if PI2D.Mode == 'accumulate':
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
115 return np.divide(PI2D.Output[margin:margin+nr,margin:margin+nc],C)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
116 if PI2D.Mode == 'replace':
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
117 return PI2D.Output[margin:margin+nr,margin:margin+nc]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
118 if len(PI2D.Output.shape) == 3:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
119 if PI2D.Mode == 'accumulate':
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
120 for i in range(PI2D.Output.shape[0]):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
121 PI2D.Output[i,margin:margin+nr,margin:margin+nc] = np.divide(PI2D.Output[i,margin:margin+nr,margin:margin+nc],C)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
122 return PI2D.Output[:,margin:margin+nr,margin:margin+nc]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
123
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
124
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
125 def demo():
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
126 I = np.random.rand(128,128)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
127 # PI2D.setup(I,128,14)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
128 PI2D.setup(I,64,4,'replace')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
129
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
130 nChannels = 2
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
131 PI2D.createOutput(nChannels)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
132
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
133 for i in range(PI2D.NumPatches):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
134 P = PI2D.getPatch(i)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
135 Q = np.zeros((nChannels,P.shape[0],P.shape[1]))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
136 for j in range(nChannels):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
137 Q[j,:,:] = P
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
138 PI2D.patchOutput(i,Q)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
139
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
140 J = PI2D.getValidOutput()
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
141 J = J[0,:,:]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
142
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
143 D = np.abs(I-J)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
144 print(np.max(D))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
145
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
146 K = cat(1,cat(1,I,J),D)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
147 imshow(K)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
148
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
149
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
150 class PI3D:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
151 Image = None
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
152 PaddedImage = None
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
153 PatchSize = 128
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
154 Margin = 14
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
155 SubPatchSize = 100
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
156 PC = None # patch coordinates
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
157 NumPatches = 0
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
158 Output = None
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
159 Count = None
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
160 NR = None # rows
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
161 NC = None # cols
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
162 NZ = None # planes
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
163 NRPI = None
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
164 NCPI = None
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
165 NZPI = None
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
166 Mode = None
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
167 W = None
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
168
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
169 def setup(image,patchSize,margin,mode):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
170 PI3D.Image = image
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
171 PI3D.PatchSize = patchSize
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
172 PI3D.Margin = margin
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
173 subPatchSize = patchSize-2*margin
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
174 PI3D.SubPatchSize = subPatchSize
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
175
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
176 W = np.ones((patchSize,patchSize,patchSize))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
177 W[[0,-1],:,:] = 0
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
178 W[:,[0,-1],:] = 0
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
179 W[:,:,[0,-1]] = 0
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
180 for i in range(1,2*margin):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
181 v = i/(2*margin)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
182 W[[i,-i-1],i:-i,i:-i] = v
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
183 W[i:-i,[i,-i-1],i:-i] = v
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
184 W[i:-i,i:-i,[i,-i-1]] = v
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
185
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
186 PI3D.W = W
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
187
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
188 if len(image.shape) == 3:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
189 nz,nr,nc = image.shape
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
190 elif len(image.shape) == 4: # multi-channel image
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
191 nz,nw,nr,nc = image.shape
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
192
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
193 PI3D.NR = nr
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
194 PI3D.NC = nc
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
195 PI3D.NZ = nz
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
196
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
197 npr = int(np.ceil(nr/subPatchSize)) # number of patch rows
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
198 npc = int(np.ceil(nc/subPatchSize)) # number of patch cols
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
199 npz = int(np.ceil(nz/subPatchSize)) # number of patch planes
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
200
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
201 nrpi = npr*subPatchSize+2*margin # number of rows in padded image
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
202 ncpi = npc*subPatchSize+2*margin # number of cols in padded image
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
203 nzpi = npz*subPatchSize+2*margin # number of plns in padded image
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
204
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
205 PI3D.NRPI = nrpi
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
206 PI3D.NCPI = ncpi
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
207 PI3D.NZPI = nzpi
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
208
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
209 if len(image.shape) == 3:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
210 PI3D.PaddedImage = np.zeros((nzpi,nrpi,ncpi))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
211 PI3D.PaddedImage[margin:margin+nz,margin:margin+nr,margin:margin+nc] = image
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
212 elif len(image.shape) == 4:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
213 PI3D.PaddedImage = np.zeros((nzpi,nw,nrpi,ncpi))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
214 PI3D.PaddedImage[margin:margin+nz,:,margin:margin+nr,margin:margin+nc] = image
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
215
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
216 PI3D.PC = [] # patch coordinates [z0,z1,r0,r1,c0,c1]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
217 for iZ in range(npz):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
218 z0 = iZ*subPatchSize
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
219 z1 = z0+patchSize
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
220 for i in range(npr):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
221 r0 = i*subPatchSize
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
222 r1 = r0+patchSize
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
223 for j in range(npc):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
224 c0 = j*subPatchSize
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
225 c1 = c0+patchSize
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
226 PI3D.PC.append([z0,z1,r0,r1,c0,c1])
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
227
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
228 PI3D.NumPatches = len(PI3D.PC)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
229 PI3D.Mode = mode # 'replace' or 'accumulate'
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
230
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
231 def getPatch(i):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
232 z0,z1,r0,r1,c0,c1 = PI3D.PC[i]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
233 if len(PI3D.PaddedImage.shape) == 3:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
234 return PI3D.PaddedImage[z0:z1,r0:r1,c0:c1]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
235 if len(PI3D.PaddedImage.shape) == 4:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
236 return PI3D.PaddedImage[z0:z1,:,r0:r1,c0:c1]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
237
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
238 def createOutput(nChannels):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
239 if nChannels == 1:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
240 PI3D.Output = np.zeros((PI3D.NZPI,PI3D.NRPI,PI3D.NCPI))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
241 else:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
242 PI3D.Output = np.zeros((PI3D.NZPI,nChannels,PI3D.NRPI,PI3D.NCPI))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
243 if PI3D.Mode == 'accumulate':
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
244 PI3D.Count = np.zeros((PI3D.NZPI,PI3D.NRPI,PI3D.NCPI))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
245
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
246 def patchOutput(i,P):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
247 z0,z1,r0,r1,c0,c1 = PI3D.PC[i]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
248 if PI3D.Mode == 'accumulate':
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
249 PI3D.Count[z0:z1,r0:r1,c0:c1] += PI3D.W
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
250 if len(P.shape) == 3:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
251 if PI3D.Mode == 'accumulate':
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
252 PI3D.Output[z0:z1,r0:r1,c0:c1] += np.multiply(P,PI3D.W)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
253 elif PI3D.Mode == 'replace':
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
254 PI3D.Output[z0:z1,r0:r1,c0:c1] = P
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
255 elif len(P.shape) == 4:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
256 if PI3D.Mode == 'accumulate':
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
257 for i in range(P.shape[1]):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
258 PI3D.Output[z0:z1,i,r0:r1,c0:c1] += np.multiply(P[:,i,:,:],PI3D.W)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
259 elif PI3D.Mode == 'replace':
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
260 PI3D.Output[z0:z1,:,r0:r1,c0:c1] = P
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
261
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
262 def getValidOutput():
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
263 margin = PI3D.Margin
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
264 nz, nr, nc = PI3D.NZ, PI3D.NR, PI3D.NC
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
265 if PI3D.Mode == 'accumulate':
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
266 C = PI3D.Count[margin:margin+nz,margin:margin+nr,margin:margin+nc]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
267 if len(PI3D.Output.shape) == 3:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
268 if PI3D.Mode == 'accumulate':
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
269 return np.divide(PI3D.Output[margin:margin+nz,margin:margin+nr,margin:margin+nc],C)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
270 if PI3D.Mode == 'replace':
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
271 return PI3D.Output[margin:margin+nz,margin:margin+nr,margin:margin+nc]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
272 if len(PI3D.Output.shape) == 4:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
273 if PI3D.Mode == 'accumulate':
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
274 for i in range(PI3D.Output.shape[1]):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
275 PI3D.Output[margin:margin+nz,i,margin:margin+nr,margin:margin+nc] = np.divide(PI3D.Output[margin:margin+nz,i,margin:margin+nr,margin:margin+nc],C)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
276 return PI3D.Output[margin:margin+nz,:,margin:margin+nr,margin:margin+nc]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
277
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
278
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
279 def demo():
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
280 I = np.random.rand(128,128,128)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
281 PI3D.setup(I,64,4,'accumulate')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
282
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
283 nChannels = 2
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
284 PI3D.createOutput(nChannels)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
285
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
286 for i in range(PI3D.NumPatches):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
287 P = PI3D.getPatch(i)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
288 Q = np.zeros((P.shape[0],nChannels,P.shape[1],P.shape[2]))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
289 for j in range(nChannels):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
290 Q[:,j,:,:] = P
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
291 PI3D.patchOutput(i,Q)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
292
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
293 J = PI3D.getValidOutput()
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
294 J = J[:,0,:,:]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
295
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
296 D = np.abs(I-J)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
297 print(np.max(D))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
298
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
299 pI = I[64,:,:]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
300 pJ = J[64,:,:]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
301 pD = D[64,:,:]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
302
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
303 K = cat(1,cat(1,pI,pJ),pD)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
304 imshow(K)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
305