-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,5 @@ | |
from .cube import cube | ||
from .cone import cone | ||
from .ellipsoid import ellipsoid | ||
from .map2mask import map2mask | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import mrcfile | ||
import numpy as np | ||
import typer | ||
from pathlib import Path | ||
|
||
from ._cli import cli | ||
from .soft_edge import add_soft_edge | ||
|
||
@cli.command(name='map2mask') | ||
def map2mask( | ||
|
||
input_map: Path = typer.Option(Path("map.mrc")), | ||
binarization_threshold: float = typer.Option(...), | ||
output_mask: Path = typer.Option(Path("mask.mrc")), | ||
pixel_size: float = typer.Option(...), | ||
soft_edge_width: int = typer.Option(0), | ||
|
||
): | ||
with mrcfile.open(input_map) as mrc: | ||
map_data = np.array(mrc.data) | ||
|
||
above_threshold = map_data >= binarization_threshold | ||
below_threshold = map_data < binarization_threshold | ||
|
||
map_data[above_threshold] = 1 | ||
map_data[below_threshold] = 0 | ||
|
||
mask = add_soft_edge(map_data, soft_edge_width) | ||
|
||
mrcfile.write(output_mask, mask, voxel_size=pixel_size, overwrite=True) |