Skip to content

Instantly share code, notes, and snippets.

View bbarad's full-sized avatar

Benjamin Barad bbarad

View GitHub Profile
@bbarad
bbarad / stl2sff.py
Created February 8, 2023 04:24
Convert a bunch of individual STL files to a large mesh collection sff file.
## Convert all mitochondria STL files in current directory to SFF/HFF files
## Usage: python stl2sff.py FOLDERNAME
## Assumes there are multiple mitochondria per tomogram and up to one ER per tomogram.
## Performs both per-segment and global annotations based on assumption of MitoGFP MEF cells treated with thapsigargin (sometimes)
## Outputs HFF format sff files.
## Author: Benjamin Barad <[email protected]> with guidance from Paul Korir
import os
import sys
import glob
@bbarad
bbarad / seg_combinator.py
Last active May 2, 2025 21:25
Combine two binary segmentations into one quantized segmentation with values 1 and 2.
# Take two binary segmentations in mrc format and combine them, with the first segmentation having label 1 and the second segmentation having label 2.
import mrcfile
import numpy as np
import argparse
def combine_segmentations(seg1, seg2, clear_overlaps=True):
"""
Combine two binary segmentations into one, with the first segmentation having label 1 and the second segmentation having label 2.
@bbarad
bbarad / combinemrcs.py
Created May 28, 2025 17:16
Combine named binary mrc segmentations into a single quantized mrc.
## Segmentation values and names are hardcoded (line 7).
## All segmentations should be in a single "segmentations" folder.
## This should match what is used in the config.yml for surface morphometrics
from sys import argv
import mrcfile
import os
import numpy as np
component_values = {"vesicle":1,
"er":2,