A high-performance Python toolset to batch convert .mrc
files (e.g., tilt series, tomograms) into movies or PNG image slices with enhanced contrast. Perfect for quickly assessing data quality, sharing results, or creating presentations.
- Batch Processing: Convert multiple
.mrc
files in a directory into movies or PNG slices - Contrast Enhancement: Apply CLAHE (Contrast Limited Adaptive Histogram Equalization) for balanced contrast
- Global Normalization: Normalize slices using global min/max values for consistent contrast
- Frame Resizing: Automatically resizes frames to match output dimensions, fixing issues with small MRC files
- Playback Direction: Choose between forward-only or forward-backward playback (for movies)
- Discard Slices: Discard a range of slices or a percentage of slices from the beginning and end
- PNG Output: Save processed slices as PNG images
- Rich Logging: Detailed information and errors logged to
mrc2movie.log
ormrc2png.log
- Progress Bars: Visual feedback for slice and tomogram processing
- Customizable Parameters: Control frame rate, CLAHE settings, video codec, and more
-
Clone the Repository:
git clone https://github.com/elemeng/mrc-converter.git cd mrc-converter
-
Install:
# Install UV if not already installed pip install uv # Create virtual environment and install dependencies uv sync uv pip install -e .
-
Verify Installation:
mrc2movie --version mrc2png --version
Use the mrc2png.py
script to convert an MRC file into PNG image slices. This is useful for visualizing individual slices or preparing data for further analysis.
python mrc2png.py input.mrc output_dir [options]
Argument | Description | Default Value |
---|---|---|
input.mrc |
Path to the input .mrc file. |
Required |
output_dir |
Directory to save output PNG files. | Required |
--discard_range |
Discard slices from START to END (0-based indexing). |
None |
--discard_percentage |
Discard START_PERCENT from the beginning and END_PERCENT from the end. |
None |
--output_size |
Resize output images to a maximum dimension of SIZE . |
1024 |
python mrc2png.py example.mrc output_images --discard_percentage 0.1 0.1 --output_size 512
Use the mrc2movie.py
script to convert an MRC file into a video. This is ideal for creating animations of tomographic data.
python mrc2movie.py input_directory output_directory [options]
Argument | Description | Default Value |
---|---|---|
input_directory |
Directory containing .mrc files. |
Required |
output_directory |
Directory to save output movies. | Required |
--fps |
Frame rate for the output movie. For built tomogram, 20 |
30.0 |
--clip_limit |
CLAHE clip limit for contrast enhancement. For tilt series, you try 30~1000 or more large number to enhance contrast. | 2.0 |
--tile_grid_size |
CLAHE tile grid size (controls local contrast granularity). | 8 |
--codec |
Video codec (e.g., MJPG , XVID , DIVX ). |
MJPG |
--playback |
Playback direction: forward or forward-backward . |
forward-backward |
--discard_range |
Discard slices from START to END (0-based indexing). |
None |
--discard_percentage |
Discard START_PERCENT from the beginning and END_PERCENT from the end. |
None |
--png |
Save processed slices as PNG files in addition to video output. | False |
--output_size |
Resize output video and images to a maximum dimension of SIZE . |
1024 |
python mrc2movie.py input_mrcs output_videos --fps 25 --clip_limit 3.0 --png --output_size 768
# Generate API documentation
pdoc --html --output-dir docs src/
We welcome contributions! Here's how to get started:
- Fork the repository
- Create a feature branch (
git checkout -b feature/your-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin feature/your-feature
) - Create a new Pull Request
Please ensure your code:
- Follows PEP 8 style guidelines
- Includes type hints
- Updates documentation as needed
-
CLAHE Parameters:
- Adjust
clip_limit
andtile_grid_size
to balance contrast enhancement and processing speed.
- Adjust
-
Profiling:
- Use
cProfile
to identify and optimize bottlenecks:python -m cProfile -s cumtime mrc2movie.py /path/to/mrc_files /path/to/output
- Use
This project is licensed under the MIT License.
Enjoy visualizing your tomograms with ease! 🎥✨