Created
January 23, 2023 15:19
-
-
Save wjiang/c35bba0ae3709a8c42fe0916694ac24a to your computer and use it in GitHub Desktop.
Convert MRC/MRCS images to png format files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys, mrcfile | |
import numpy as np | |
from skimage.io import imsave | |
if len(sys.argv)!=3: | |
print(f"Usage: {sys.argv[0]} <input.mrc> <outputPrefix>") | |
sys.exit(-1) | |
with mrcfile.open(sys.argv[1]) as mrc: | |
for i in range(len(mrc.data)): | |
vmin = np.min(mrc.data[i]) | |
vmax = np.max(mrc.data[i]) | |
d = (255*(mrc.data[i]-vmin)/(vmax-vmin)).astype(np.ubyte) | |
imageFile = f"{sys.argv[2]}.{i+1}.png" | |
imsave(imageFile, d) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment