Created
January 10, 2023 11:46
-
-
Save alisterburt/05bf43ede9c5ba6c44472d79bd7579bc to your computer and use it in GitHub Desktop.
point in masked region (for Shen Han)
This file contains hidden or 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
| import numpy as np | |
| import napari | |
| from skimage import data | |
| # fake tomogram | |
| tomogram = np.random.random((300, 300, 300)) | |
| # fake mask | |
| mask = data.binary_blobs( | |
| length=300, n_dim=3, blob_size_fraction=0.3, volume_fraction=0.1 | |
| ) | |
| # random particle positions | |
| positions = np.random.uniform(low=0, high=300, size=(100, 3)) | |
| idx = positions.astype(int) # integer positions | |
| # check if integer particle position is in a masked region | |
| in_mask = mask[idx[:, 0], idx[:, 1], idx[:, 2]] == 1 | |
| # visualise in napari | |
| viewer = napari.Viewer(ndisplay=3) | |
| viewer.add_labels(mask, blending='translucent_no_depth') | |
| viewer.add_points( | |
| positions, | |
| features={'in_mask': in_mask}, | |
| face_color='in_mask', | |
| face_color_cycle=['white', 'green'] | |
| ) | |
| napari.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment