0
# Filtering
1
2
Image filtering operations for noise reduction, edge detection, enhancement, and feature extraction. Includes linear filters, morphological filters, thresholding methods, and specialized filters for various image analysis tasks.
3
4
## Capabilities
5
6
### Gaussian and Smoothing Filters
7
8
Apply Gaussian and related smoothing filters for noise reduction and image preprocessing.
9
10
```python { .api }
11
def gaussian(image, sigma=1, output=None, mode='nearest', cval=0.0, multichannel=None, preserve_range=False, truncate=4.0):
12
"""
13
Apply Gaussian filter for smoothing and noise reduction.
14
15
Parameters:
16
image : array_like
17
Input image
18
sigma : scalar or sequence of scalars, optional
19
Standard deviation for Gaussian kernel
20
output : array, optional
21
Output array for result
22
mode : str, optional
23
Boundary condition mode
24
cval : scalar, optional
25
Value for constant mode
26
multichannel : bool, optional
27
Whether last axis is channels
28
preserve_range : bool, optional
29
Keep original data range
30
truncate : float, optional
31
Kernel truncation factor
32
33
Returns:
34
ndarray
35
Filtered image
36
"""
37
38
def difference_of_gaussians(image, low_sigma, high_sigma=None, mode='nearest', cval=0.0, multichannel=False, truncate=4.0):
39
"""
40
Apply Difference of Gaussians filter for edge detection.
41
42
Parameters:
43
image : array_like
44
Input image
45
low_sigma : scalar or sequence
46
Standard deviation for low-pass filter
47
high_sigma : scalar or sequence, optional
48
Standard deviation for high-pass filter
49
mode : str, optional
50
Boundary condition mode
51
cval : scalar, optional
52
Value for constant mode
53
multichannel : bool, optional
54
Whether last axis is channels
55
truncate : float, optional
56
Kernel truncation factor
57
58
Returns:
59
ndarray
60
Filtered image showing edges
61
"""
62
```
63
64
### Edge Detection Filters
65
66
Detect edges using various gradient-based operators including Sobel, Scharr, Prewitt, Roberts, and Farid filters.
67
68
```python { .api }
69
def sobel(image, mask=None, axis=None, mode='reflect', cval=0.0):
70
"""
71
Apply Sobel edge detection filter.
72
73
Parameters:
74
image : array_like
75
Input image
76
mask : array_like, optional
77
Mask to limit computation region
78
axis : int, optional
79
Axis for directional gradient
80
mode : str, optional
81
Boundary condition mode
82
cval : scalar, optional
83
Value for constant mode
84
85
Returns:
86
ndarray
87
Edge magnitude image
88
"""
89
90
def sobel_h(image, mask=None):
91
"""
92
Apply horizontal Sobel filter.
93
94
Parameters:
95
image : array_like
96
Input image
97
mask : array_like, optional
98
Mask to limit computation region
99
100
Returns:
101
ndarray
102
Horizontal edge response
103
"""
104
105
def sobel_v(image, mask=None):
106
"""
107
Apply vertical Sobel filter.
108
109
Parameters:
110
image : array_like
111
Input image
112
mask : array_like, optional
113
Mask to limit computation region
114
115
Returns:
116
ndarray
117
Vertical edge response
118
"""
119
120
def scharr(image, mask=None, axis=None, mode='reflect', cval=0.0):
121
"""
122
Apply Scharr edge detection filter.
123
124
Parameters:
125
image : array_like
126
Input image
127
mask : array_like, optional
128
Mask to limit computation region
129
axis : int, optional
130
Axis for directional gradient
131
mode : str, optional
132
Boundary condition mode
133
cval : scalar, optional
134
Value for constant mode
135
136
Returns:
137
ndarray
138
Edge magnitude image
139
"""
140
141
def prewitt(image, mask=None, axis=None, mode='reflect', cval=0.0):
142
"""
143
Apply Prewitt edge detection filter.
144
145
Parameters:
146
image : array_like
147
Input image
148
mask : array_like, optional
149
Mask to limit computation region
150
axis : int, optional
151
Axis for directional gradient
152
mode : str, optional
153
Boundary condition mode
154
cval : scalar, optional
155
Value for constant mode
156
157
Returns:
158
ndarray
159
Edge magnitude image
160
"""
161
162
def roberts(image, mask=None):
163
"""
164
Apply Roberts cross-gradient edge detection.
165
166
Parameters:
167
image : array_like
168
Input image
169
mask : array_like, optional
170
Mask to limit computation region
171
172
Returns:
173
ndarray
174
Edge magnitude image
175
"""
176
177
def farid(image, mask=None, axis=None):
178
"""
179
Apply Farid edge detection filter.
180
181
Parameters:
182
image : array_like
183
Input image
184
mask : array_like, optional
185
Mask to limit computation region
186
axis : int, optional
187
Axis for directional gradient
188
189
Returns:
190
ndarray
191
Edge magnitude image
192
"""
193
194
def laplace(image, ksize=3, mask=None):
195
"""
196
Apply Laplacian edge detection filter.
197
198
Parameters:
199
image : array_like
200
Input image
201
ksize : int, optional
202
Kernel size (3, 5, etc.)
203
mask : array_like, optional
204
Mask to limit computation region
205
206
Returns:
207
ndarray
208
Laplacian response
209
"""
210
```
211
212
### Advanced Edge Detection
213
214
Apply Canny edge detection with non-maximum suppression and hysteresis thresholding.
215
216
```python { .api }
217
def canny(image, sigma=1.0, low_threshold=None, high_threshold=None, mask=None, use_quantiles=False, mode='constant', cval=0.0):
218
"""
219
Apply Canny edge detection algorithm.
220
221
Parameters:
222
image : array_like
223
Input grayscale image
224
sigma : float, optional
225
Standard deviation of Gaussian filter
226
low_threshold : float, optional
227
Lower hysteresis threshold
228
high_threshold : float, optional
229
Upper hysteresis threshold
230
mask : array_like, optional
231
Mask to limit edge detection region
232
use_quantiles : bool, optional
233
Interpret thresholds as quantiles
234
mode : str, optional
235
Boundary condition mode
236
cval : scalar, optional
237
Value for constant mode
238
239
Returns:
240
ndarray
241
Binary edge image
242
"""
243
```
244
245
### Ridge and Vessel Detection
246
247
Detect ridge-like structures and vessels using specialized filters optimized for tubular structures.
248
249
```python { .api }
250
def frangi(image, sigmas=range(1, 10, 2), scale_range=None, scale_step=None, alpha=0.5, beta=0.5, gamma=15, black_ridges=True, mode='reflect', cval=0):
251
"""
252
Apply Frangi filter for ridge/vessel detection.
253
254
Parameters:
255
image : array_like
256
Input image
257
sigmas : iterable of floats, optional
258
Sigmas used as scales of filter
259
scale_range : 2-tuple of floats, optional
260
Range of sigmas used
261
scale_step : float, optional
262
Step size between sigmas
263
alpha : float, optional
264
Frangi correction constant
265
beta : float, optional
266
Frangi correction constant
267
gamma : float, optional
268
Frangi correction constant
269
black_ridges : bool, optional
270
Detect black ridges on white background
271
mode : str, optional
272
Boundary condition mode
273
cval : scalar, optional
274
Value for constant mode
275
276
Returns:
277
ndarray
278
Ridge-filtered image
279
"""
280
281
def hessian(image, sigmas=range(1, 10, 2), scale_range=None, scale_step=None, alpha=0.5, beta=0.5, gamma=15, black_ridges=True, mode='reflect', cval=0):
282
"""
283
Apply Hessian-based ridge detection filter.
284
285
Parameters:
286
image : array_like
287
Input image
288
sigmas : iterable of floats, optional
289
Sigmas used as scales of filter
290
scale_range : 2-tuple of floats, optional
291
Range of sigmas used
292
scale_step : float, optional
293
Step size between sigmas
294
alpha : float, optional
295
Hessian correction constant
296
beta : float, optional
297
Hessian correction constant
298
gamma : float, optional
299
Hessian correction constant
300
black_ridges : bool, optional
301
Detect black ridges on white background
302
mode : str, optional
303
Boundary condition mode
304
cval : scalar, optional
305
Value for constant mode
306
307
Returns:
308
ndarray
309
Ridge-filtered image
310
"""
311
312
def sato(image, sigmas=range(1, 10, 2), black_ridges=True, mode='reflect', cval=0):
313
"""
314
Apply Sato ridge detection filter.
315
316
Parameters:
317
image : array_like
318
Input image
319
sigmas : iterable of floats, optional
320
Sigmas used as scales of filter
321
black_ridges : bool, optional
322
Detect black ridges on white background
323
mode : str, optional
324
Boundary condition mode
325
cval : scalar, optional
326
Value for constant mode
327
328
Returns:
329
ndarray
330
Ridge-filtered image
331
"""
332
333
def meijering(image, sigmas=range(1, 10, 2), alpha=None, black_ridges=True, mode='reflect', cval=0):
334
"""
335
Apply Meijering ridge detection filter.
336
337
Parameters:
338
image : array_like
339
Input image
340
sigmas : iterable of floats, optional
341
Sigmas used as scales of filter
342
alpha : float, optional
343
Meijering correction constant
344
black_ridges : bool, optional
345
Detect black ridges on white background
346
mode : str, optional
347
Boundary condition mode
348
cval : scalar, optional
349
Value for constant mode
350
351
Returns:
352
ndarray
353
Ridge-filtered image
354
"""
355
```
356
357
### Thresholding Methods
358
359
Apply various automatic and adaptive thresholding methods for image binarization.
360
361
```python { .api }
362
def threshold_otsu(image, nbins=256):
363
"""
364
Calculate Otsu's threshold for automatic binarization.
365
366
Parameters:
367
image : array_like
368
Input grayscale image
369
nbins : int, optional
370
Number of histogram bins
371
372
Returns:
373
float
374
Threshold value
375
"""
376
377
def threshold_multiotsu(image, classes=3, nbins=256):
378
"""
379
Calculate multi-class Otsu thresholds.
380
381
Parameters:
382
image : array_like
383
Input grayscale image
384
classes : int, optional
385
Number of classes to threshold into
386
nbins : int, optional
387
Number of histogram bins
388
389
Returns:
390
ndarray
391
Array of threshold values
392
"""
393
394
def threshold_yen(image, nbins=256):
395
"""
396
Calculate Yen's threshold method.
397
398
Parameters:
399
image : array_like
400
Input grayscale image
401
nbins : int, optional
402
Number of histogram bins
403
404
Returns:
405
float
406
Threshold value
407
"""
408
409
def threshold_li(image, tolerance=None, initial_guess=None, iter_callback=None):
410
"""
411
Calculate Li's minimum cross-entropy threshold.
412
413
Parameters:
414
image : array_like
415
Input grayscale image
416
tolerance : float, optional
417
Convergence tolerance
418
initial_guess : float, optional
419
Initial threshold guess
420
iter_callback : callable, optional
421
Iteration callback function
422
423
Returns:
424
float
425
Threshold value
426
"""
427
428
def threshold_triangle(image, nbins=256):
429
"""
430
Calculate triangle threshold method.
431
432
Parameters:
433
image : array_like
434
Input grayscale image
435
nbins : int, optional
436
Number of histogram bins
437
438
Returns:
439
float
440
Threshold value
441
"""
442
443
def threshold_local(image, block_size, method='generic', mode='reflect', param=None, cval=0, offset=0):
444
"""
445
Apply adaptive local thresholding.
446
447
Parameters:
448
image : array_like
449
Input grayscale image
450
block_size : int
451
Odd size of pixel neighborhood
452
method : str, optional
453
Thresholding method ('generic', 'gaussian', 'mean', 'median')
454
mode : str, optional
455
Boundary condition mode
456
param : float, optional
457
Generic method parameter
458
cval : float, optional
459
Constant value for constant mode
460
offset : float, optional
461
Constant subtracted from weighted mean
462
463
Returns:
464
ndarray
465
Threshold image
466
"""
467
468
def threshold_niblack(image, window_size=15, k=0.2):
469
"""
470
Apply Niblack local thresholding.
471
472
Parameters:
473
image : array_like
474
Input grayscale image
475
window_size : int, optional
476
Window size for local statistics
477
k : float, optional
478
Value of parameter k in threshold formula
479
480
Returns:
481
ndarray
482
Threshold image
483
"""
484
485
def threshold_sauvola(image, window_size=15, k=0.2, r=None):
486
"""
487
Apply Sauvola local thresholding.
488
489
Parameters:
490
image : array_like
491
Input grayscale image
492
window_size : int, optional
493
Window size for local statistics
494
k : float, optional
495
Value of parameter k in threshold formula
496
r : float, optional
497
Dynamic range of standard deviation
498
499
Returns:
500
ndarray
501
Threshold image
502
"""
503
504
def apply_hysteresis_threshold(image, low, high):
505
"""
506
Apply hysteresis thresholding.
507
508
Parameters:
509
image : array_like
510
Input image
511
low : float
512
Lower threshold
513
high : float
514
Upper threshold
515
516
Returns:
517
ndarray
518
Binary thresholded image
519
"""
520
```
521
522
### Noise Reduction Filters
523
524
Apply various filters for noise reduction including median filtering and other morphological filters.
525
526
```python { .api }
527
def median(image, footprint=None, out=None, mode='nearest', cval=0.0, behavior='ndimage'):
528
"""
529
Apply median filter for noise reduction.
530
531
Parameters:
532
image : array_like
533
Input image
534
footprint : array_like, optional
535
Footprint defining filter shape
536
out : array, optional
537
Output array
538
mode : str, optional
539
Boundary condition mode
540
cval : scalar, optional
541
Value for constant mode
542
behavior : str, optional
543
Algorithm behavior ('ndimage' or 'rank')
544
545
Returns:
546
ndarray
547
Median filtered image
548
"""
549
550
def unsharp_mask(image, radius=1.0, amount=1.0, multichannel=False, preserve_range=False):
551
"""
552
Apply unsharp masking for image sharpening.
553
554
Parameters:
555
image : array_like
556
Input image
557
radius : scalar, optional
558
Standard deviation of Gaussian blur
559
amount : scalar, optional
560
Strength of sharpening
561
multichannel : bool, optional
562
Whether last axis is channels
563
preserve_range : bool, optional
564
Keep original data range
565
566
Returns:
567
ndarray
568
Sharpened image
569
"""
570
```
571
572
### Gabor Filters
573
574
Apply Gabor filters for texture analysis and feature extraction.
575
576
```python { .api }
577
def gabor(image, frequency, theta=0, bandwidth=1, sigma_x=None, sigma_y=None, n_stds=3, offset=0, mode='reflect', cval=0):
578
"""
579
Apply Gabor filter for texture analysis.
580
581
Parameters:
582
image : array_like
583
Input image
584
frequency : float
585
Spatial frequency of harmonic function
586
theta : float, optional
587
Orientation of normal to parallel stripes
588
bandwidth : float, optional
589
Bandwidth of filter
590
sigma_x : float, optional
591
Standard deviation in x direction
592
sigma_y : float, optional
593
Standard deviation in y direction
594
n_stds : scalar, optional
595
Number of standard deviations
596
offset : float, optional
597
Phase offset
598
mode : str, optional
599
Boundary condition mode
600
cval : scalar, optional
601
Value for constant mode
602
603
Returns:
604
tuple of ndarrays
605
Real and imaginary responses
606
"""
607
608
def gabor_kernel(frequency, theta=0, bandwidth=1, sigma_x=None, sigma_y=None, n_stds=3, offset=0):
609
"""
610
Generate Gabor kernel.
611
612
Parameters:
613
frequency : float
614
Spatial frequency of harmonic function
615
theta : float, optional
616
Orientation of normal to parallel stripes
617
bandwidth : float, optional
618
Bandwidth of filter
619
sigma_x : float, optional
620
Standard deviation in x direction
621
sigma_y : float, optional
622
Standard deviation in y direction
623
n_stds : scalar, optional
624
Number of standard deviations
625
offset : float, optional
626
Phase offset
627
628
Returns:
629
tuple of ndarrays
630
Real and imaginary parts of kernel
631
"""
632
```
633
634
## Usage Examples
635
636
### Basic Edge Detection
637
638
```python
639
from skimage import data, filters
640
import matplotlib.pyplot as plt
641
642
# Load image
643
image = data.camera()
644
645
# Apply different edge detection filters
646
sobel_edges = filters.sobel(image)
647
canny_edges = filters.canny(image, sigma=1.0, low_threshold=0.1, high_threshold=0.2)
648
prewitt_edges = filters.prewitt(image)
649
650
# Display results
651
fig, axes = plt.subplots(2, 2, figsize=(10, 8))
652
axes[0, 0].imshow(image, cmap='gray')
653
axes[0, 0].set_title('Original')
654
axes[0, 1].imshow(sobel_edges, cmap='gray')
655
axes[0, 1].set_title('Sobel')
656
axes[1, 0].imshow(canny_edges, cmap='gray')
657
axes[1, 0].set_title('Canny')
658
axes[1, 1].imshow(prewitt_edges, cmap='gray')
659
axes[1, 1].set_title('Prewitt')
660
plt.show()
661
```
662
663
### Noise Reduction and Enhancement
664
665
```python
666
from skimage import data, filters, util
667
import numpy as np
668
669
# Load image and add noise
670
image = data.camera()
671
noisy = util.random_noise(image, mode='gaussian', var=0.01)
672
673
# Apply different filters
674
gaussian_filtered = filters.gaussian(noisy, sigma=1.0)
675
median_filtered = filters.median(noisy, disk(2))
676
unsharp_filtered = filters.unsharp_mask(image, radius=1.0, amount=2.0)
677
678
# Compare results
679
print(f"Original PSNR: {util.compare_psnr(image, noisy):.2f}")
680
print(f"Gaussian PSNR: {util.compare_psnr(image, gaussian_filtered):.2f}")
681
print(f"Median PSNR: {util.compare_psnr(image, median_filtered):.2f}")
682
```
683
684
### Automatic Thresholding
685
686
```python
687
from skimage import data, filters
688
import numpy as np
689
690
# Load grayscale image
691
image = data.coins()
692
693
# Apply different thresholding methods
694
otsu_thresh = filters.threshold_otsu(image)
695
yen_thresh = filters.threshold_yen(image)
696
li_thresh = filters.threshold_li(image)
697
698
# Create binary images
699
otsu_binary = image > otsu_thresh
700
yen_binary = image > yen_thresh
701
li_binary = image > li_thresh
702
703
print(f"Otsu threshold: {otsu_thresh:.2f}")
704
print(f"Yen threshold: {yen_thresh:.2f}")
705
print(f"Li threshold: {li_thresh:.2f}")
706
```
707
708
## Types
709
710
```python { .api }
711
from typing import Union, Optional, Tuple, Sequence, Callable
712
from numpy.typing import NDArray
713
import numpy as np
714
715
# Filter parameters
716
Sigma = Union[float, Sequence[float]]
717
Footprint = Optional[NDArray[np.bool_]]
718
BoundaryMode = str
719
ThresholdMethod = str
720
FilterResponse = Union[NDArray[np.floating], Tuple[NDArray[np.floating], NDArray[np.floating]]]
721
```
722
723
### Advanced Edge Detection
724
725
Extended edge detection operators with directional variants.
726
727
```python { .api }
728
def farid_h(image, *, mask=None):
729
"""
730
Find horizontal edges using the Farid transform.
731
732
Parameters:
733
image : array_like
734
Input image
735
mask : array_like, optional
736
Binary mask for selective filtering
737
738
Returns:
739
ndarray
740
Horizontal edges response
741
"""
742
743
def farid_v(image, *, mask=None):
744
"""
745
Find vertical edges using the Farid transform.
746
747
Parameters:
748
image : array_like
749
Input image
750
mask : array_like, optional
751
Binary mask for selective filtering
752
753
Returns:
754
ndarray
755
Vertical edges response
756
"""
757
758
def prewitt_h(image, *, mask=None):
759
"""
760
Find horizontal edges using the Prewitt operator.
761
762
Parameters:
763
image : array_like
764
Input image
765
mask : array_like, optional
766
Binary mask for selective filtering
767
768
Returns:
769
ndarray
770
Horizontal edges response
771
"""
772
773
def prewitt_v(image, *, mask=None):
774
"""
775
Find vertical edges using the Prewitt operator.
776
777
Parameters:
778
image : array_like
779
Input image
780
mask : array_like, optional
781
Binary mask for selective filtering
782
783
Returns:
784
ndarray
785
Vertical edges response
786
"""
787
788
def scharr_h(image, *, mask=None):
789
"""
790
Find horizontal edges using the Scharr operator.
791
792
Parameters:
793
image : array_like
794
Input image
795
mask : array_like, optional
796
Binary mask for selective filtering
797
798
Returns:
799
ndarray
800
Horizontal edges response
801
"""
802
803
def scharr_v(image, *, mask=None):
804
"""
805
Find vertical edges using the Scharr operator.
806
807
Parameters:
808
image : array_like
809
Input image
810
mask : array_like, optional
811
Binary mask for selective filtering
812
813
Returns:
814
ndarray
815
Vertical edges response
816
"""
817
818
def roberts_pos_diag(image, *, mask=None):
819
"""
820
Find edges using the Roberts cross-gradient positive diagonal operator.
821
822
Parameters:
823
image : array_like
824
Input image
825
mask : array_like, optional
826
Binary mask for selective filtering
827
828
Returns:
829
ndarray
830
Positive diagonal edges response
831
"""
832
833
def roberts_neg_diag(image, *, mask=None):
834
"""
835
Find edges using the Roberts cross-gradient negative diagonal operator.
836
837
Parameters:
838
image : array_like
839
Input image
840
mask : array_like, optional
841
Binary mask for selective filtering
842
843
Returns:
844
ndarray
845
Negative diagonal edges response
846
"""
847
```
848
849
### Frequency Domain Filters
850
851
Frequency domain filtering operations and signal processing filters.
852
853
```python { .api }
854
def butterworth(image, cutoff_frequency_ratio=0.005, high_pass=True, order=2.0, channel_axis=None, *, squared_butterworth=True, npad=0):
855
"""
856
Apply a Butterworth filter to enhance high or low frequency features.
857
858
Parameters:
859
image : array_like
860
Input image
861
cutoff_frequency_ratio : float, optional
862
Cutoff frequency ratio relative to Nyquist frequency
863
high_pass : bool, optional
864
Whether to apply high-pass (True) or low-pass (False) filter
865
order : float, optional
866
Filter order parameter
867
channel_axis : int, optional
868
Axis of color channels
869
squared_butterworth : bool, optional
870
Whether to use squared Butterworth filter
871
npad : int, optional
872
Padding size for boundary effects
873
874
Returns:
875
ndarray
876
Filtered image
877
"""
878
879
def wiener(data, impulse_response=None, filter_params=None, K=0.25, predefined_filter=None):
880
"""
881
Minimum Mean Square Error (Wiener) inverse filter.
882
883
Parameters:
884
data : array_like
885
Input data to be filtered
886
impulse_response : callable, optional
887
Function defining the impulse response
888
filter_params : dict, optional
889
Parameters for the impulse response function
890
K : float or array_like, optional
891
Ratio between power spectrum of noise and undegraded signal
892
predefined_filter : str, optional
893
Name of predefined filter to use
894
895
Returns:
896
ndarray
897
Filtered data
898
"""
899
900
class LPIFilter2D:
901
"""
902
Linear Position-Invariant Filter (2-dimensional).
903
904
A class implementing 2D linear position-invariant filtering operations
905
using impulse response functions.
906
"""
907
908
def __init__(self, impulse_response, **filter_params):
909
"""
910
Initialize the LPI filter.
911
912
Parameters:
913
impulse_response : callable
914
Function that yields the impulse response
915
**filter_params : keyword arguments
916
Additional parameters for the impulse response function
917
"""
918
919
def filter_forward(data, impulse_response=None, filter_params=None, predefined_filter=None):
920
"""
921
Apply a linear filter with a predefined or custom impulse response.
922
923
Parameters:
924
data : array_like
925
Input data
926
impulse_response : callable, optional
927
Custom impulse response function
928
filter_params : dict, optional
929
Parameters for impulse response function
930
predefined_filter : str, optional
931
Name of predefined filter
932
933
Returns:
934
ndarray
935
Filtered data
936
"""
937
938
def filter_inverse(data, impulse_response=None, filter_params=None, predefined_filter=None, max_gain=2):
939
"""
940
Apply an inverse filter with a predefined or custom impulse response.
941
942
Parameters:
943
data : array_like
944
Input data
945
impulse_response : callable, optional
946
Custom impulse response function
947
filter_params : dict, optional
948
Parameters for impulse response function
949
predefined_filter : str, optional
950
Name of predefined filter
951
max_gain : float, optional
952
Maximum gain to prevent amplification of noise
953
954
Returns:
955
ndarray
956
Inverse filtered data
957
"""
958
959
def window(name, shape):
960
"""
961
Generate a window function for filtering applications.
962
963
Parameters:
964
name : str
965
Name of the window function (e.g., 'hann', 'hamming', 'blackman')
966
shape : tuple
967
Shape of the output window
968
969
Returns:
970
ndarray
971
Window function array
972
"""
973
```
974
975
### Rank and Statistical Filters
976
977
Rank-based filtering operations and statistical analysis functions.
978
979
```python { .api }
980
def rank(image, footprint, rank):
981
"""
982
Return the rank-th value from the neighborhood defined by the footprint.
983
984
Parameters:
985
image : array_like
986
Input image
987
footprint : array_like
988
The neighborhood expressed as a 2-D array of 1's and 0's
989
rank : int
990
The rank of the value to return (0-based indexing)
991
992
Returns:
993
ndarray
994
Filtered image
995
"""
996
997
def rank_order(image):
998
"""
999
Return an image of rank-order values for each pixel.
1000
1001
Parameters:
1002
image : array_like
1003
Input image
1004
1005
Returns:
1006
ndarray
1007
Rank-order image where each pixel value represents the rank
1008
of the original pixel value within the image
1009
"""
1010
1011
def correlate_sparse(image, kernel, mode='reflect'):
1012
"""
1013
Compute the correlation of a sparse kernel with an image.
1014
1015
Parameters:
1016
image : array_like
1017
Input image
1018
kernel : sparse matrix
1019
Sparse correlation kernel
1020
mode : str, optional
1021
Boundary mode for correlation
1022
1023
Returns:
1024
ndarray
1025
Correlated image
1026
"""
1027
```
1028
1029
### Additional Thresholding Methods
1030
1031
Extended thresholding algorithms for different image characteristics.
1032
1033
```python { .api }
1034
def threshold_isodata(image, nbins=256):
1035
"""
1036
Return threshold value based on ISODATA method.
1037
1038
Parameters:
1039
image : array_like
1040
Input image
1041
nbins : int, optional
1042
Number of bins used to calculate histogram
1043
1044
Returns:
1045
float
1046
Threshold value
1047
"""
1048
1049
def threshold_mean(image):
1050
"""
1051
Return threshold value based on the mean of image intensities.
1052
1053
Parameters:
1054
image : array_like
1055
Input image
1056
1057
Returns:
1058
float
1059
Threshold value (mean of image)
1060
"""
1061
1062
def threshold_minimum(image, nbins=256, max_num_iter=10000):
1063
"""
1064
Return threshold value based on minimum method.
1065
1066
Parameters:
1067
image : array_like
1068
Input image
1069
nbins : int, optional
1070
Number of bins used to calculate histogram
1071
max_num_iter : int, optional
1072
Maximum number of iterations
1073
1074
Returns:
1075
float
1076
Threshold value
1077
"""
1078
1079
def try_all_threshold(image, figsize=(8, 5), verbose=True):
1080
"""
1081
Compare results of different threshold methods on the same image.
1082
1083
Parameters:
1084
image : array_like
1085
Input image
1086
figsize : tuple, optional
1087
Figure size for the comparison plot
1088
verbose : bool, optional
1089
Whether to print threshold values
1090
1091
Returns:
1092
dict
1093
Dictionary containing threshold values for each method
1094
"""
1095
```