Skip to content
Snippets Groups Projects
Commit c5bfdb81 authored by s214735's avatar s214735
Browse files

changes to notebooks

parent 1de34fd0
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id:855a28ff tags:
# Get references from DOI
This notebook shows how it is possible to use the `Qim3D` library to easily get well formatted references from a DOI
This notebook shows how it is possible to use the `qim3D` library to easily get well formatted references from a DOI.
First we import the `qim3d` library and define our DOI:
%% Cell type:code id:35b9fe6b tags:
``` python
import qim3d
qim3d.io.logger.level('info')
doi = "https://doi.org/10.1007/s10851-021-01041-3"
```
%% Cell type:code id:7962731c tags:
%% Cell type:markdown id:d4bf7556 tags:
``` python
doi = "https://doi.org/10.1007/s10851-021-01041-3"
```
In order to get a bibtex for the doi, we can use the `get_bibtex` method:
%% Cell type:code id:17720b94 tags:
``` python
bibtext = qim3d.utils.doi.get_bibtex(doi)
bibtext = qim3d.utils.get_bibtex(doi)
```
%% Output
@article{Stephensen_2021,
doi = {10.1007/s10851-021-01041-3},
url = {https://doi.org/10.1007%2Fs10851-021-01041-3},
year = 2021,
month = {jun},
publisher = {Springer Science and Business Media {LLC}},
volume = {63},
number = {8},
pages = {1069--1083},
author = {Hans J. T. Stephensen and Anne Marie Svane and Carlos B. Villanueva and Steven A. Goldman and Jon Sporring},
title = {Measuring Shape Relations Using r-Parallel Sets},
journal = {Journal of Mathematical Imaging and Vision}
}
@article{Stephensen_2021, title={Measuring Shape Relations Using r-Parallel Sets}, volume={63}, ISSN={1573-7683}, url={http://dx.doi.org/10.1007/s10851-021-01041-3}, DOI={10.1007/s10851-021-01041-3}, number={8}, journal={Journal of Mathematical Imaging and Vision}, publisher={Springer Science and Business Media LLC}, author={Stephensen, Hans J. T. and Svane, Anne Marie and Villanueva, Carlos B. and Goldman, Steven A. and Sporring, Jon}, year={2021}, month=jun, pages={1069–1083} }
%% Cell type:markdown id:4bec3259 tags:
To display a metadata dictionary from a doi, the `get_reference` method can build a reference string:
%% Cell type:code id:a15baf83 tags:
``` python
reference = qim3d.utils.doi.get_reference(doi)
reference = qim3d.utils.get_reference(doi)
```
%% Output
%% Cell type:markdown id:88a65569 tags:
Stephensen, H. J. T., Svane, A. M., Villanueva, C. B., Goldman, S. A., & Sporring, J. (2021). Measuring Shape Relations Using r-Parallel Sets. Journal of Mathematical Imaging and Vision, 63(8), 1069–1083. https://doi.org/10.1007/s10851-021-01041-3
Lastly, to get metadata from the doi, use the `get_metadata` method:
%% Cell type:code id:6d4d215e tags:
``` python
qim3d.utils.doi.get_metadata(doi)
qim3d.utils.get_metadata(doi)
```
%% Output
{'indexed': {'date-parts': [[2023, 9, 21]],
'date-time': '2023-09-21T13:58:37Z',
'timestamp': 1695304717010},
{'indexed': {'date-parts': [[2023, 10, 20]],
'date-time': '2023-10-20T12:08:45Z',
'timestamp': 1697803725999},
'reference-count': 26,
'publisher': 'Springer Science and Business Media LLC',
'issue': '8',
'license': [{'start': {'date-parts': [[2021, 6, 26]],
'date-time': '2021-06-26T00:00:00Z',
'timestamp': 1624665600000},
'content-version': 'tdm',
'delay-in-days': 0,
'URL': 'https://www.springer.com/tdm'},
{'start': {'date-parts': [[2021, 6, 26]],
'date-time': '2021-06-26T00:00:00Z',
'timestamp': 1624665600000},
'content-version': 'vor',
'delay-in-days': 0,
'URL': 'https://www.springer.com/tdm'}],
'funder': [{'DOI': '10.13039/100008398',
'name': 'Villum Fonden',
'doi-asserted-by': 'publisher'},
'doi-asserted-by': 'publisher',
'id': [{'id': '10.13039/100008398',
'id-type': 'DOI',
'asserted-by': 'publisher'}]},
{'DOI': '10.13039/501100005275',
'name': 'Region Hovedstaden',
'doi-asserted-by': 'publisher'}],
'doi-asserted-by': 'publisher',
'id': [{'id': '10.13039/501100005275',
'id-type': 'DOI',
'asserted-by': 'publisher'}]}],
'content-domain': {'domain': ['link.springer.com'],
'crossmark-restriction': False},
'published-print': {'date-parts': [[2021, 10]]},
'DOI': '10.1007/s10851-021-01041-3',
'type': 'journal-article',
'created': {'date-parts': [[2021, 6, 26]],
'date-time': '2021-06-26T15:02:20Z',
'timestamp': 1624719740000},
'page': '1069-1083',
'update-policy': 'http://dx.doi.org/10.1007/springer_crossmark_policy',
'source': 'Crossref',
'is-referenced-by-count': 3,
'title': 'Measuring Shape Relations Using r-Parallel Sets',
'prefix': '10.1007',
'volume': '63',
'author': [{'ORCID': 'http://orcid.org/0000-0001-8245-0571',
'authenticated-orcid': False,
'given': 'Hans J. T.',
'family': 'Stephensen',
'sequence': 'first',
'affiliation': []},
{'ORCID': 'http://orcid.org/0000-0001-6356-0484',
'authenticated-orcid': False,
'given': 'Anne Marie',
'family': 'Svane',
'sequence': 'additional',
'affiliation': []},
{'ORCID': 'http://orcid.org/0000-0001-9786-9439',
'authenticated-orcid': False,
'given': 'Carlos B.',
'family': 'Villanueva',
'sequence': 'additional',
'affiliation': []},
{'ORCID': 'http://orcid.org/0000-0002-5498-4303',
'authenticated-orcid': False,
'given': 'Steven A.',
'family': 'Goldman',
'sequence': 'additional',
'affiliation': []},
{'ORCID': 'http://orcid.org/0000-0003-1261-6702',
'authenticated-orcid': False,
'given': 'Jon',
'family': 'Sporring',
'sequence': 'additional',
'affiliation': []}],
'member': '297',
'published-online': {'date-parts': [[2021, 6, 26]]},
'reference': [{'key': '1041_CR1',
'doi-asserted-by': 'publisher',
'DOI': '10.1201/b19708',
'volume-title': 'Spatial Point Patterns: Methodology and Applications with R',
'author': 'A Baddeley',
'year': '2015',
'unstructured': 'Baddeley, A., Rubak, E., Turner, R.: Spatial Point Patterns: Methodology and Applications with R. CRC Press, Boca Raton (2015)',
'DOI': '10.1201/b19708'},
'unstructured': 'Baddeley, A., Rubak, E., Turner, R.: Spatial Point Patterns: Methodology and Applications with R. CRC Press, Boca Raton (2015)'},
{'key': '1041_CR2',
'series-title': 'Statistics Reference Online',
'doi-asserted-by': 'publisher',
'DOI': '10.1002/9781118445112.stat07751',
'volume-title': 'Ripley’s $$k$$ Function',
'author': 'PM Dixon',
'year': '2014',
'unstructured': 'Dixon, P.M.: Ripley’s $$k$$ Function. Statistics Reference Online, Wiley, New York (2014)'},
{'issue': '1',
'key': '1041_CR3',
'doi-asserted-by': 'publisher',
'first-page': '1',
'DOI': '10.1016/0962-8924(94)90025-6',
'volume': '4',
'author': 'R Fesce',
'year': '1994',
'unstructured': 'Fesce, R., Grohovaz, F., Valtorta, F., Meldolesi, J.: Neurotransmitter release: fusion or kiss-and-run? Trends Cell Biol. 4(1), 1–4 (1994)',
'journal-title': 'Trends Cell Biol.'},
{'issue': '8',
'key': '1041_CR4',
'doi-asserted-by': 'publisher',
'first-page': '1953',
'DOI': '10.1007/s00138-014-0625-2',
'volume': '25',
'author': 'Y Gavet',
'year': '2014',
'unstructured': 'Gavet, Y., Fernandes, M., Debayle, J., Pinoli, J.C.: Dissimilarity criteria and their comparison for quantitative evaluation of image segmentation: application to human retina vessels. Mach. Vis. Appl. 25(8), 1953–1966 (2014)',
'journal-title': 'Mach. Vis. Appl.'},
{'key': '1041_CR5',
'doi-asserted-by': 'publisher',
'first-page': '248',
'DOI': '10.3389/fncel.2018.00248',
'volume': '12',
'author': 'N Gavrilov',
'year': '2018',
'unstructured': 'Gavrilov, N., Golyagina, I., Brazhe, A., Scimemi, A., Turlapov, V., Semyanov, A.: Astrocytic coverage of dendritic spines, dendritic shafts, and axonal boutons in hippocampal neuropil. Front. Cell. Neurosci. 12, 248 (2018)',
'journal-title': 'Front. Cell. Neurosci.'},
{'issue': '498',
'key': '1041_CR6',
'doi-asserted-by': 'publisher',
'first-page': '754',
'DOI': '10.1080/01621459.2012.688463',
'volume': '107',
'author': 'U Hahn',
'year': '2012',
'unstructured': 'Hahn, U.: A studentized permutation test for the comparison of spatial point patterns. J. Am. Stat. Assoc. 107(498), 754–764 (2012). https://doi.org/10.1080/01621459.2012.688463',
'journal-title': 'J. Am. Stat. Assoc.'},
{'issue': '4',
'key': '1041_CR7',
'doi-asserted-by': 'publisher',
'first-page': '60:1',
'DOI': '10.1145/3197517.3201353',
'volume': '37',
'author': 'Y Hu',
'year': '2018',
'unstructured': 'Hu, Y., Zhou, Q., Gao, X., Jacobson, A., Zorin, D., Panozzo, D.: Tetrahedral meshing in the wild. ACM Trans. Gr. 37(4), 60:1-60:14 (2018). https://doi.org/10.1145/3197517.3201353',
'journal-title': 'ACM Trans. Gr.'},
{'key': '1041_CR8',
'doi-asserted-by': 'publisher',
'unstructured': 'Khanmohammadi, M., Waagepetersen, R.P., Sporring, J.: Analysis of shape and spatial interaction of synaptic vesicles using data from focused ion beam scanning electron microscopy (FIB-SEM). Front. Neuroanatomy (2015). https://doi.org/10.3389/fnana.2015.00116',
'DOI': '10.3389/fnana.2015.00116'},
{'issue': '3',
'key': '1041_CR9',
'doi-asserted-by': 'publisher',
'first-page': '797',
'DOI': '10.1083/jcb.135.3.797',
'volume': '135',
'author': 'J Koenig',
'year': '1996',
'unstructured': 'Koenig, J., Ikeda, K.: Synaptic vesicles have two distinct recycling pathways. J. Cell Biol. 135(3), 797–808 (1996)',
'journal-title': 'J. Cell Biol.'},
{'key': '1041_CR10',
'unstructured': 'Lucchi, A., Li, Y., Becker, C., Fua, P.: Electron microscopy dataset. https://cvlab.epfl.ch/data/data-em/. Accessed 14 Mar 2020'},
{'issue': '2',
'key': '1041_CR11',
'doi-asserted-by': 'publisher',
'first-page': '568',
'DOI': '10.1002/mrm.24477',
'volume': '70',
'author': 'J Marques',
'year': '2013',
'unstructured': 'Marques, J., Genant, H.K., Lillholm, M., Dam, E.B.: Diagnosis of osteoarthritis and prognosis of tibial cartilage loss by quantification of tibia trabecular bone from MRI. Magn. Reson. Med. 70(2), 568–575 (2013). https://doi.org/10.1002/mrm.24477',
'journal-title': 'Magn. Reson. Med.'},
{'issue': '1654',
'key': '1041_CR12',
'doi-asserted-by': 'publisher',
'first-page': '20140047',
'DOI': '10.1098/rstb.2014.0047',
'volume': '369',
'author': 'N Medvedev',
'year': '2014',
'unstructured': 'Medvedev, N., Popov, V., Henneberger, C., Kraev, I., Rusakov, D.A., Stewart, M.G.: Glia selectively approach synapses on thin dendritic spines. Philos. Trans. R Soc. B Biol. Sci. 369(1654), 20140047 (2014)',
'journal-title': 'Philos. Trans. R Soc. B Biol. Sci.'},
{'issue': '3',
'key': '1041_CR13',
'doi-asserted-by': 'publisher',
'first-page': '551',
'DOI': '10.1016/S0896-6273(00)00065-9',
'volume': '27',
'author': 'D Richards',
'year': '2000',
'unstructured': 'Richards, D., Guatimosim, C., Betz, W.: Two endocytic recycling routes selectively fill two vesicle pools in frog motor nerve terminals. Neuron 27(3), 551–559 (2000)',
'journal-title': 'Neuron'},
{'issue': '3',
'key': '1041_CR14',
'doi-asserted-by': 'publisher',
'first-page': '368',
'DOI': '10.1111/j.2517-6161.1979.tb01091.x',
'volume': '41',
'author': 'BD Ripley',
'year': '1979',
'unstructured': 'Ripley, B.D.: Tests of randomness for spatial point patterns. J. Roy. Stat. Soc. Ser. B (Methodol.) 41(3), 368–374 (1979). https://doi.org/10.1111/j.2517-6161.1979.tb01091.x',
'journal-title': 'J. Roy. Stat. Soc. Ser. B (Methodol.)'},
{'key': '1041_CR15',
'doi-asserted-by': 'publisher',
'DOI': '10.1017/CBO9780511624131',
'volume-title': 'Statistical Inference for Spatial Processes',
'author': 'BD Ripley',
'year': '1988',
'unstructured': 'Ripley, B.D.: Statistical Inference for Spatial Processes. Cambridge University Press, Cambridge (1988)',
'DOI': '10.1017/CBO9780511624131'},
'unstructured': 'Ripley, B.D.: Statistical Inference for Spatial Processes. Cambridge University Press, Cambridge (1988)'},
{'key': '1041_CR16',
'doi-asserted-by': 'crossref',
'unstructured': 'Ronneberger, O., Fischer, P., Brox, T.: U-net: convolutional networks for biomedical image segmentation. In: International Conference on Medical Image Computing and Computer-Assisted Intervention, pp. 234–241. Springer (2015)',
'DOI': '10.1007/978-3-319-24574-4_28'},
{'key': '1041_CR17',
'doi-asserted-by': 'publisher',
'DOI': '10.1007/978-3-540-78859-1',
'volume-title': 'Stochastic and Integral Geometry',
'author': 'R Schneider',
'year': '2008',
'unstructured': 'Schneider, R., Weil, W.: Stochastic and Integral Geometry. Springer, Heidelberg (2008)',
'DOI': '10.1007/978-3-540-78859-1'},
'unstructured': 'Schneider, R., Weil, W.: Stochastic and Integral Geometry. Springer, Heidelberg (2008)'},
{'key': '1041_CR18',
'unstructured': 'Scientific, T.F.: Amira-avizo software (2020)'},
{'key': '1041_CR19',
'doi-asserted-by': 'crossref',
'unstructured': 'Sethian, J.A.: Fast marching methods. SIAM Rev. 41(2), 199–235 (1999)',
'DOI': '10.1137/S0036144598347059'},
{'issue': '2',
'key': '1041_CR20',
'doi-asserted-by': 'publisher',
'first-page': '1',
'DOI': '10.1145/2629697',
'volume': '41',
'author': 'H Si',
'year': '2015',
'unstructured': 'Si, H.: TetGen, a delaunay-based quality tetrahedral mesh generator. ACM Trans. Math. Softw. 41(2), 1–36 (2015)',
'journal-title': 'ACM Trans. Math. Softw.'},
{'key': '1041_CR21',
'doi-asserted-by': 'crossref',
'unstructured': 'Sporring, J., Waagepetersen, R., Sommer, S.: Generalizations of Ripley’s k-function with application to space curves. In: International Conference on Information Processing in Medical Imaging, pp. 731–742. Springer (2019)',
'DOI': '10.1007/978-3-030-20351-1_57'},
{'issue': '1',
'key': '1041_CR22',
'doi-asserted-by': 'publisher',
'first-page': '1',
'DOI': '10.1038/s42003-020-0809-4',
'volume': '3',
'author': 'HJT Stephensen',
'year': '2020',
'unstructured': 'Stephensen, H.J.T., Darkner, S., Sporring, J.: Restoring drifted electron microscope volumes using synaptic vesicles at sub-pixel accuracy. Commun. Biol. 3(1), 1–7 (2020)',
'journal-title': 'Commun. Biol.'},
{'key': '1041_CR23',
'unstructured': 'Stephensen, H.J.T., Sporring, J.: Rodent neuronal volume annotations and segmentations (2020). https://www.doi.org/10.17894/ucph.33bd30d2-5796-48f4-a0a8-96fcc0ce6af5'},
{'key': '1041_CR24',
'doi-asserted-by': 'crossref',
'unstructured': 'Svane, A.M.: Valuations in image analysis. In: Tensor Valuations and Their Applications in Stochastic Geometry and Imaging, pp. 435–454. Springer (2017)',
'DOI': '10.1007/978-3-319-51951-7_15'},
{'key': '1041_CR25',
'doi-asserted-by': 'publisher',
'unstructured': 'Virtanen, P., Gommers, R., Oliphant, T.E., Haberland, M., Reddy, T., Cournapeau, D., Burovski, E., Peterson, P., Weckesser, W., Bright, J., van der Walt, S.J., Brett, M., Wilson, J., Jarrod Millman, K., Mayorov, N., Nelson, A.R.J., Jones, E., Kern, R., Larson, E., Carey, C., Polat, İ, Feng, Y., Moore, E.W., Van der Plas, J., Laxalde, D., Perktold, J., Cimrman, R., Henriksen, I., Quintero, E.A., Harris, C.R., Archibald, A.M., Ribeiro, A.H., Pedregosa, F., van Mulbregt, P., Contributors, S., et al.: SciPy 1.0: fundamental algorithms for scientific computing in python. Nat. Methods 17, 261–272 (2020). https://doi.org/10.1038/s41592-019-0686-2',
'DOI': '10.1038/s41592-019-0686-2'},
{'issue': '1',
'key': '1041_CR26',
'doi-asserted-by': 'publisher',
'first-page': '1',
'DOI': '10.1016/j.patcog.2003.07.008',
'volume': '37',
'author': 'D Zhang',
'year': '2004',
'unstructured': 'Zhang, D., Lu, G.: Review of shape representation and description techniques. Pattern Recogn. 37(1), 1–19 (2004). https://doi.org/10.1016/j.patcog.2003.07.008',
'journal-title': 'Pattern Recogn.'}],
'container-title': 'Journal of Mathematical Imaging and Vision',
'original-title': [],
'language': 'en',
'link': [{'URL': 'https://link.springer.com/content/pdf/10.1007/s10851-021-01041-3.pdf',
'content-type': 'application/pdf',
'content-version': 'vor',
'intended-application': 'text-mining'},
{'URL': 'https://link.springer.com/article/10.1007/s10851-021-01041-3/fulltext.html',
'content-type': 'text/html',
'content-version': 'vor',
'intended-application': 'text-mining'},
{'URL': 'https://link.springer.com/content/pdf/10.1007/s10851-021-01041-3.pdf',
'content-type': 'application/pdf',
'content-version': 'vor',
'intended-application': 'similarity-checking'}],
'deposited': {'date-parts': [[2023, 1, 1]],
'date-time': '2023-01-01T16:48:24Z',
'timestamp': 1672591704000},
'score': 1,
'resource': {'primary': {'URL': 'https://link.springer.com/10.1007/s10851-021-01041-3'}},
'subtitle': [],
'short-title': [],
'issued': {'date-parts': [[2021, 6, 26]]},
'references-count': 26,
'journal-issue': {'issue': '8',
'published-print': {'date-parts': [[2021, 10]]}},
'alternative-id': ['1041'],
'URL': 'http://dx.doi.org/10.1007/s10851-021-01041-3',
'relation': {},
'ISSN': ['0924-9907', '1573-7683'],
'subject': ['Applied Mathematics',
'Geometry and Topology',
'Computer Vision and Pattern Recognition',
'Condensed Matter Physics',
'Modeling and Simulation',
'Statistics and Probability'],
'subject': [],
'container-title-short': 'J Math Imaging Vis',
'published': {'date-parts': [[2021, 6, 26]]},
'assertion': [{'value': '7 November 2020',
'order': 1,
'name': 'received',
'label': 'Received',
'group': {'name': 'ArticleHistory', 'label': 'Article History'}},
{'value': '2 June 2021',
'order': 2,
'name': 'accepted',
'label': 'Accepted',
'group': {'name': 'ArticleHistory', 'label': 'Article History'}},
{'value': '26 June 2021',
'order': 3,
'name': 'first_online',
'label': 'First Online',
'group': {'name': 'ArticleHistory', 'label': 'Article History'}},
{'order': 1,
'name': 'Ethics',
'group': {'name': 'EthicsHeading', 'label': 'Declarations'}},
{'value': 'The authors declare that they have no conflict of interest.',
'order': 2,
'name': 'Ethics',
'group': {'name': 'EthicsHeading', 'label': 'Conflict of interest'}}]}
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
%% Cell type:code id: tags:
``` python
import qim3d
```
%% Cell type:markdown id: tags:
### Blob detection notebook
## Blob detection notebook
%% Cell type:markdown id: tags:
This notebook shows how to do **blob detection** in a 3D volume using the `qim3d` library.
Blob detection is done by using the `qim3d.processing.blob_detection` method, which detects blobs by using the Difference of Gaussian (DoG) blob detection method, and returns two arrays:
- `blobs`: The blobs found in the volume stored as `(p, r, c, radius)`
- `binary_volume`: A binary mask of the volume with the blobs marked as `True`
%% Cell type:markdown id: tags:
### **Example 1**: Blob detection in cement volume
### Blob detection in cement volume
%% Cell type:markdown id: tags:
**Applying Gaussian filter to volume**
First we apply a gaussian filter to the volume to remove some noise. This is done using the filters module, whereafter the result is visualized with the `slices_grid` method.
%% Cell type:code id: tags:
``` python
import qim3d
# Import 3D volume of cement
cement = qim3d.examples.cement_128x128x128
vol = qim3d.examples.cement_128x128x128
# Visualize slices of the original cement volume
fig1 = qim3d.viz.slices_grid(cement, num_slices=5, display_figure=True)
fig1 = qim3d.viz.slices_grid(vol, num_slices=5, display_figure=True)
# Apply Gaussian filter to the cement volume
cement_filtered = qim3d.filters.gaussian(cement, sigma = 2)
vol_filtered = qim3d.filters.gaussian(vol, sigma = 2)
# Visualize slices of the filtered cement volume
fig2 = qim3d.viz.slices_grid(cement_filtered, num_slices=5, display_figure=True)
fig2 = qim3d.viz.slices_grid(vol_filtered, num_slices=5, display_figure=True)
```
%% Output
%% Cell type:markdown id: tags:
**Detecting blobs in volume**
Then the blobs are detected using the `blobs` method from the `detection` module.
%% Cell type:code id: tags:
``` python
# Detect blobs, and get binary mask
blobs, mask = qim3d.detection.blobs(
cement_filtered,
vol_filtered,
min_sigma=1,
max_sigma=8,
threshold=0.001,
overlap=0.1,
background="bright"
)
# Number of blobs found
print(f'Number of blobs found in the volume: {len(blobs)} blobs')
```
%% Output
Bright background selected, volume will be inverted.
Number of blobs found in the volume: 1813 blobs
%% Cell type:markdown id: tags:
We can then use the `circles` method to visualize the mask on top of slices of the original volume:
%% Cell type:code id: tags:
``` python
# Visualize blobs on slices of cement volume
qim3d.viz.circles(blobs, cement, alpha = 0.8, color='red')
qim3d.viz.circles(blobs, vol, alpha = 0.8, color='red')
```
%% Output
interactive(children=(IntSlider(value=64, description='Slice', max=127), Output()), layout=Layout(align_items=…
%% Cell type:markdown id: tags:
**Binary mask of detected blobs**
Lastly we can use the `slicer` method to explore the slices of the mask created by the blob detector.
%% Cell type:code id: tags:
``` python
# Visualize binary mask
qim3d.viz.slicer(mask)
```
%% Output
interactive(children=(IntSlider(value=64, description='Slice', max=127), Output()), layout=Layout(align_items=…
......
%% Cell type:code id: tags:
%% Cell type:markdown id: tags:
``` python
import qim3d
import numpy as np
from scipy import ndimage
```
## Filter showcase notebook
This notebook demonstrates how to use filters in the qim3d library. There are multiple ways to initialize and apply the filters, which can make filter application more straight forward.
Filtering is done using the `qim3d.filter` module, which include direct application of filters, initialization of filter classes or pipelines.
All filters are used either from the ndimage library or dask library, depending on input arguments. Therefore kwargs include the arguments for these functions.
We start by importing the qim3d library and a volume to apply the filters to.
%% Cell type:code id: tags:
``` python
import qim3d
vol = qim3d.examples.fly_150x256x256
qim3d.viz.slices_grid(vol, num_slices=5)
```
%% Output
<Figure size 1000x200 with 5 Axes>
%% Cell type:markdown id: tags:
## Filter showcase notebook
This notebook demonstrates how to use filters in the qim3d library. There are multiple ways to initialize and apply the filters, which can make filter application more straight forward.
Filtering is done using the `qim3d.filter` module, which include direct application of filters, initialization of filter classes or pipelines.
All filters are used either from the ndimage library or dask library, depending on input arguments. Therefore kwargs include the arguments for these functions.
%% Cell type:markdown id: tags:
### Direct filter use
Filters can be directly used on a volume, resulting in a filtered volume. This is demonstrated with the `gaussian` and `median` filter.
%% Cell type:code id: tags:
``` python
### Gaussian filter
vol_gaussian = qim3d.filters.gaussian(vol, sigma=3)
### Median filter
vol_median = qim3d.filters.median(vol, size=5)
```
%% Cell type:markdown id: tags:
### Filter classes
The filter can also be instantiated with the filter class, which can then be applied to a volume. This is demonstrated with the `Maximum` filter class. Notice that the class of the filter has a capital first letter.
%% Cell type:code id: tags:
``` python
gaussian_fn = qim3d.filters.Maximum(size=5)
vol_maximum = gaussian_fn(vol)
```
%% Cell type:markdown id: tags:
## Using filter classes to construct a pipeline of filters
When more than one filter is needed, a pipeline can be created. This makes it easy to reapply multiple filters to different volumes. This is demonstrated with the `Maximum` and `Minumum` filter classes.
%% Cell type:code id: tags:
``` python
pipeline = qim3d.filters.Pipeline(
qim3d.filters.Maximum(size=3),
qim3d.filters.Minimum(size=10))
vol_pipeline = pipeline(vol)
```
%% Cell type:markdown id: tags:
Filter functions can also be appended to the sequence after defining the class instance. This is demonstrated by appending a `Tophat` filter to the pipeline.
%% Cell type:code id: tags:
``` python
pipeline.append(qim3d.filters.Tophat(size=5))
vol_pipeline2 = pipeline(vol)
```
%% Cell type:markdown id: tags:
To get an overview of the filters in a pipeline, we can access the `filters` dictionary in the pipeline:
%% Cell type:code id: tags:
``` python
print(pipeline.filters)
```
%% Output
{'0': <qim3d.filters._common_filter_methods.Maximum object at 0x7fe329e43f10>, '1': <qim3d.filters._common_filter_methods.Minimum object at 0x7fe32a1b3e10>, '2': <qim3d.filters._common_filter_methods.Tophat object at 0x7fe329e3c210>}
......
This diff is collapsed.
%% Cell type:code id: tags:
``` python
import qim3d
```
%% Cell type:markdown id: tags:
### Structure tensor notebook
## Structure tensor notebook
%% Cell type:markdown id: tags:
This notebook shows how to compute eigenvalues and eigenvectors of the **structure tensor** of a 3D volume using the `qim3d` library. The structure tensor (matrix) represents information about the local gradient directions in the volume, such that the eigenvectors represent the orientation of the structure in the volume, and the corresponding eigenvaleus indicate the magnitude.
The function `qim3d.processing.structure_tensor` returns two arrays `val` and `vec` for the eigenvalues and eigenvectors, respectively.\
By having the argument `visulize = True`, the function displays a figure of three subplots:
* Slice of volume with vector field of the eigenvectors
* Orientation histogram of the eigenvectors
* Slice of volume with overlaying colors of the orientation
For all three subplots, the colors used to visualize the orientation within the volume are from the HSV colorspace. In these visualizations, the saturation of the color corresponds to the vector component of the slicing direction (i.e. $z$-component when choosing visualization along `axis = 0`). Hence, if an orientation in the volume is orthogonal to the slicing direction, the corresponding color of the visualization will be gray.
%% Cell type:markdown id: tags:
### **Example:** Structure tensor of brain tissue volume
First we import the `qim3d` library and visualize the volume:
%% Cell type:code id: tags:
``` python
import qim3d
# Import 3D volume of brain tissue
NT = qim3d.examples.NT_128x128x128
# Visuaize the 3D volume
qim3d.viz.vol(NT)
qim3d.viz.volumetric(NT)
```
%% Output
%% Cell type:markdown id: tags:
From the visualization of the full volume, it can be seen that the circular structures of the brain tissue are aligned orthogonal to the $z$-axis (`axis = 0`). By choosing to slice the volume in this direction, the structure tensor visualizations will largely be gray, since the $z$-component of the eigenvectors are close to $0$, meaning the saturation of the coloring will be close to $0$ (i.e. gray). This can be seen below.
%% Cell type:code id: tags:
``` python
# Compute eigenvalues and eigenvectors of the structure tensor
val, vec = qim3d.processing.structure_tensor(NT, visualize = True, axis = 0) # Slicing in z-direction
```
%% Output
%% Cell type:markdown id: tags:
By slicing the volume in the $x$-direction (`axis = 2`) instead, the orientation along the length of the structures in the brain tissue can be seen instead. Then the structure tensor visualizations will be largely blue, corresponding to eigenvectors along the $x$-direction with angles of $\approx \frac{\pi}{2}$ radians ($90$ degrees).
%% Cell type:code id: tags:
``` python
# Compute eigenvalues and eigenvectors of the structure tensor
val, vec = qim3d.processing.structure_tensor(NT, visualize = True, axis = 2) # Slicing in x-direction
```
%% Output
......
......@@ -24,7 +24,7 @@ from PIL import Image, UnidentifiedImageError
import qim3d
from qim3d.utils._logger import log
from qim3d.utils._misc import get_file_size, sizeof, stringify_path
from qim3d.utils._misc import get_file_size, sizeof, stringify_path, find_similar_paths
from qim3d.utils._system import Memory
from qim3d.utils._progress_bar import FileLoadingProgressBar
import trimesh
......@@ -720,7 +720,7 @@ class DataLoader:
# Fails
else:
# Find the closest matching path to warn the user
similar_paths = qim3d.utils.misc.find_similar_paths(path)
similar_paths = find_similar_paths(path)
if similar_paths:
suggestion = similar_paths[0] # Get the closest match
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment