AI/ML & Data Science / TamuraTexture
Tamura Texture Features in Python
A comprehensive Python implementation of Tamura texture features for image analysis, supporting both NumPy and TensorFlow backends.
Open the full technical write-up
A comprehensive Python implementation of Tamura texture features for image analysis, supporting both NumPy and TensorFlow backends.
What this project does
This project implements the six Tamura texture features as described in the original paper:
Tamura, H., Mori, S., & Yamawaki, T. (1978). Textural features corresponding to visual perception. IEEE Transactions on Systems, Man, and Cybernetics, 8(6), 460-473.
Features Implemented
- Coarseness - Measures the scale of texture primitives
- Contrast - Measures the intensity difference between pixels
- Directionality - Measures the degree of directional patterns
- Linelikeness - Measures the presence of line-like structures
- Regularity - Measures the uniformity of texture patterns
- Roughness - Combined measure of coarseness and contrast
Installation
Prerequisites
- Python 3.7 or higher
- Windows 10/11 (for the batch file)
Quick Start
- Clone or download this repository
- Run the setup script:
This will automatically:run.bat- Create a virtual environment
- Install all required dependencies
- Provide an interactive menu for analysis
Manual Installation
-
Create a virtual environment:
python -m venv venv -
Activate the virtual environment:
# Windows venv\Scripts\activate # Linux/Mac source venv/bin/activate -
Install dependencies:
pip install -r requirements.txt
Usage
Command Line Interface
Basic Usage
python tamura_features.py [options]
Examples
# Analyze with NumPy backend (default)
python tamura_features.py test.jpg
# Analyze with TensorFlow backend
python tamura_features.py test.jpg --backend tensorflow
# Save results to file
python tamura_features.py test.jpg --output results.txt
# Compare both backends
python tamura_features.py test.jpg --backend numpy --output numpy_results.txt
python tamura_features.py test.jpg --backend tensorflow --output tf_results.txt
Programmatic Usage
from tamura_features import TamuraFeatures
# Initialize with NumPy backend
calculator = TamuraFeatures(backend='numpy')
# Compute all features
features = calculator.compute_all_features('path/to/image.jpg')
print(features)
# Compute individual features
image = calculator.load_image('path/to/image.jpg')
coarseness = calculator.coarseness(image)
contrast = calculator.contrast(image)
# ... etc
Interactive Batch File
Simply double-click run.bat for an interactive experience that:
- Sets up the environment automatically
- Provides menu options for different backends
- Handles test images automatically
- Offers comparison between backends
Backend Comparison
| Feature | NumPy Backend | TensorFlow Backend |
|---|---|---|
| Speed | Faster for small images | Faster for large images |
| Memory | Lower memory usage | Higher memory usage |
| GPU Support | CPU only | GPU acceleration available |
| Dependencies | Minimal | TensorFlow ecosystem |
| Precision | Slightly different due to implementation | Slightly different due to implementation |
API Reference
TamuraFeatures Class
Constructor
TamuraFeatures(backend='numpy')
backend: 'numpy' or 'tensorflow'
Methods
load_image(image_path: str)`
Load and preprocess an image for analysis.
coarseness(image, kmax=5)`
Compute coarseness feature.
kmax: Maximum scale factor (default: 5)
contrast(image)`
Compute contrast feature.
directionality(image)`
Compute directionality feature.
linelikeness(image, theta=0.0, dist=4)`
Compute linelikeness feature.
theta: Orientation angle (default: 0.0)dist: Distance parameter (default: 4)
regularity(image, filter_size=64)`
Compute regularity feature.
filter_size: Size of the filter (default: 64)
roughness(fcrs, fcon)`
Compute roughness feature.
fcrs: Coarseness valuefcon: Contrast value
compute_all_features(image_path: str)`
Compute all Tamura features for an image and return as dictionary.
Requirements
opencv-python>=4.5.0- Image processingnumpy>=1.21.0- Numerical computationstensorflow>=2.8.0- TensorFlow backend (optional)
File Structure
Tamura-In-Python/
├── tamura_features.py # Main implementation
├── run.bat # Windows setup and run script
├── requirements.txt # Python dependencies
├── test.jpg # Sample test image
├── README.md # This file
├── .gitignore # Git ignore rules
└── venv/ # Virtual environment (created by setup)
Performance Notes
- NumPy Backend: Optimized for CPU processing, faster for smaller images
- TensorFlow Backend: Can utilize GPU acceleration, better for large images
- Memory Usage: TensorFlow backend uses more memory due to graph construction
- Precision: Small numerical differences between backends are expected
Troubleshooting
Common Issues
-
"ModuleNotFoundError: No module named 'cv2'"
- Solution: Activate the virtual environment first
- Run:
venv\Scripts\activate(Windows) orsource venv/bin/activate(Linux/Mac)
-
"TensorFlow not available"
- Solution: Install TensorFlow with
pip install tensorflow - Or use NumPy backend:
--backend numpy
- Solution: Install TensorFlow with
-
"Image file not found"
- Solution: Check the image path is correct
- Ensure the image file exists and is readable
-
Performance Issues
- For large images, try TensorFlow backend with GPU
- For small images, use NumPy backend
- Consider resizing images if memory is limited
Getting Help
- Check that all dependencies are installed correctly
- Ensure Python 3.7+ is being used
- Verify image file format is supported (JPG, PNG, etc.)
- Check file permissions for image access
Contributing
This implementation provides a solid foundation for Tamura texture analysis. Potential improvements:
- Additional texture feature implementations
- GPU optimization for NumPy backend
- Batch processing capabilities
- Visualization tools for feature analysis
License
This project implements academic research from the original Tamura paper. Please cite the original work when using this implementation in research.
Citation
If you use this implementation in your research, please cite:
@article{tamura1978textural,
title={Textural features corresponding to visual perception},
author={Tamura, Hideyuki and Mori, Shunji and Yamawaki, Takashi},
journal={IEEE Transactions on Systems, Man, and Cybernetics},
volume={8},
number={6},
pages={460--473},
year={1978},
publisher={IEEE}
}