Skip to content

Commit

Permalink
Merge pull request #17 from LorenzLamm/cleanup_and_docs
Browse files Browse the repository at this point in the history
clean up and docs
  • Loading branch information
LorenzLamm authored Jan 5, 2025
2 parents fc75799 + c954c40 commit ba6d792
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 632 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,22 @@ This [napari] plugin was generated with [Cookiecutter] using [@napari]'s [cookie

## Lasso tool

This repository currently contains 4 different methods for computing a 3D mask from a polygon:
This repository allows to draw 3D lassos, generate masks from these, and then mask out the image.
For instructions on how to use the plugin, please refer to the [Usage instructions](./docs/Usage.md).

<div style="text-align: center;">
<img src="https://private-user-images.githubusercontent.com/34575029/400214662-88851e09-6f10-4219-9b45-6f608c3e10b6.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzYwOTY5MDEsIm5iZiI6MTczNjA5NjYwMSwicGF0aCI6Ii8zNDU3NTAyOS80MDAyMTQ2NjItODg4NTFlMDktNmYxMC00MjE5LTliNDUtNmY2MDhjM2UxMGI2LmdpZj9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAxMDUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMTA1VDE3MDMyMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWY2ZTBmNjhkYjQ4Zjc3ZWZkMzlhYzdmODM3NTY3ZGNjYjAyZDk1MzI3ZTc1ZjY1NDJlYzgxYTRhZDcwNGJmOWUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.rUYe0XfZLvXy_5iZCXqkKvP_SkZbXfKL4owh7ot8YeU" alt="lasso_gif" width="75%" />
</div>

How it works: A polygon is drawn and a mask is generated via:
### Mask via rotation
Steps:
1. Rotate and project polygon to 2D and create a pixel mask
2. Create a 3D mask by stacking the pixel mask along z
3. Rotate 3D mask s.t. it is aligned with the original polygon

This performed more efficiently than the other methods:

### Mask via projection
Steps:
1. Project all points onto the hyperplane defined by the polygon
Expand All @@ -46,14 +54,6 @@ Steps:
3. Do that for many pixel mask, varying the z-component --> will be moved into tomogram along the polygon normal
4. Binary closing to get rid of holes from integer conversion

<!--
Don't miss the full getting started guide to set up your new package:
https://github.com/napari/cookiecutter-napari-plugin#getting-started
and review the napari docs for plugin developers:
https://napari.org/stable/plugins/index.html
-->

## Installation

pip install .
Expand Down
52 changes: 52 additions & 0 deletions docs/Usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
## How to use the lasso plugin

### 1. Preparation
- Open the napari viewer
- Load a 3D image (binary)
- Load the lasso plugin

### 2. Draw Lasso
First, click the "Freehand" button in the upper right corner of the viewer. Then, draw a lasso on the image by clicking and dragging the mouse.

<div style="text-align: center;">
<img src="https://private-user-images.githubusercontent.com/34575029/400213952-48f24e49-4cd0-4fa1-9f22-bfe8f9ae09bb.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzYwOTU2MzAsIm5iZiI6MTczNjA5NTMzMCwicGF0aCI6Ii8zNDU3NTAyOS80MDAyMTM5NTItNDhmMjRlNDktNGNkMC00ZmExLTlmMjItYmZlOGY5YWUwOWJiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAxMDUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMTA1VDE2NDIxMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWU3YjEzMjk3ZjdlY2EyY2M5NDdmOWEwNDNhMzdhNmY2MmJhYjc1OGViOTk0ZDQ1Y2RlYTY3MDNmNDM2MzViMDImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.w9KCehExEcqAfsGSxw8-UVTLusFaS265ckAN9LMBtag" alt="lasso_selection" width="49%" />
<img src="https://private-user-images.githubusercontent.com/34575029/400213951-bf73433d-f9f2-4f7d-b798-de2c71f3197a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzYwOTU2MzAsIm5iZiI6MTczNjA5NTMzMCwicGF0aCI6Ii8zNDU3NTAyOS80MDAyMTM5NTEtYmY3MzQzM2QtZjlmMi00ZjdkLWI3OTgtZGUyYzcxZjMxOTdhLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAxMDUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMTA1VDE2NDIxMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTNjNjk3YmEyMTE1YWYzZTdhZDg1OGM0NTAwMDcxNWE4YzMzMTYyZDU5YjBlNDA3NTI3ZjI4ZWE3MTVkYzQwMGYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.aYU0q4jzIQwb2maGQ0yiDJCXFaW3wDqGIYoFhDETy-w" alt="lasso_draw" width="49%" />
</div>


