forked from coraxx/3DCT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
90 lines (74 loc) · 2.61 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
# @Title : conftest
# @Project : 3DCTv2
# @Description : conftest for pytest
# @Author : Jan Arnold
# @Email : jan.arnold (at) coraxx.net
# @Copyright : Copyright (C) 2016 Jan Arnold
# @License : GPLv3 (see LICENSE file)
# @Credits :
# @Maintainer : Jan Arnold
# @Date : 2016/09
# @Version : 3DCT 2.3.0 module rev. 1
# @Status : stable
# @Usage : pytest
# @Notes :
# @Python_version : 2.7.11
"""
# ======================================================================================================================
import pytest
from PyQt4 import QtGui
import sys
import os
import numpy as np
from scipy.ndimage.filters import gaussian_filter
import tifffile as tf
execdir = os.path.dirname(os.path.realpath(__file__))
maindir_ = execdir
sys.path.append(maindir_)
app = QtGui.QApplication(sys.argv)
@pytest.fixture(scope='session')
def maindir():
print maindir_
return maindir_
@pytest.fixture(scope='session')
def image_RGB(tmpdir_factory):
img = np.random.randint(256, size=(941, 1024, 3))
fn = tmpdir_factory.mktemp('data').join('img_RGB.tif')
tf.imsave(str(fn), img.astype('uint8'), metadata={"PhysicalSizeX": "123", "FocusStepSize": "456"})
return fn
@pytest.fixture(scope='session')
def image_Grey(tmpdir_factory):
img = np.random.randint(256, size=(941, 1024))
fn = tmpdir_factory.mktemp('data').join('img_grey.tif')
tf.imsave(str(fn), img.astype('uint8'), metadata={"PhysicalSizeZ": "0.123", "FIBimage": "PixelWidth=4.56e-006\r\n"})
return fn
@pytest.fixture(scope='module')
def testVolume(size=[100, 100, 100]):
vol = np.zeros(size, dtype='uint8')
vol = insertSphere(vol, [40,20,70], 10, blur=False)
return vol
def insertSphere(volIn, pos, radius, blur=False):
try:
if pos[0] < radius or pos[0] > volIn.shape[0] - radius:
raise Exception("Sphere's x position too close to volume boundaries! Returning original volume...")
if pos[1] < radius or pos[1] > volIn.shape[1] - radius:
raise Exception("Sphere's y position too close to volume boundaries! Returning original volume...")
if pos[2] < radius or pos[2] > volIn.shape[2] - radius:
raise Exception("Sphere's z position too close to volume boundaries! Returning original volume...")
except Exception as e:
print "ERROR:", e
return volIn
## diameter
r = radius
d = r * 2 + 1
z,y,x = np.ogrid[-r:d-r, -r:d-r, -r:d-r]
mask = x*x + y*y + z*z <= r*r
sphere = np.zeros((d, d, d),dtype='uint8')
sphere[mask] = 255
if blur is True:
sphere = gaussian_filter(sphere, sigma=1).astype('uint8')
volIn[pos[0]-r:pos[0]-r+d, pos[1]-r:pos[1]-r+d, pos[2]-r:pos[2]-r+d] += sphere
return volIn