diff --git a/README.md b/README.md index 71293c8..45e3277 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/docs/source/code/modules.rst b/docs/source/code/modules.rst index 9b8a3d4..e3df989 100644 --- a/docs/source/code/modules.rst +++ b/docs/source/code/modules.rst @@ -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 -------------- diff --git a/docs/source/quick_start/basic_usage.rst b/docs/source/quick_start/basic_usage.rst index d753356..982febc 100644 --- a/docs/source/quick_start/basic_usage.rst +++ b/docs/source/quick_start/basic_usage.rst @@ -18,11 +18,36 @@ The basic usage of the package is presented. Loading the video ----------------- -First create the :py:class:`pyIDI ` object: +First create the :py:class:`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 ` class. +Available methods are: + +* :py:class:`SimplifiedOpticalFlow ` + +* :py:class:`LucasKanade ` + +* :py:class:`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 ------------------ @@ -38,30 +63,22 @@ 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 ---------------- @@ -69,7 +86,7 @@ Finally, displacements can be identified: .. code:: python - displacements = video.get_displacements() + displacements = sof.get_displacements() Saved analysis -------------- diff --git a/docs/source/quick_start/disp_id_methods.rst b/docs/source/quick_start/disp_id_methods.rst index 684d5eb..059dbc5 100644 --- a/docs/source/quick_start/disp_id_methods.rst +++ b/docs/source/quick_start/disp_id_methods.rst @@ -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 \ No newline at end of file + [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 \ No newline at end of file diff --git a/pyidi/methods/_directional_lucas_kanade.py b/pyidi/methods/_directional_lucas_kanade.py index 9137952..e359ca6 100644 --- a/pyidi/methods/_directional_lucas_kanade.py +++ b/pyidi/methods/_directional_lucas_kanade.py @@ -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 @@ -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 @@ -306,7 +306,7 @@ 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 @@ -314,14 +314,13 @@ def _padded_slice(self, point, roi_size, image_shape, pad=None): :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 diff --git a/pyidi/pyidi.py b/pyidi/pyidi.py index d1d7e25..edf74d4 100644 --- a/pyidi/pyidi.py +++ b/pyidi/pyidi.py @@ -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