### 3. Generate mask and mask out the image
Click the "Lasso" button to generate a mask in the shape of the image you want to mask. Then click the "Mask Volume" button to mask out the image and generate a new layer with the masked image ("masked_volume").


<div style="text-align: center;">
<img src="https://private-user-images.githubusercontent.com/34575029/400213950-98242f8a-bfa7-44ed-9a44-aed49c124955.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzYwOTU5NTYsIm5iZiI6MTczNjA5NTY1NiwicGF0aCI6Ii8zNDU3NTAyOS80MDAyMTM5NTAtOTgyNDJmOGEtYmZhNy00NGVkLTlhNDQtYWVkNDljMTI0OTU1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAxMDUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMTA1VDE2NDczNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTAxOTBmMzlhOTk2ZDIyNTIwMDYyYjI3MDVhNTVkNTg2ZTM5NTEwZGI1ZGE0ODUyM2EzZDE3NDk4NWNmOWNmNWQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.cgEHtdFzxq1gNZ08LLQF453ZqtzGUAPtPtD4KsymASg" alt="lasso_mask_generation" width="49%" />
<img src="https://private-user-images.githubusercontent.com/34575029/400213946-8dff4d4d-c0ce-4c31-abc5-f730c69f62c8.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzYwOTU5NTYsIm5iZiI6MTczNjA5NTY1NiwicGF0aCI6Ii8zNDU3NTAyOS80MDAyMTM5NDYtOGRmZjRkNGQtYzBjZS00YzMxLWFiYzUtZjczMGM2OWY2MmM4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAxMDUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMTA1VDE2NDczNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTVlYjQ3OGFkZTg5NzQyZDc5MjhjYTk3Yjk2YTgyZjY5NWI1ZmYyNzMzMTQ5ZjU4ZjE4NjcyM2YwNmJlZDhkMTImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.HJjL9w-57SLYseQdlAuyImRCiEz6kQNFLNeszLVR3rw" alt="lasso_masked_volume" width="49%" />
</div>


### 4. Compute connected components
By selecting the "masked_volume" layer and clicking the "Connected Components" button, you can compute the connected components of the masked image. The connected components will be displayed as a new layer ("connected_components").

You can choose the remove small objects from the components by setting the "remove small objects" parameter to something other than 0. This will remove all connected components with a volume smaller than the specified value.

You also the the option to perform morphological opening before computing the connected components. This could be useful to split components that were wrongly merged by single voxels in the initial segmentations.

#### Visualization
To look at a single connected component, you can select the number of the component you would like to visualize and click "Display Connected Components" to display the selected component. All others will be blacked out.

If you would like to display all components again, you can select component number 0 and click "Display Connected Components".

