Skip to content

Commit db9d162

Browse files
authored
Merge pull request #1825 from danforthcenter/image-sharpening
Image sharpening
2 parents a3a0eab + 125cc85 commit db9d162

115 files changed

Lines changed: 631 additions & 432 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
107 KB
Loading
111 KB
Loading

docs/sharpen.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
## Sharpen
2+
3+
Sharpens an image through the unsharp masking method. Applies a gaussian blur which is subtracted from an exaggerated version of the starting image.
4+
5+
**plantcv.sharpen**(*img, ksize, amount=1, threshold=0, sigma_x=0, sigma_y=None, roi=None*)
6+
7+
**returns** sharpened image
8+
9+
- **Parameters:**
10+
- img - RGB or grayscale image data
11+
- ksize - Tuple of kernel dimensions, e.g. (5, 5). Must be odd integers.
12+
- amount - Integer describing amount of sharpening, higher numbers will sharpen more.
13+
- threshold - Integer cutoff on low contrast, contrasts lower than this will be removed.
14+
- sigma_x - standard deviation in X direction; if 0 (default), calculated from kernel size
15+
- sigma_y - standard deviation in Y direction; if sigma_Y is None (default), sigma_Y is taken to equal sigma_X
16+
- roi - Optional rectangular ROI as returned by [`pcv.roi.rectangle`](roi_rectangle.md) within which to apply this function. (default = None, which uses the entire image)
17+
- **Context:**
18+
- Used to reduce blur in an image
19+
20+
**Original image**
21+
22+
![Screenshot](img/documentation_images/threshold_2channels/VIS_TV_z500_h2_g0_e100_163042_0_m.png)
23+
24+
**Sharpening Image**
25+
26+
```python
27+
28+
# Apply sharpening within an ROI to show differences
29+
roi = pcv.roi.rectangle(img, 200, 0, 335, 200)
30+
sharp1 = pcv.sharpen(img, (5, 5), amount=1, roi=roi)
31+
32+
# Higher amount of sharpening will look more dramatic
33+
sharp5 = pcv.sharpen(img, (5, 5), amount = 5, roi=roi)
34+
```
35+
36+
**Sharpen (ksize = (5,5), amount=1, roi=roi)**
37+
38+
![sharp1](img/documentation_images/sharpen/sharp1.png)
39+
40+
**Sharpen (ksize = (5,5), amount=5, roi=roi)**
41+
42+
![sharp5](img/documentation_images/sharpen/sharp5.png)
43+
44+
**Source Code:** [Here](https://github.com/danforthcenter/plantcv/blob/main/plantcv/plantcv/sharpen.py)

docs/updating.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,10 @@ pages for more details on the input and output variable types.
11561156
* post v3.0dev2: sr_img = **plantcv.scharr_filter**(*gray_img, dx, dy, scale*)
11571157
* post v4.9: sr_img = **plantcv.scharr_filter**(*gray_img, dx, dy, scale, roi=None*)
11581158

1159+
#### plantcv.sharpen
1160+
* pre v5.0: NA
1161+
* post v5.0: img = **plantcv.sharpen**(*img, ksize, amount=1, threshold=0, sigma_x=0, sigma_y=None, roi=None*)
1162+
11591163
#### plantcv.shift_img
11601164

11611165
* pre v3.0dev2: device, adjusted_img = **plantcv.shift_img**(*img, device, number, side="right", debug=None*)

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ nav:
160160
- 'Filter a mask by ROI (quickly)': roi_quick_filter.md
161161
- 'Convert ROI to Mask': roi2mask.md
162162
- 'Segment Image Series': segment_image_series.md
163+
- 'Sharpen Image': sharpen.md
163164
- 'Shift Image': shift.md
164165
- 'Spatial Clustering': spatial_clustering.md
165166
- 'Spectral Index': spectral_index.md

plantcv/plantcv/__init__.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@
44
__version__ = version("plantcv")
55

66
from plantcv.plantcv.fatal_error import fatal_error
7-
from plantcv.plantcv.classes import Params
8-
from plantcv.plantcv.classes import Outputs
97
from plantcv.plantcv.classes import Spectral_data
108
from plantcv.plantcv.classes import PSII_data
11-
from plantcv.plantcv.classes import Points
9+
from plantcv.plantcv.classes import Point
1210
from plantcv.plantcv.classes import Objects
1311

1412
# Initialize an instance of the Params and Outputs class with default values
1513
# params and outputs are available when plantcv is imported
16-
params = Params()
17-
outputs = Outputs()
14+
from plantcv.plantcv._globals import Params, Outputs
15+
from plantcv.plantcv._globals import params, outputs
1816

1917
from plantcv.plantcv.deprecation_warning import deprecation_warning
2018
from plantcv.plantcv.warn import warn
@@ -63,6 +61,7 @@
6361
from plantcv.plantcv.canny_edge_detect import canny_edge_detect
6462
from plantcv.plantcv.opening import opening
6563
from plantcv.plantcv.closing import closing
64+
from plantcv.plantcv.sharpen import sharpen
6665
from plantcv.plantcv import roi
6766
from plantcv.plantcv import threshold
6867
from plantcv.plantcv import visualize
@@ -87,12 +86,14 @@
8786

8887
__all__ = [
8988
"fatal_error",
90-
"Params",
91-
"Outputs",
9289
"Spectral_data",
9390
'PSII_data',
94-
'Points',
91+
'Point',
9592
"Objects",
93+
"Params",
94+
"Outputs",
95+
"params",
96+
"outputs",
9697
"deprecation_warning",
9798
"warn",
9899
"print_image",
@@ -139,6 +140,7 @@
139140
"canny_edge_detect",
140141
"opening",
141142
"closing",
143+
"sharpen",
142144
"roi",
143145
"threshold",
144146
"visualize",

plantcv/plantcv/_debug.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Debugging module
2-
from plantcv.plantcv import params
2+
from plantcv.plantcv._globals import params
33
from plantcv.plantcv import print_image
44
from plantcv.plantcv import plot_image
55

0 commit comments

Comments
 (0)