You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
3.2 KiB

10 years ago
10 years ago
  1. # nd2reader
  2. ### About
  3. `nd2reader` is a pure-Python package that reads images produced by NIS Elements.
  4. .nd2 files contain images and metadata, which can be split along multiple dimensions: time, fields of view (xy-plane), focus (z-plane), and filter channel.
  5. `nd2reader` produces data in numpy arrays, which makes it trivial to use with the image analysis packages such as `scikit-image` and `OpenCV`.
  6. ### Installation
  7. Just use pip:
  8. `pip install nd2reader`
  9. If you want to install via git, clone the repo and run:
  10. `python setup.py install`
  11. ### ND2s
  12. A quick summary of ND2 metadata can be obtained as shown below.
  13. ```python
  14. >>> import nd2reader
  15. >>> nd2 = nd2reader.Nd2("/path/to/my_images.nd2")
  16. >>> nd2
  17. <ND2 /path/to/my_images.nd2>
  18. Created: 2014-11-11 15:59:19
  19. Image size: 1280x800 (HxW)
  20. Image cycles: 636
  21. Channels: '', 'GFP'
  22. Fields of View: 8
  23. Z-Levels: 3
  24. ```
  25. ### Simple Iteration
  26. For most cases, you'll just want to iterate over each image:
  27. ```python
  28. import nd2reader
  29. nd2 = nd2reader.Nd2("/path/to/my_images.nd2")
  30. for image in nd2:
  31. do_something(image.data)
  32. ```
  33. ### Image Sets
  34. If you have complicated hierarchical data, it may be easier to use image sets, which groups images together if they
  35. share the same time index and field of view:
  36. ```python
  37. import nd2reader
  38. nd2 = nd2reader.Nd2("/path/to/my_complicated_images.nd2")
  39. for image_set in nd2.image_sets:
  40. # you can select images by channel
  41. gfp_image = image_set.get("GFP")
  42. do_something_gfp_related(gfp_image)
  43. # you can also specify the z-level. this defaults to 0 if not given
  44. out_of_focus_image = image_set.get("Bright Field", z_level=1)
  45. do_something_out_of_focus_related(out_of_focus_image)
  46. ```
  47. ### Direct Image Access
  48. There is a method, `get_image`, which allows random access to images. This might not always return an image, however,
  49. if you acquired different numbers of images in each cycle of a program. For example, if you acquire GFP images every
  50. other minute, but acquire bright field images every minute, `get_image` will return `None` at certain time indexes.
  51. ### Images
  52. `Image` objects provide several pieces of useful data.
  53. ```python
  54. >>> import nd2reader
  55. >>> nd2 = nd2reader.Nd2("/path/to/my_images.nd2")
  56. >>> image = nd2.get_image(14, 2, "GFP", 1)
  57. >>> image.data
  58. array([[1809, 1783, 1830, ..., 1923, 1920, 1914],
  59. [1687, 1855, 1792, ..., 1986, 1903, 1889],
  60. [1758, 1901, 1849, ..., 1911, 2010, 1954],
  61. ...,
  62. [3363, 3370, 3570, ..., 3565, 3601, 3459],
  63. [3480, 3428, 3328, ..., 3542, 3461, 3575],
  64. [3497, 3666, 3635, ..., 3817, 3867, 3779]])
  65. >>> image.channel
  66. 'GFP'
  67. >>> image.timestamp
  68. 1699.7947813408175
  69. >>> image.field_of_view
  70. 2
  71. >>> image.z_level
  72. 1
  73. # You can also get a quick summary of image data:
  74. >>> image
  75. <ND2 Image>
  76. 1280x800 (HxW)
  77. Timestamp: 1699.79478134
  78. Field of View: 2
  79. Channel: GFP
  80. Z-Level: 1
  81. ```
  82. ### Bug Reports and Features
  83. If this fails to work exactly as expected, please open a Github issue. If you get an unhandled exception, please
  84. paste the entire stack trace into the issue as well.
  85. ### Contributing
  86. Please feel free to submit a pull request with any new features you think would be useful. You can also create an
  87. issue if you'd just like to propose or discuss a potential idea.