PyOPIA 2.11.0__tar.gz → 2.12.0__tar.gz

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.
Files changed (33) hide show
  1. {pyopia-2.11.0 → pyopia-2.12.0}/PKG-INFO +1 -1
  2. pyopia-2.12.0/pyopia/__init__.py +1 -0
  3. pyopia-2.12.0/pyopia/instrument/common.py +150 -0
  4. pyopia-2.11.0/pyopia/__init__.py +0 -1
  5. pyopia-2.11.0/pyopia/instrument/common.py +0 -54
  6. {pyopia-2.11.0 → pyopia-2.12.0}/.gitignore +0 -0
  7. {pyopia-2.11.0 → pyopia-2.12.0}/LICENSE +0 -0
  8. {pyopia-2.11.0 → pyopia-2.12.0}/README.md +0 -0
  9. {pyopia-2.11.0 → pyopia-2.12.0}/pyopia/auxillarydata.py +0 -0
  10. {pyopia-2.11.0 → pyopia-2.12.0}/pyopia/background.py +0 -0
  11. {pyopia-2.11.0 → pyopia-2.12.0}/pyopia/cf_metadata.json +0 -0
  12. {pyopia-2.11.0 → pyopia-2.12.0}/pyopia/classify.py +0 -0
  13. {pyopia-2.11.0 → pyopia-2.12.0}/pyopia/cli.py +0 -0
  14. {pyopia-2.11.0 → pyopia-2.12.0}/pyopia/exampledata.py +0 -0
  15. {pyopia-2.11.0 → pyopia-2.12.0}/pyopia/instrument/__init__.py +0 -0
  16. {pyopia-2.11.0 → pyopia-2.12.0}/pyopia/instrument/holo.py +0 -0
  17. {pyopia-2.11.0 → pyopia-2.12.0}/pyopia/instrument/silcam.py +0 -0
  18. {pyopia-2.11.0 → pyopia-2.12.0}/pyopia/instrument/uvp.py +0 -0
  19. {pyopia-2.11.0 → pyopia-2.12.0}/pyopia/io.py +0 -0
  20. {pyopia-2.11.0 → pyopia-2.12.0}/pyopia/metadata.py +0 -0
  21. {pyopia-2.11.0 → pyopia-2.12.0}/pyopia/pipeline.py +0 -0
  22. {pyopia-2.11.0 → pyopia-2.12.0}/pyopia/plotting.py +0 -0
  23. {pyopia-2.11.0 → pyopia-2.12.0}/pyopia/process.py +0 -0
  24. {pyopia-2.11.0 → pyopia-2.12.0}/pyopia/simulator/__init__.py +0 -0
  25. {pyopia-2.11.0 → pyopia-2.12.0}/pyopia/simulator/silcam.py +0 -0
  26. {pyopia-2.11.0 → pyopia-2.12.0}/pyopia/statistics.py +0 -0
  27. {pyopia-2.11.0 → pyopia-2.12.0}/pyopia/tests/__init__.py +0 -0
  28. {pyopia-2.11.0 → pyopia-2.12.0}/pyopia/tests/test_auxillarydata.py +0 -0
  29. {pyopia-2.11.0 → pyopia-2.12.0}/pyopia/tests/test_classify.py +0 -0
  30. {pyopia-2.11.0 → pyopia-2.12.0}/pyopia/tests/test_io.py +0 -0
  31. {pyopia-2.11.0 → pyopia-2.12.0}/pyopia/tests/test_notebooks.py +0 -0
  32. {pyopia-2.11.0 → pyopia-2.12.0}/pyopia/tests/test_pipeline.py +0 -0
  33. {pyopia-2.11.0 → pyopia-2.12.0}/pyproject.toml +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyOPIA
3
- Version: 2.11.0
3
+ Version: 2.12.0
4
4
  Summary: A Python Ocean Particle Image Analysis toolbox.
5
5
  Project-URL: Repository, https://github.com/sintef/pyopia
6
6
  Project-URL: Documentation, https://pyopia.readthedocs.io
