or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

data-structures.mdfiltering.mdfinite-difference.mdgpu-computing.mdimage-adaptors.mdimage-functions.mdindex.mdio.mdmesh.mdnumpy-integration.mdregistration.mdsegmentation.mdspatial-objects.mdtransforms.md

filtering.mddocs/

0

# Image Filtering

1

2

Comprehensive collection of image processing algorithms for smoothing, enhancement, morphological operations, feature detection, and specialized image transformations. ITK provides both modern functional interfaces and traditional object-oriented approaches for maximum flexibility and ease of use.

3

4

## Capabilities

5

6

### Smoothing Filters

7

8

Noise reduction and image smoothing algorithms including linear and non-linear filters.

9

10

```python { .api }

11

# Median filtering (non-linear, edge-preserving)

12

def median_image_filter(input_image, radius: int | Sequence[int]) -> Image:

13

"""

14

Apply median filtering to reduce noise while preserving edges.

15

16

Parameters:

17

- input_image: Input image to filter

18

- radius: Neighborhood radius (int for isotropic, sequence for anisotropic)

19

20

Returns:

21

- Filtered image with reduced noise

22

"""

23

24

# Gaussian smoothing (linear)

25

def gaussian_blur_image_filter(input_image, variance: float | Sequence[float]) -> Image:

26

"""

27

Apply Gaussian smoothing with specified variance.

28

29

Parameters:

30

- input_image: Input image to smooth

31

- variance: Gaussian variance (float for isotropic, sequence for anisotropic)

32

33

Returns:

34

- Smoothed image

35

"""

36

37

# Mean filtering

38

def mean_image_filter(input_image, radius: int | Sequence[int]) -> Image: ...

39

40

# Bilateral filtering (edge-preserving)

41

def bilateral_image_filter(input_image, domain_sigma: float, range_sigma: float) -> Image: ...

42

43

# Anisotropic diffusion

44

def gradient_anisotropic_diffusion_image_filter(input_image, time_step: float,

45

conductance: float, iterations: int) -> Image: ...

46

```

47

48

### Thresholding

49

50

Binary and multi-level thresholding operations for image segmentation and analysis.

51

52

```python { .api }

53

# Binary thresholding

54

def binary_threshold_image_filter(input_image, lower_threshold, upper_threshold,

55

inside_value=255, outside_value=0) -> Image:

56

"""

57

Apply binary thresholding to create binary image.

58

59

Parameters:

60

- input_image: Input grayscale image

61

- lower_threshold: Lower threshold value

62

- upper_threshold: Upper threshold value

63

- inside_value: Value for pixels within threshold range

64

- outside_value: Value for pixels outside threshold range

65

66

Returns:

67

- Binary thresholded image

68

"""

69

70

# Automatic thresholding methods

71

def otsu_threshold_image_filter(input_image, inside_value=255, outside_value=0) -> Image: ...

72

def huang_threshold_image_filter(input_image, inside_value=255, outside_value=0) -> Image: ...

73

def li_threshold_image_filter(input_image, inside_value=255, outside_value=0) -> Image: ...

74

def triangle_threshold_image_filter(input_image, inside_value=255, outside_value=0) -> Image: ...

75

76

# Multi-level thresholding

77

def otsu_multiple_thresholds_image_filter(input_image, number_of_thresholds: int) -> Image: ...

78

```

79

80

### Mathematical Morphology

81

82

Structural image processing operations using morphological operators.

83

84

```python { .api }

85

# Binary morphology

86

def binary_dilate_image_filter(input_image, kernel_radius: int | Sequence[int],

87

foreground_value=255, background_value=0) -> Image:

88

"""

89

Apply binary dilation to expand foreground regions.

90

91

Parameters:

92

- input_image: Binary input image

93

- kernel_radius: Structuring element radius

94

- foreground_value: Value representing foreground pixels

95

- background_value: Value representing background pixels

96

97

Returns:

98

- Dilated binary image

99

"""

100

101

def binary_erode_image_filter(input_image, kernel_radius: int | Sequence[int],

102

foreground_value=255, background_value=0) -> Image: ...

103

104

def binary_opening_by_reconstruction_image_filter(input_image, kernel_radius: int | Sequence[int]) -> Image: ...

105

def binary_closing_by_reconstruction_image_filter(input_image, kernel_radius: int | Sequence[int]) -> Image: ...

106

107

# Grayscale morphology

108

def grayscale_dilate_image_filter(input_image, kernel_radius: int | Sequence[int]) -> Image: ...

109

def grayscale_erode_image_filter(input_image, kernel_radius: int | Sequence[int]) -> Image: ...

110

def morphological_gradient_image_filter(input_image, kernel_radius: int | Sequence[int]) -> Image: ...

111

112

# Advanced morphological operations

113

def black_top_hat_image_filter(input_image, kernel_radius: int | Sequence[int]) -> Image: ...

114

def white_top_hat_image_filter(input_image, kernel_radius: int | Sequence[int]) -> Image: ...

115

```

116

117

### Image Enhancement

118

119

Filters for improving image quality, contrast, and feature visibility.

120

121

