项目作者: ollimacp

项目描述 :
A spacial boxcount algorithm is proposed, which encodes incoming data into scaled down version of itself at diffrent scales discribing spacial resolved complexity and heterogenity.
高级语言: Jupyter Notebook
项目地址: git://github.com/ollimacp/spacial-boxcounting-cpu-gpu.git
创建时间: 2021-01-28T19:00:38Z
项目社区:https://github.com/ollimacp/spacial-boxcounting-cpu-gpu

开源协议:MIT License

下载


spacial-boxcounting: Spatial Boxcount Algorithm & Fractal Analysis

An implementation of a spatial boxcount algorithm for fractal analysis, with an option to use a convolutional neural network to accelerate computation via GPU.

Abstract

This project implements a spatial boxcount algorithm that characterizes 2D arrays by topological complexity and spatial heterogeneity. With both CPU and GPU support, it enables spatial similarity search, edge detection, and statistical analysis of image datasets. The algorithm has been translated into a convolutional neural network for faster processing on compatible hardware.

Installation

Install via pip:

  1. pip install .

Ensure dependencies are installed: numpy, numba, Pillow, matplotlib, hilbertcurve, cupy (optional), and pytest.

Basic Usage

Processing a Single File

  1. from spacial_boxcounting.api import boxcount_from_file, fractal_dimension
  2. # Get spatial box count map
  3. result_spatial = boxcount_from_file('path/to/your/image.jpg', mode='spatial')
  4. print('Spatial Box Count Map:', result_spatial)
  5. # Get overall box count & lacunarity
  6. result_single = boxcount_from_file('path/to/your/image.jpg', mode='single')
  7. print('Box Count & Lacunarity:', result_single)
  8. # Compute fractal dimension
  9. fd = fractal_dimension('path/to/your/image.jpg')
  10. print('Fractal Dimension:', fd)

Processing from a Numpy Array

  1. import numpy as np
  2. from spacial_boxcounting.api import boxcount_from_array
  3. arr = np.random.randint(0, 256, size=(256, 256)).astype(np.uint8)
  4. result = boxcount_from_array(arr, mode='spatial')
  5. print('Spatial Result from Array:', result)

Fractal Dimension from Array or File

  1. from spacial_boxcounting.api import fractal_dimension_from_array, fractal_dimension_from_file
  2. # From array
  3. fd_array = fractal_dimension_from_array(arr)
  4. print('Fractal Dimension (Array):', fd_array)
  5. # From file
  6. fd_file = fractal_dimension_from_file('path/to/your/image.jpg')
  7. print('Fractal Dimension (File):', fd_file)

Batch Processing

Run the CLI to process all files in a directory:

  1. python3 -m spacial_boxcounting.batch path/to/your/input_folder

GPU Acceleration

If Cupy is installed, GPU accelerated functions will execute:

  1. import numpy as np
  2. from spacial_boxcounting.core import spacialBoxcount_gpu, Z_boxcount_gpu
  3. arr = np.random.randint(0, 256, size=(64, 64)).astype(np.uint8)
  4. result_gpu = spacialBoxcount_gpu(arr, iteration=0, MaxValue=256)
  5. print('GPU spatial result:', result_gpu)

Packaging & Distribution

This project is structured as a pip-installable package. Future releases may be distributed via PyPI. Contributions towards expanding its functionality are welcome.

Testing

Run unit tests with:

  1. pytest

Academic Context

Originally derived from academic work in spatial analysis, this repository provides the tools for box counting and lacunarity computation as described in the accompanying Jupyter Notebook. For a full exposition, please review the notebook:
Spacial boxcount algorithm CPU and GPU.ipynb

License

See LICENSE.txt for details.