read-vk6
A fast and simple Rust library for reading VK6/VK7 files from Keyence confocal laser scanning microscopes (VK-X series), such as the VK-X1000 and VK-X3000.
This library extracts:
- Height maps (surface topography in micrometers)
- RGB optical images (when available)
- Comprehensive metadata (75+ fields including timestamp, lens info, measurement settings, camera parameters, etc.)
Inspired by the excellent Surfalize Python library.
Features
- ✨ Simple API: read a VK6 file in one function call
- 🚀 Fast native Rust implementation
- 📊 Returns data as
ndarrayarrays ready for scientific computing - 🎨 Optional RGB image extraction
- 📝 Comprehensive metadata extraction (75+ measurement and camera settings fields)
- 🔬 Preserves all measurement conditions from the original file
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Usage
use ;
use Path;
Read without RGB image
If you only need the height map and want to skip image processing:
let surface = read_vk6?;
Data Structure
The RawSurface struct contains:
Metadata Fields
The Metadata struct contains 75+ fields extracted from the VK6 file, including:
Basic Information:
title,lens_name,timestamp,diff_from_utc
Optical Settings:
optical_zoom,objective_magnification,lens_id,num_aperturend_filter,light_filter_type,head_type
Measurement Settings:
run_mode,peak_mode,speed,distance,pitchsharpening_level,plane_compensation
Camera & PMT Settings:
pmt_gain_mode,pmt_gain,pmt_gain_2,pmt_offsetcamera_gain,shutter_speed_mode,shutter_speedwhite_balance_mode,white_balance_red,white_balance_blue
Resolution & Units:
x_length_per_pixel,y_length_per_pixel,z_length_per_digit(in picometers)xy_length_unit,z_length_unit,xy_decimal_place,z_decimal_placeheight_effective_bit_depth,light_effective_bit_depth
Image Processing:
gamma,gamma_reverse,gamma_correction_offsetlight_lut_modeand LUT parameters (light_lut_in0-4,light_lut_out0-4)img_attributes,color_composite_mode,img_layer_number
And many more... See src/types.rs for the complete list.
Use the summary() method for a quick overview:
println!;
Example: See examples/show_metadata.rs for a complete demonstration of all metadata fields:
Example: Export to NumPy and PNG
See tests/integration.rs for a complete example that:
- Reads a VK6 file
- Exports the height map as a NumPy
.npyfile - Exports the RGB image as a PNG
Run the test:
# Place your VK6 file at tests/data/sample.vk6
This will create:
tests/out/height.npy- Height map arraytests/out/rgb.png- RGB optical image
Visualizing Results with Streamlit
A simple Streamlit app is included to visualize the extracted data:
# Install uv if you haven't already
|
# Place your VK6 file at tests/data/sample.vk6
# Run the viewer
The app will display:
- Height map with colorbar
- RGB optical image
File Format Support
Currently supports:
- ✅ VK6 files (tested)
- 🔄 VK7 files (uses same internal format, should work)
The library reads the embedded Vk4File from the ZIP archive and parses:
- Measurement conditions
- Height layer (16-bit or 32-bit depth)
- Color/Light layer (RGB image)
- String data (title, lens)
Dependencies
ndarray- Multi-dimensional arraysbyteorder- Binary data parsingzip- ZIP archive handlingchrono- Timestamp parsingthiserror- Error handling
Contributing
Contributions welcome! This library was created to provide a Rust alternative for reading Keyence microscope files. If you encounter issues with specific VK6/VK7 files or have suggestions, please open an issue.
License
MIT License. See LICENSE-MIT for details.
Acknowledgments
- Inspired by Surfalize by Frederic Schell
- Format information based on reverse engineering of VK6 file structure