napari-dpr 0.1.0__cp310-cp310-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,103 @@
1
+ # distutils: language = c++
2
+ import numpy as np
3
+ cimport numpy as np
4
+ from libc.math cimport fabs, ceil
5
+ import scipy.ndimage as ndi
6
+ from scipy.interpolate import RectBivariateSpline
7
+
8
+ np.import_array()
9
+
10
+ ctypedef np.float64_t DTYPE_t
11
+
12
+ def dpr_set_parameters(double psf, double gain=1, double background=-1, temporal=None):
13
+ if background < 0:
14
+ background = ceil(17 * psf)
15
+ return {'gain': gain, 'background': background, 'temporal': temporal}
16
+
17
+ cpdef tuple dpr_update_single(np.ndarray[DTYPE_t, ndim=2] i, double psf, dict opt):
18
+ cdef:
19
+ int h = i.shape[0]
20
+ int w = i.shape[1]
21
+ int r = <int>ceil(opt['background'])
22
+ double g = opt['gain']
23
+ np.ndarray[DTYPE_t, ndim=2] localmin = np.zeros((h, w))
24
+ np.ndarray[DTYPE_t, ndim=2] i_localmin = np.zeros((h, w))
25
+ int u, v
26
+
27
+ i = i - i.min()
28
+ for u in range(h):
29
+ for v in range(w):
30
+ sub = i[max(0, u - r):min(h, u + r + 1), max(0, v - r):min(w, v + r + 1)]
31
+ localmin[u, v] = np.min(sub)
32
+ i_localmin[u, v] = i[u, v] - localmin[u, v]
33
+
34
+ psf /= 1.6651
35
+ x0 = np.linspace(-0.5, 0.5, w)
36
+ y0 = np.linspace(-0.5, 0.5, h)
37
+ x = np.linspace(-0.5, 0.5, round(5 * w / psf))
38
+ y = np.linspace(-0.5, 0.5, round(5 * h / psf))
39
+
40
+ interp_m = RectBivariateSpline(y0, x0, i_localmin)(y, x)
41
+ interp_m[interp_m < 0] = 0
42
+ interp_m = np.pad(interp_m, 10)
43
+
44
+ interp_i = RectBivariateSpline(y0, x0, i)(y, x)
45
+ interp_i[interp_i < 0] = 0
46
+ interp_i = np.pad(interp_i, 10)
47
+
48
+ hn, wn = interp_i.shape
49
+ norm = interp_m / (ndi.gaussian_filter(interp_m, 10) + 1e-5)
50
+
51
+ sobel_x = np.array([[1, 0, -1], [2, 0, -2], [1, 0, -1]])
52
+ sobel_y = np.array([[1, 2, 1], [0, 0, 0], [-1, -2, -1]])
53
+ gx = ndi.convolve(norm, sobel_y, mode='reflect') / (norm + 1e-5)
54
+ gy = ndi.convolve(norm, sobel_x, mode='reflect') / (norm + 1e-5)
55
+
56
+ gain_val = 0.5 * g + 1
57
+ dx = gain_val * gx
58
+ dy = gain_val * gy
59
+ dx[np.abs(dx) > 10] = 0
60
+ dy[np.abs(dy) > 10] = 0
61
+
62
+ out = np.zeros((hn, wn))
63
+ cdef int nx, ny, fx, fy, sx, sy
64
+ cdef double wx, wy, w1, w2, w3, w4, val
65
+
66
+ for nx in range(10, hn - 10):
67
+ for ny in range(10, wn - 10):
68
+ wx, wy = dx[nx, ny], dy[nx, ny]
69
+ fx, fy = int(wx), int(wy)
70
+ sx, sy = int(np.sign(wx)), int(np.sign(wy))
71
+ w1 = (1 - fabs(wx - fx)) * (1 - fabs(wy - fy))
72
+ w2 = (1 - fabs(wx - fx)) * fabs(wy - fy)
73
+ w3 = fabs(wx - fx) * (1 - fabs(wy - fy))
74
+ w4 = fabs(wx - fx) * fabs(wy - fy)
75
+ val = interp_i[nx, ny]
76
+ out[nx + fx, ny + fy] += w1 * val
77
+ out[nx + fx, ny + fy + sy] += w2 * val
78
+ out[nx + fx + sx, ny + fy] += w3 * val
79
+ out[nx + fx + sx, ny + fy + sy] += w4 * val
80
+
81
+ return out[10:-10, 10:-10], interp_i[10:-10, 10:-10], g, r
82
+
83
+ cpdef tuple dpr_stack(np.ndarray[DTYPE_t, ndim=3] s, double psf, dict opt):
84
+ cdef int f = s.shape[2]
85
+ dpr0, mag0, _, _ = dpr_update_single(s[:, :, 0], psf, opt)
86
+ shp = dpr0.shape
87
+ out = np.zeros((shp[0], shp[1], f))
88
+ mag = np.zeros((shp[0], shp[1], f))
89
+ cdef int i
90
+ for i in range(f):
91
+ dpr, m, _, _ = dpr_update_single(s[:, :, i], psf, opt)
92
+ out[:, :, i] = dpr
93
+ mag[:, :, i] = m
94
+ if opt.get('temporal') == 'mean':
95
+ out = np.mean(out, axis=2)
96
+ elif opt.get('temporal') == 'var':
97
+ out = np.var(out, axis=2)
98
+ return out, mag
99
+ cpdef tuple apply_dpr(np.ndarray[DTYPE_t, ndim=3] im, double psf=4, double gain=2, double background=10, temporal='mean'):
100
+ if im.ndim == 2:
101
+ im = im[:, :, np.newaxis]
102
+ opt = dpr_set_parameters(psf, gain, background, temporal)
103
+ return dpr_stack(im, psf, opt)
napari_dpr/run.dpr.py ADDED
@@ -0,0 +1,68 @@
1
+ # run_dpr.py
2
+ import os
3
+ import numpy as np
4
+ import tifffile as tf
5
+ from napari_dpr.dpr_core import apply_dpr
6
+ import matplotlib.pyplot as plt
7
+ import time
8
+ from pathlib import Path
9
+
10
+ def run_example(input_file=None):
11
+ """Run DPR on an example image file."""
12
+
13
+ # If no input file is provided, try to find the test image in standard locations
14
+ if input_file is None:
15
+ # Try several possible locations for the test image
16
+ possible_paths = [
17
+ "test_data/test_image.tif", # Repository structure
18
+ "../test_data/test_image.tif", # If run from src directory
19
+ "../../test_data/test_image.tif", # If run from deeper directory
20
+ os.path.join(os.path.dirname(__file__), '../../test_data/test_image.tif') # Relative to script
21
+ ]
22
+
23
+ for path in possible_paths:
24
+ if os.path.exists(path):
25
+ input_file = path
26
+ break
27
+
28
+ if input_file is None:
29
+ # If no test image is found, generate a random one
30
+ print("No test image found, generating random data...")
31
+ input_image = np.random.rand(64, 64, 5).astype(np.float64)
32
+ else:
33
+ print(f"Using test image: {input_file}")
34
+ else:
35
+ print(f"Using provided image: {input_file}")
36
+
37
+ # Load the image if a file was found or provided
38
+ if input_file is not None:
39
+ input_image = tf.imread(input_file)
40
+ # Ensure correct dimensions (HEIGHT, WIDTH, TIME)
41
+ if input_image.ndim == 3 and input_image.shape[0] < input_image.shape[1]:
42
+ input_image = input_image.transpose([1, 2, 0])
43
+
44
+ # Ensure 3D image (HEIGHT, WIDTH, TIME)
45
+ if input_image.ndim == 2:
46
+ input_image = input_image[:, :, np.newaxis]
47
+
48
+ # Process with DPR
49
+ print(f"Processing image of shape {input_image.shape}...")
50
+ start = time.time()
51
+ dpr_out, magnified = apply_dpr(input_image, psf=4.0)
52
+ print(f"Time taken: {time.time() - start:.2f} seconds")
53
+
54
+ # Display results
55
+ plt.figure(figsize=(12, 6))
56
+ plt.subplot(121)
57
+ plt.title("Original (Magnified)")
58
+ plt.imshow(magnified.sum(2))
59
+ plt.subplot(122)
60
+ plt.title("DPR Enhanced")
61
+ plt.imshow(dpr_out)
62
+ plt.tight_layout()
63
+ plt.show()
64
+
65
+ return dpr_out, magnified
66
+
67
+ if __name__ == "__main__":
68
+ run_example()
@@ -0,0 +1,32 @@
1
+ Metadata-Version: 2.4
2
+ Name: napari-dpr
3
+ Version: 0.1.0
4
+ Summary: Napari plugin for DPR
5
+ Author-email: JenuC <jenu.chacko@wisc.edu>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/jenuc/napari-dpr
8
+ Project-URL: Bug Tracker, https://github.com/jenuc/napari-dpr/issues
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.9
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Framework :: napari
18
+ Requires-Python: >=3.9
19
+ Description-Content-Type: text/markdown
20
+ Requires-Dist: napari>=0.4.15
21
+ Requires-Dist: numpy>=1.24.3
22
+ Requires-Dist: scipy>=1.10.1
23
+ Requires-Dist: matplotlib>=3.7.2
24
+ Requires-Dist: cython>=0.29.0
25
+ Requires-Dist: setuptools>=42.0.0
26
+ Requires-Dist: tifffile
27
+ Requires-Dist: pillow
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest; extra == "dev"
30
+ Requires-Dist: build; extra == "dev"
31
+ Requires-Dist: twine; extra == "dev"
32
+ Requires-Dist: cibuildwheel; extra == "dev"
@@ -0,0 +1,14 @@
1
+ napari_dpr/__init__.py,sha256=HFUdQMoqtTsOemML-GXsGoAC8q-EGgfAbqgQzhqfRwY,165
2
+ napari_dpr/_widget.py,sha256=_4c3sK7JQGcBR97SHkh8EkSULcw_O0IE9kaRXY-lT44,2933
3
+ napari_dpr/dpr.py,sha256=6pNcqYCI7HQXJv2nU33ZFyhEJu4Po5Fo3xG5Z1L8WIc,5267
4
+ napari_dpr/dpr_core.cp310-win_amd64.pyd,sha256=XSPkw-7w569QoqQytaG7Qr2c-4tefdOF91GfzsoSI94,102912
5
+ napari_dpr/dpr_core.cp311-win_amd64.pyd,sha256=jNnBf1NOD5TDAa5nWIQxU0vX4Ab_I7abPuRO-WywYFo,103424
6
+ napari_dpr/dpr_core.cp312-win_amd64.pyd,sha256=UWnFnnQhb-OQtgTBq-KsWNDA1V0RLkE5cnL3t3eChco,102400
7
+ napari_dpr/dpr_core.cp39-win_amd64.pyd,sha256=YnljIT3EbCAuhz1w2pHmi4HfIj7xUb7wUNtoLnFAcOY,102912
8
+ napari_dpr/dpr_core.cpp,sha256=fijGJvSO3RHFqsfgiGJrzetKozYK2kYrS-YO48H7uVg,621646
9
+ napari_dpr/dpr_core.pyx,sha256=GGnCR37RnWW_IDBHwuqrCevCUJHo5p7cNhQyKUQlvIs,3804
10
+ napari_dpr/run.dpr.py,sha256=NDr2QhzYMjr0ZqudspgzOCZhMxaqRrbejwaS7lPs6_4,2427
11
+ napari_dpr-0.1.0.dist-info/METADATA,sha256=jQQWu1SNBmqgAre6eFK7ep7k0ujRiFJ35wniF54tWYY,1207
12
+ napari_dpr-0.1.0.dist-info/WHEEL,sha256=wtBQCQglBFOecpGS5EGnKK_Vb7B0KxTvBpQoiSy-jL0,101
13
+ napari_dpr-0.1.0.dist-info/top_level.txt,sha256=i9hH6jDl1Ge8GHx1LoWvm1k5DLu4b7-59b5ceuaWxuI,11
14
+ napari_dpr-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (78.1.1)
3
+ Root-Is-Purelib: false
4
+ Tag: cp310-cp310-win_amd64
5
+
@@ -0,0 +1 @@
1
+ napari_dpr