@@ -0,0 +1 @@
1
+ __version__ = "2.12.0"
@@ -0,0 +1,150 @@
1
+ """
2
+ Non-instrument-specific functions that operates on the image loading or initial processing level.
3
+ """
4
+
5
+ import numpy as np
6
+ from skimage.draw import disk
7
+
8
+
9
+ def apply_circular_mask(image, radius, center=None):
10
+ """
11
+ Apply a circular mask to an RGB image, zeroing out pixels outside the disc.
12
+
13
+ Parameters
14
+ ----------
15
+ image: (np.array)
16
+ numpy array of shape (h,w) or (h, w, 3)
17
+ radius: int
18
+ radius of the circular mask, in pixels
19
+ center: (int, int)
20
+ center of the circular mask, in pixels from top left corner
21
+ vertical coordinate first
22
+ optional, will use center of image if not given
23
+
24
+
25
+ Returns
26
+ -------
27
+ masked_image:
28
+ numpy array of shape (h,w) or (h, w, 3) with mask applied
29
+ """
30
+ # Find image shape
31
+ if len(image.shape) == 3:
32
+ h, w, _ = image.shape
33
+ else:
34
+ h, w = image.shape
35
+ if center is None:
36
+ center = (h // 2, w // 2)
37
+
38
+ # Create mask, True for those pixels that will be masked away
39
+ mask = np.ones((h, w), dtype=bool)
40
+ rr, cc = disk(center, radius, shape=mask.shape)
41
+ mask[rr, cc] = False
42
+
43
+ # Apply mask, handling both greyscale (h, w) and colour (h, w, 3)
44
+ if len(image.shape) == 3:
45
+ masked_image = np.where(mask[:, :, None], 0.0, image)
46
+ else:
47
+ masked_image = np.where(mask, 0.0, image)
48
+
49
+ return masked_image
50
+
51
+
52
+ class RectangularImageMask:
53
+ """PyOpia pipline-compatible class for masking out part of the raw image.
54
+
55
+ Required keys in :class:`pyopia.pipeline.Data`:
56
+ - :attr:`pyopia.pipeline.Data.imraw`
57
+
58
+ Parameters
59
+ ----------
60
+ mask_bbox : (list, optional)
61
+ Pixel corner coordinates of rectangle to mask (image outside the rectangle is set to 0)
62
+
63
+ Returns
64
+ -------
65
+ data : :class:`pyopia.pipeline.Data`
66
+ containing the new key:
67
+
68
+ :attr:`pyopia.pipeline.Data.im_masked`
69
+
70
+
71
+ Example pipeline use:
72
+ ----------------------
73
+ Put this in your pipeline right after load step to mask out border outside specified pixel coordinates.
74
+ Remember to update the next step in the pipeline to use 'im_masked' as source.
75
+
76
+ .. code-block:: toml
77
+
78
+ [steps.mask]
79
+ pipeline_class = 'pyopia.instrument.common.RectangularImageMask'
80
+ mask_bbox = [[200, 1850], [400, 2048], [0, 3]]
81
+
82
+ The mask_bbox is [[start_row, end_row], [start_col, end_col], [start_colorchan, end_colorchan]]
83
+ """
84
+
85
+ def __init__(self, mask_bbox=None):
86
+ if mask_bbox is None:
87
+ self.mask_bbox = (slice(None), slice(None), slice(None))
88
+ else:
89
+ self.mask_bbox = (
90
+ slice(mask_bbox[0][0], mask_bbox[0][1]),
91
+ slice(mask_bbox[1][0], mask_bbox[1][1]),
92
+ slice(mask_bbox[2][0], mask_bbox[2][1]),
93
+ )
94
+
95
+ def __call__(self, data):
96
+ # Create a masked version of imraw, where space between defined mask rectangle and border is set to 0,
97
+ # while inside is kept.
98
+ imraw_masked = np.ones_like(data["imraw"])
99
+ imraw_masked[self.mask_bbox] = data["imraw"][self.mask_bbox]
100
+ data["im_masked"] = imraw_masked
101
+
102
+ return data
103
+
104
+
105
+ class CircularImageMask:
106
+ """PyOPIA pipline-compatible class for masking out part of the raw image with a circular centered disc
107
+
108
+ Required keys in :class:`pyopia.pipeline.Data`:
109
+ - :attr:`pyopia.pipeline.Data.imraw`
110
+
111
+ Parameters
112
+ ----------
113
+ radius : (int)
114
+ Radius in pixel of the circular disc mask (image outside disc is set to 0)
115
+ center : (list of ints, optional)
116
+ Center coordinate for masking circle (pixels)
117
+
118
+ Returns
119
+ -------
120
+ data : :class:`pyopia.pipeline.Data`
121
+ containing the new key:
122
+
123
+ :attr:`pyopia.pipeline.Data.im_masked`
124
+
125
+
126
+ Example pipeline use:
127
+ ----------------------
128
+ Put this in your pipeline right after load step to mask out border outside specified pixel coordinates.
129
+ Remember to update the next step in the pipeline to use 'im_masked' as source.
130
+
131
+ .. code-block:: toml
132
+
133
+ [steps.mask]
134
+ pipeline_class = 'pyopia.instrument.common.CircularImageMask'
135
+ radius = 500
136
+ center = (600, 600) # Optional, is image center by default
137
+ """
138
+
139
+ def __init__(self, radius, center=None):
140
+ self.radius = radius
141
+ self.center = center
142
+
143
+ def __call__(self, data):
144
+ """
145
+ Create a masked version of imraw, where the area outside a disc
146
+ with given radius centered in the image is set to 0, while the inside is kept.
147
+ """
148
+ data["im_masked"] = apply_circular_mask(data["imraw"], self.radius, self.center)
149
+
150
+ return data
@@ -1 +0,0 @@
1
- __version__ = "2.11.0"
@@ -1,54 +0,0 @@
1
- '''
2
- Non-instrument-specific functions that operates on the image loading or initial processing level.
3
- '''
4
- import numpy as np
5
-
6
-
7
- class RectangularImageMask():
8
- '''PyOpia pipline-compatible class for masking out part of the raw image.
9
-
10
- Required keys in :class:`pyopia.pipeline.Data`:
11
- - :attr:`pyopia.pipeline.Data.imraw`
12
-
13
- Parameters
14
- ----------
15
- mask_bbox : (list, optional)
16
- Pixel corner coordinates of rectangle to mask (image outside the rectangle is set to 0)
17
-
18
- Returns
19
- -------
20
- data : :class:`pyopia.pipeline.Data`
21
- containing the new key:
22
-
23
- :attr:`pyopia.pipeline.Data.im_masked`
24
-
25
-
26
- Example pipeline use:
27
- ----------------------
28
- Put this in your pipeline right after load step to mask out border outside specified pixel coordinates:
29
-
30
- .. code-block:: toml
31
-
32
- [steps.mask]
33
- pipeline_class = 'pyopia.instrument.common.RectangularImageMask'
34
- mask_bbox = [[200, 1850], [400, 2048], [0, 3]]
35
-
36
- The mask_bbox is [[start_row, end_row], [start_col, end_col], [start_colorchan, end_colorchan]]
37
- '''
38
-
39
- def __init__(self, mask_bbox=None):
40
- if mask_bbox is None:
41
- self.mask_bbox = (slice(None), slice(None), slice(None))
42
- else:
43
- self.mask_bbox = (slice(mask_bbox[0][0], mask_bbox[0][1]),
44
- slice(mask_bbox[1][0], mask_bbox[1][1]),
45
- slice(mask_bbox[2][0], mask_bbox[2][1]))
46
-
47
- def __call__(self, data):
48
- # Create a masked version of imraw, where space between defined mask rectangle and border is set to 0,
49
- # while inside is kept.
50
- imraw_masked = np.zeros_like(data['imraw'])
51
- imraw_masked[self.mask_bbox] = data['imraw'][self.mask_bbox]
52
- data['im_masked'] = imraw_masked
53
-
54
- return data
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes