Application Scenarios
The CFAImageFD class is used to calculate the fractal dimension of 2D images, serving as an important tool for image complexity analysis and texture feature extraction. Main application scenarios include:
- Image Texture Analysis: Quantify image roughness and complexity
- Medical Image Analysis: Analyze tissue structure complexity
- Materials Science: Study fractal features of material surfaces
- Computer Vision: Image feature extraction and classification
- Geology: Terrain and landform complexity analysis
Usage Examples
Basic Usage
GPU Accelerated Version
Batch Processing
Installation
Class Description
CFAImageFD
Description: Class for calculating 2D image fractal dimensions, supporting three different calculation methods: Box-Counting (BC), Differential Box-Counting (DBC), and Shifted DBC (SDBC).
Initialization Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
image | numpy.ndarray | Required | Input image (single channel) |
max_size | int | None | Maximum box size (default: minimum image dimension) |
max_scales | int | 30 | Maximum number of scales |
with_progress | bool | True | Whether to show progress bar |
min_size | int | 2 | Minimum box size |
Main Methods
1. get_bc_fd(corp_type=-1, fit_range=None)
Description: Calculate fractal dimension using Box-Counting (BC) method.
Parameters:
corp_type(int): Image cropping method-1: Auto crop to multiples of box size0: No processing (requires image dimensions to be multiples of box size)1: Padding
fit_range(tuple or None): Optional(min_scale, max_scale)to restrict log-log fit range
Return Value (dict):
Use Case: Suitable for binary images, calculating the dimension of occupied space.
2. get_dbc_fd(corp_type=-1, fit_range=None)
Description: Calculate fractal dimension using Differential Box-Counting (DBC) method (Sarkar & Chaudhuri 1994). Uses n_r = ceil(I_max/h) - ceil(I_min/h) + 1.
Parameters: Same as get_bc_fd
Return Value: Same as get_bc_fd
Use Case: Suitable for grayscale images, considering grayscale information in fractal dimension calculation.
3. get_sdbc_fd(corp_type=-1, fit_range=None)
Description: Calculate fractal dimension using Shifted DBC (SDBC) method (Chen 1995). Uses n_r = floor((I_max - I_min)/h) + 1.
Parameters: Same as get_bc_fd
Return Value: Same as get_bc_fd
Use Case: SDBC is a simplified version of DBC, faster computation, suitable for grayscale images.
4. get_fd(scale_list, box_count_list)
Description: Utility method to perform log-log fit on custom scale and count data.
Parameters:
scale_list: List of scale valuesbox_count_list: Corresponding box counts
Return Value: Same dict structure as get_bc_fd
5. plot(raw_img, gray_img, bin_img, fd_bc, fd_dbc, fd_sdbc)
Description: Static method to visualize original image, grayscale image, binary image, and fitting results of three fractal dimensions.
Parameters:
raw_img: Original RGB imagegray_img: Grayscale imagebin_img: Binary imagefd_bc: BC method result dictionaryfd_dbc: DBC method result dictionaryfd_sdbc: SDBC method result dictionary
6. get_batch_bc / get_batch_dbc / get_batch_sdbc(images, ...)
Description: Static methods for batch processing of multiple images.
Parameters:
images(list): List of input images- Additional keyword arguments passed to the corresponding single-image method
Return Value: List of result dictionaries
Algorithm Description
BC (Box-Counting) Method
The box-counting method calculates fractal dimension by counting the number of non-empty boxes needed to cover the image at different scales. Formula:
Where N(ε) is the number of boxes at scale ε.
DBC (Differential Box-Counting) Method
DBC considers grayscale height information, treating the image as a 3D surface. The height of each box is:
Where h = max_val / (image_size / r) is the height of a grayscale unit.
SDBC (Simplified DBC) Method
Shifted DBC uses a simplified height calculation:
This avoids the rounding artefact in the original DBC formula.
Important Notes
- Image Preprocessing:
- BC method requires binary images, recommend using Otsu auto-thresholding
- DBC and SDBC methods are suitable for grayscale images
- Scale Selection:
max_sizeaffects the scale range of analysismax_scalesaffects sampling density, recommend default value 30- Use
fit_rangeto exclude unreliable small/large scales
- Result Interpretation:
- Fractal dimension range typically 1-2 (for 2D images)
- Larger values indicate more complex images
r_valueclose to 1 indicates good power-law fit
- Performance Optimization:
- For large images, can downsample first
- Set
with_progress=Falseto improve computation speed - Use GPU version (
CFAImageFDGPU) for batch processing - Note: GPU version sets
p_value=None(not computed)
References
- Mandelbrot, B. B. (1982). The Fractal Geometry of Nature.
- Sarkar, N., & Chaudhuri, B. B. (1994). An efficient differential box-counting approach to compute fractal dimension of image. IEEE Transactions on Systems, Man, and Cybernetics.
- Chen, W. S., et al. (1995). Efficient fractal coding of images based on differential box counting. Pattern Recognition.