Skip to content

Commit

Permalink
fixing docs, README, DLK docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
jasasonc committed Jan 30, 2025
1 parent b1261ea commit 2a6623f
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 44 deletions.
16 changes: 0 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,6 @@ video.set_points(points=p)
```
Or use point selection UI to set individual points or grid inside selected area. For more information about UI see [documentation](https://pyidi.readthedocs.io/en/quick_start/napari.html). Launch viewer with:

```
video.gui()
```

The method of identification has to be specified:
```
video.set_method(method='sof', **method_kwargs)
```
After points are set, displacements can be calculated (using method, set in `set_method`):
```
displacements = video.get_displacements()
```
Multiprocessing can also be used by passing the `processes` argument:
```
displacements = video.get_displacements(processes=4)
```

# DEVELOPER GUIDELINES:
* Add _name_of_method.py with class that inherits after `IDIMethods`
Expand Down
5 changes: 5 additions & 0 deletions docs/source/code/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ The Lucas-Kanade algorithm for translations
.. automodule:: pyidi.methods._lucas_kanade
:members:

Directional Lucas-Kanade
^^^^^^^^^^^^^^^^^^^^^^^^
.. automodule:: pyidi.methods._directional_lucas_kanade
:members:

Postprocessing
--------------

Expand Down
53 changes: 35 additions & 18 deletions docs/source/quick_start/basic_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,36 @@ The basic usage of the package is presented.

Loading the video
-----------------
First create the :py:class:`pyIDI <pyidi.pyidi.pyIDI>` object:
First create the :py:class:`VideoReader <pyidi.video_reader.VideoReader>` object:

.. code:: python
video = pyidi.pyIDI('filename.cih')
from pyidi import VideoReader
video = VideoReader('filename.cih')
Setting the method
------------------
The video object must be passed to the :py:class:`IDIMethod <pyidi.methods.idi_method.IDIMethod>` class.
Available methods are:

* :py:class:`SimplifiedOpticalFlow <pyidi.methods._simplified_optical_flow.SimplifiedOpticalFlow>`

* :py:class:`LucasKanade <pyidi.methods._lucas_kanade.LucasKanade>`

* :py:class:`DirectionalLucasKanade <pyidi.methods._directional_lucas_kanade.DirectionalLucasKanade>`

To use the Simplified Optical Flow method, the object must be instantiated:

.. code:: python
from pyidi import SimplifiedOpticalFlow
sof = SimplifiedOpticalFlow(video)
After the method object is instantiated, the points can be set and the arguments can be configured.

For more details on the available methods, see the currently implemented :ref:`implemented_disp_id_methods`.

Setting the points
------------------
Expand All @@ -38,38 +63,30 @@ Points must be of shape ``n_points x 2``:
where the first column indicates indices along **axis 0**, and the second column indices along **axis 1**.

The points must be passed to ``pyIDI`` object:
The points must be passed to ``method`` object:

.. code:: python
video.set_points(points=points)
sof.set_points(points=points)
If the points are not known, a :ref:`point-selection` or newer :ref:`napari` can be used to select the points.

Setting the method
------------------
The method for displacement identification must be selected:

.. code:: python
video.set_method(method='sof') # Simplified optical flow method
After the method is selected, the arguments can be configured. Note that the docstring is now
showing the required arguments for the selected method.
Configuring the method
----------------------
The method can be configured using:

.. code:: python
sof.configure(...)
video.method.configure(*args, **kwargs)
For more details on the available methods, see the currently implemented :ref:`implemented_disp_id_methods`.
Get displacement
----------------
Finally, displacements can be identified:

.. code:: python
displacements = video.get_displacements()
displacements = sof.get_displacements()
Saved analysis
--------------
Expand Down
7 changes: 6 additions & 1 deletion docs/source/quick_start/disp_id_methods.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ Simplified Optical Flow (SOF)
Lucas-Kanade (LK)
-----------------

[2] Lucas, B. D., & Kanade, T. (1981). An Iterative Image Registration Technique with an Application to Stereo Vision. In Proceedings of the 7th International Joint Conference on Artificial Intelligence - Volume 2 (pp. 674–679). San Francisco, CA, USA: Morgan Kaufmann Publishers Inc. Retrieved from http://dl.acm.org/citation.cfm?id=1623264.1623280
[2] Lucas, B. D., & Kanade, T. (1981). An Iterative Image Registration Technique with an Application to Stereo Vision. In Proceedings of the 7th International Joint Conference on Artificial Intelligence - Volume 2 (pp. 674–679). San Francisco, CA, USA: Morgan Kaufmann Publishers Inc. Retrieved from http://dl.acm.org/citation.cfm?id=1623264.1623280

Directional DIC
------------------------

[3] Masmeijer T., Habtour E., Zaletelj K. & Slavič J. (2025). Directional DIC method with automatic feature selection. Mechanical Systems and Signal Processing, 224. https://doi.org/10.1016/j.ymssp.2024.112080
15 changes: 7 additions & 8 deletions pyidi/methods/_directional_lucas_kanade.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def configure(
:param roi_size: (h, w) height and width of the region of interest.
ROI dimensions should be odd numbers. Defaults to (9, 9)
:type roi_size: tuple, list, optional
:param dij: Assumed vibration direction. Must be |d|=1. Convention is 'negative down, positive right'.
:param dij: Assumed vibration direction. Must be \\|d\\|=1. Convention is 'negative down, positive right'.
:type dij: tuple, list, optional
:param pad: size of padding around the region of interest in px, defaults to 2
:type pad: int, optional
Expand All @@ -69,7 +69,7 @@ def configure(
:param processes: number of processes to run
:type processes: int, optional, defaults to 1.
:param resume_analysis: if True, the last analysis results are loaded and computation continues from last computed time point.
:type resum_analysis: bool, optional
:type resume_analysis: bool, optional
:param reference_image: The reference image for computation. Can be index of a frame, tuple (slice) or numpy.ndarray that
is taken as a reference.
:type reference_image: int or tuple or ndarray
Expand Down Expand Up @@ -306,22 +306,21 @@ def optimize_translations(self, G, F_spline, maxiter, tol, dij, d_subpixel_init=


def _padded_slice(self, point, roi_size, image_shape, pad=None):
'''
"""
Returns a slice that crops an image around a given `point` center,
`roi_size` and `pad` size. If the resulting slice would be out of
bounds of the image to be sliced (given by `image_shape`), the
slice is snifted to be on the image edge and a warning is issued.
:param point: The center point coordiante of the desired ROI.
:type point: array_like of size 2, (y, x)
:param roi_size: Size of desired cropped image (y, x).
type roi_size: array_like of size 2, (h, w)
:type roi_size: array_like of size 2, (h, w)
:param image_shape: Shape of the image to be sliced, (h, w).
type image_shape: array_like of size 2, (h, w)
:param pad: Pad border size in pixels. If None, the video.pad
attribute is read.
:type image_shape: array_like of size 2, (h, w)
:param pad: Pad border size in pixels. If None, the video.pad attribute is read.
:type pad: int, optional, defaults to None
:return crop_slice: tuple (yslice, xslice) to use for image slicing.
'''
"""

if pad is None:
pad = self.pad
Expand Down
2 changes: 1 addition & 1 deletion pyidi/pyidi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import warnings
warnings.simplefilter("default")

from .methods import IDIMethod, SimplifiedOpticalFlow, LucasKanade, LucasKanadeSc, LucasKanadeSc2, GradientBasedOpticalFlow, DirectionalLucasKanade
from .methods import IDIMethod, SimplifiedOpticalFlow, LucasKanade, DirectionalLucasKanade #, LucasKanadeSc, LucasKanadeSc2, GradientBasedOpticalFlow
from .video_reader import VideoReader
from . import tools
from . import selection
Expand Down

0 comments on commit 2a6623f

Please sign in to comment.