| Crates.io | read-vk6 |
| lib.rs | read-vk6 |
| version | 0.1.0 |
| created_at | 2025-11-18 12:55:57.353125+00 |
| updated_at | 2025-11-18 12:55:57.353125+00 |
| description | Fast and simple reader for VK6/VK7 files from Keyence confocal laser scanning microscopes |
| homepage | |
| repository | https://github.com/beneficial01/read-vk6 |
| max_upload_size | |
| id | 1938413 |
| size | 347,549 |
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:
Inspired by the excellent Surfalize Python library.
ndarray arrays ready for scientific computingAdd this to your Cargo.toml:
[dependencies]
read-vk6 = "0.1.0"
use read_vk6::{read_vk6, RawSurface};
use std::path::Path;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Read VK6 file with RGB image
let surface = read_vk6(Path::new("sample.vk6"), true)?;
// Access height map (µm)
println!("Height map shape: {:?}", surface.height.dim());
println!("Step X: {} µm/pixel", surface.step_x);
println!("Step Y: {} µm/pixel", surface.step_y);
// Access metadata
if let Some(title) = &surface.metadata.title {
println!("Title: {}", title);
}
if let Some(timestamp) = &surface.metadata.timestamp {
println!("Timestamp: {}", timestamp);
}
// Access RGB image if available
if let Some(rgb) = &surface.rgb_image {
println!("RGB image shape: {:?}", rgb.dim());
}
Ok(())
}
If you only need the height map and want to skip image processing:
let surface = read_vk6(Path::new("sample.vk6"), false)?;
The RawSurface struct contains:
pub struct RawSurface {
pub height: Array2<f64>, // Height map in micrometers (rows, cols)
pub step_x: f64, // µm per pixel in X direction
pub step_y: f64, // µm per pixel in Y direction
pub metadata: Metadata, // Comprehensive file metadata
pub rgb_image: Option<Array3<u8>>, // RGB image (rows, cols, 3) if available
}
The Metadata struct contains 75+ fields extracted from the VK6 file, including:
Basic Information:
title, lens_name, timestamp, diff_from_utcOptical Settings:
optical_zoom, objective_magnification, lens_id, num_aperturend_filter, light_filter_type, head_typeMeasurement Settings:
run_mode, peak_mode, speed, distance, pitchsharpening_level, plane_compensationCamera & 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_blueResolution & 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_depthImage Processing:
gamma, gamma_reverse, gamma_correction_offsetlight_lut_mode and LUT parameters (light_lut_in0-4, light_lut_out0-4)img_attributes, color_composite_mode, img_layer_numberAnd many more... See src/types.rs for the complete list.
Use the summary() method for a quick overview:
println!("{}", surface.metadata.summary());
Example: See examples/show_metadata.rs for a complete demonstration of all metadata fields:
cargo run --example show_metadata
See tests/integration.rs for a complete example that:
.npy fileRun the test:
# Place your VK6 file at tests/data/sample.vk6
cargo test --test integration -- --nocapture
This will create:
tests/out/height.npy - Height map arraytests/out/rgb.png - RGB optical imageA simple Streamlit app is included to visualize the extracted data:
# Install uv if you haven't already
curl -LsSf https://astral.sh/uv/install.sh | sh
# Place your VK6 file at tests/data/sample.vk6
cargo test --test integration -- --nocapture
# Run the viewer
uv run streamlit run streamlit_app.py
The app will display:
Currently supports:
The library reads the embedded Vk4File from the ZIP archive and parses:
ndarray - Multi-dimensional arraysbyteorder - Binary data parsingzip - ZIP archive handlingchrono - Timestamp parsingthiserror - Error handlingContributions 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.
MIT License. See LICENSE-MIT for details.