<div style="text-align: center;">
<img src="https://private-user-images.githubusercontent.com/34575029/400213937-2e4571ee-ab4c-4c01-bcfe-df3ceb2f9a60.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzYwOTYyNzUsIm5iZiI6MTczNjA5NTk3NSwicGF0aCI6Ii8zNDU3NTAyOS80MDAyMTM5MzctMmU0NTcxZWUtYWI0Yy00YzAxLWJjZmUtZGYzY2ViMmY5YTYwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAxMDUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMTA1VDE2NTI1NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTQ3YzhmZTdmZGY3NmMxZTgzNjYwYjExYjlkYmI3ZjUwZTA1ZTlhYzE5ZTBkZGZlNGY3NzlhNzU3MzQ0NDM3YjkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.hOBHQ2oVUBADDjr2Wo5VScv-9Qcelfisyqi1al430pw" alt="lasso_compute_components" width="49%" />
<img src="https://private-user-images.githubusercontent.com/34575029/400213931-17253256-258e-4861-99d5-07c32f47bc07.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzYwOTYyNzUsIm5iZiI6MTczNjA5NTk3NSwicGF0aCI6Ii8zNDU3NTAyOS80MDAyMTM5MzEtMTcyNTMyNTYtMjU4ZS00ODYxLTk5ZDUtMDdjMzJmNDdiYzA3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAxMDUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMTA1VDE2NTI1NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTE4Mjk2N2Y5OTI5OTU3MmE5NjdhMzRkZmFlY2Q2ZDBlYmU3YzNkMDc4OGQ2NGUzY2JlNmRkOGI0NTU5OTg5MDcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.MJuCpAPPt28BnjLXanxfz18rIX9D8VVYk_MYGcrZJRo" alt="lasso_look_at_components" width="49%" />
</div>

### 5. Save out the connected components
You can now save out the components you would like to keep by selecting the corresponding component number, specifiying a file path, and clicking the "Store Tomogram" button. This will save the selected component as a new .mrc file.

Alternatively, you also also specify a directory path and select "Store All Components" to save out all components as individual .mrc files.

<div style="text-align: center;">
<img src="https://private-user-images.githubusercontent.com/34575029/400213927-14c8b195-f439-49c4-8d9e-6af6c80c82eb.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzYwOTYyNzUsIm5iZiI6MTczNjA5NTk3NSwicGF0aCI6Ii8zNDU3NTAyOS80MDAyMTM5MjctMTRjOGIxOTUtZjQzOS00OWM0LThkOWUtNmFmNmM4MGM4MmViLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAxMDUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMTA1VDE2NTI1NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTFmZTJhODY2YjkwNzYxMWQ3YTM1MTQxMTFlMDZmZmVmYzFjMTNjY2YwNjc0YjgwZjdkODlmYjhhOWRjMDNhZmUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.oypEXHl5zcB1Oq9V2jh9Cgy9gY6dlKm56giuGmksapE" alt="lasso_visualize_single_membrane" width="49%" />
<img src="https://private-user-images.githubusercontent.com/34575029/400213919-126cab19-3c36-4556-b674-ed79d5deaa18.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzYwOTYyNzUsIm5iZiI6MTczNjA5NTk3NSwicGF0aCI6Ii8zNDU3NTAyOS80MDAyMTM5MTktMTI2Y2FiMTktM2MzNi00NTU2LWI2NzQtZWQ3OWQ1ZGVhYTE4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAxMDUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMTA1VDE2NTI1NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWViYmIwMDJjNDYzM2Q2NjhiODFiNDg2ZjY0ODg4NWU3MjQ2ODRkZGYxNjlhMjFjZDFmZmYwYmZjN2VlOTFlNDkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.-h77temIeiS21EJ4vE5h_x6aq0AchFU9aNjcy8SECIo" alt="generated_files" width="49%" />
</div>
150 changes: 0 additions & 150 deletions lasso_example.ipynb

This file was deleted.

12 changes: 5 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@ classifiers = [
]
requires-python = ">=3.9"
dependencies = [
"numpy",
"magicgui",
"membrain-seg",
"napari-mrcfile-reader",
"numpy",
"pyqt5",
"qtpy",
"scikit-image",
"scipy",
"open3d",
"pyqt5",
"napari-mrcfile-reader",
"membrain-seg",
"dijkstra3d"
"scikit-image",
]

[project.optional-dependencies]
Expand Down
8 changes: 1 addition & 7 deletions src/lasso_3d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,4 @@
Lasso3D,
)

__all__ = (
# "napari_get_reader",
"Lasso3D",
# "ImageThreshold",
# "threshold_autogenerate_widget",
# "threshold_magic_widget",
)
__all__ = ("Lasso3D",)
73 changes: 0 additions & 73 deletions src/lasso_3d/_reader.py

This file was deleted.

Loading

0 comments on commit ba6d792

Please sign in to comment.