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