```python { .api }

122

# Gradient and edge detection

123

def gradient_magnitude_image_filter(input_image) -> Image:

124

"""

125

Compute gradient magnitude for edge detection.

126

127

Parameters:

128

- input_image: Input grayscale image

129

130

Returns:

131

- Gradient magnitude image highlighting edges

132

"""

133

134

def laplacian_image_filter(input_image) -> Image: ...

135

def zero_crossing_image_filter(input_image) -> Image: ...

136

def canny_edge_detection_image_filter(input_image, variance: float,

137

upper_threshold: float, lower_threshold: float) -> Image: ...

138

139

# Contrast enhancement

140

def histogram_equalization_image_filter(input_image) -> Image: ...

141

def adaptive_histogram_equalization_image_filter(input_image, radius: Sequence[int]) -> Image: ...

142

def rescale_intensity_image_filter(input_image, output_minimum=0, output_maximum=255) -> Image: ...

143

144

# Sharpening

145

def laplacian_sharpening_image_filter(input_image) -> Image: ...

146

def unsharp_mask_image_filter(input_image, sigma: float, amount: float) -> Image: ...

147

```

148

149

### Frequency Domain Processing

150

151

FFT-based filtering and frequency domain transformations.

152

153

```python { .api }

154

# FFT operations

155

def forward_fft_image_filter(input_image) -> Image: ...

156

def inverse_fft_image_filter(input_image) -> Image: ...

157

def fft_shift_image_filter(input_image) -> Image: ...

158

159

# Frequency filtering

160

def fft_normalize_image_filter(input_image) -> Image: ...

161

def butterworth_band_pass_image_filter(input_image, cutoff_frequency: float, order: int) -> Image: ...

162

163

# Convolution

164

def convolution_image_filter(input_image, kernel: Image) -> Image: ...

165

def fft_convolution_image_filter(input_image, kernel: Image) -> Image: ...

166

```

167

168

### Traditional Object-Oriented Interface

169

170

Classical ITK filter interface for advanced parameter control and pipeline construction.

171

172

```python { .api }

173

class MedianImageFilter[InputImageType, OutputImageType]:

174

"""Median filtering with configurable neighborhood."""

175

def SetRadius(self, radius: int | Sequence[int]) -> None: ...

176

def GetRadius(self) -> Sequence[int]: ...

177

def SetInput(self, input: InputImageType) -> None: ...

178

def GetOutput(self) -> OutputImageType: ...

179

def Update(self) -> None: ...

180

181

class BinaryThresholdImageFilter[InputImageType, OutputImageType]:

182

"""Binary thresholding with configurable threshold values."""

183

def SetLowerThreshold(self, threshold: PixelType) -> None: ...

184

def SetUpperThreshold(self, threshold: PixelType) -> None: ...

185

def SetInsideValue(self, value: OutputPixelType) -> None: ...

186

def SetOutsideValue(self, value: OutputPixelType) -> None: ...

187

188

class GaussianBlurImageFilter[InputImageType, OutputImageType]:

189

"""Gaussian smoothing with variance control."""

190

def SetVariance(self, variance: float | Sequence[float]) -> None: ...

191

def SetMaximumKernelWidth(self, width: int) -> None: ...

192

def SetMaximumError(self, error: float) -> None: ...

193

194

class GradientMagnitudeImageFilter[InputImageType, OutputImageType]:

195

"""Gradient magnitude computation for edge detection."""

196

def SetUseImageSpacing(self, use_spacing: bool) -> None: ...

197

```

198

199

## Usage Examples

200

201

### Basic Filtering Workflow

202

203

```python

204

import itk

205

206

# Load image

207

image = itk.imread('input.png')

208

209

# Apply median filter to reduce noise

210

smoothed = itk.median_image_filter(image, radius=2)

211

212

# Apply binary thresholding

213

binary = itk.binary_threshold_image_filter(smoothed,

214

lower_threshold=100,

215

upper_threshold=255)

216

217

# Apply morphological opening to clean up binary image

218

cleaned = itk.binary_opening_by_reconstruction_image_filter(binary, kernel_radius=3)

219

220

# Save result

221

itk.imwrite(cleaned, 'output.png')

222

```

223

224

### Advanced Pipeline Construction

225

226

```python

227

import itk

228

229

# Create filter pipeline using object-oriented interface

230

image = itk.imread('noisy_image.png')

231

232

# Set up Gaussian smoothing

233

gaussian = itk.GaussianBlurImageFilter.New(image)

234

gaussian.SetVariance(1.5)

235

236

# Set up Otsu thresholding

237

otsu = itk.OtsuThresholdImageFilter.New(gaussian)

238

otsu.SetInsideValue(255)

239

otsu.SetOutsideValue(0)

240

241

# Set up morphological closing

242

closing = itk.BinaryMorphologicalClosingImageFilter.New(otsu)

243

closing.SetKernelRadius(2)

244

245

# Execute pipeline

246

closing.Update()

247

result = closing.GetOutput()

248

249

# Save result

250

itk.imwrite(result, 'processed.png')

251

```

252

253

### Multi-scale Processing

254

255

```python

256

import itk

257

258

def multi_scale_enhancement(image, scales=[1.0, 2.0, 4.0]):

259

"""Multi-scale enhancement using Gaussian derivatives."""

260

enhanced_images = []

261

262

for scale in scales:

263

# Apply Gaussian smoothing at current scale

264

smoothed = itk.gaussian_blur_image_filter(image, variance=scale)

265

266

# Compute gradient magnitude

267

gradient = itk.gradient_magnitude_image_filter(smoothed)

268

enhanced_images.append(gradient)

269

270

# Combine scales (simplified - could use more sophisticated combination)

271

result = enhanced_images[0]

272

for enhanced in enhanced_images[1:]:

273

result = itk.add_image_filter(result, enhanced)

274

275

return result

276

277

# Apply multi-scale enhancement

278

image = itk.imread('vessel_image.png')

279

enhanced = multi_scale_enhancement(image)

280

itk.imwrite(enhanced, 'enhanced_vessels.png')

281

```