Skip to content

New api #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 39 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
a09bf82
updated video reader
klemengit Nov 27, 2024
9d866b6
updated gitignore
klemengit Nov 27, 2024
56915e2
refactor VideoReader and IDIMethod classes; add analysis directory cr…
klemengit Nov 27, 2024
c95cbd6
refactor calculate_displacements method in LucasKanade and IDIMethod …
klemengit Nov 27, 2024
30f2768
refactor imports and update load_analysis function; comment out unuse…
klemengit Nov 27, 2024
2f1f4d3
refactor LucasKanade class; update roi_size handling and streamline s…
klemengit Nov 27, 2024
f3b64ca
refactor IDIMethod class; enhance temporary file management, add sett…
klemengit Nov 27, 2024
c22f4e2
add show_points method to IDIMethod class; visualize points and ROI b…
klemengit Nov 27, 2024
6452a06
refactor SimplifiedOpticalFlow class for new api
klemengit Nov 27, 2024
4b09aa7
updated directional LucasKanade to new api
klemengit Nov 27, 2024
4d75725
refactor selection module; rename ROISelect to SubsetSelection and up…
klemengit Nov 27, 2024
f9626a8
added repr to SubsetSelection
klemengit Nov 27, 2024
5f09d7f
fix: adjust mraw_range condition and enhance progress task description
klemengit Nov 27, 2024
eb79fe4
fix: update mraw_range condition and enhance progress task description
klemengit Nov 27, 2024
551a974
updated progress bar
klemengit Nov 27, 2024
762af7e
readme update
klemengit Nov 29, 2024
b5c71b6
small update in SubsetSelection
klemengit Nov 29, 2024
6488d36
feat: add legacy pyIDI class for backward compatibility and depricati…
klemengit Nov 29, 2024
b453d8e
test updates for legacy api
klemengit Dec 3, 2024
b5cec5f
updated mode shape magnification to new API
klemengit Dec 3, 2024
522bf81
updated showcase LK to new API
klemengit Dec 3, 2024
3a1a989
load analysis update to new API
klemengit Dec 3, 2024
3c39b6c
Updated directional LK to new api
klemengit Dec 3, 2024
f920d25
Refactor selection UI to use ttk widgets and improve combobox functio…
klemengit Dec 3, 2024
e6e993e
GUI upgrade with respect to the new API
jasasonc Jan 10, 2025
d20c6fa
bugfix in GUI; default values updating
jasasonc Jan 13, 2025
7f059ed
GUI docs updated
jasasonc Jan 14, 2025
54622ad
GUI output console added
jasasonc Jan 15, 2025
b57a479
New GUI (with console) gif
jasasonc Jan 20, 2025
b1261ea
Fixed GUI gif: larger text
jasasonc Jan 21, 2025
2a6623f
fixing docs, README, DLK docstrings
jasasonc Jan 30, 2025
7b7a9b3
Fixed file path in tests
jasasonc Jan 30, 2025
39808eb
docs update
klemengit Feb 3, 2025
959e700
backward compatibility bugfix
klemengit Feb 3, 2025
792e7db
Update README with legacy pyIDI class documentation
klemengit Feb 3, 2025
39ac548
Update README: minor change
klemengit Feb 3, 2025
f5a837c
Disable progress bar in test configurations
klemengit Feb 3, 2025
ef99ea9
Update test configurations to use show_pbar instead of progress_bar
klemengit Feb 3, 2025
6a5b031
Simplify test configurations by removing multiprocessing parameter
klemengit Feb 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,5 @@ server_user_id.txt

/temp

data_synthetic_pyidi_analysis/
data_synthetic_pyidi_analysis/
temp_file/
91 changes: 72 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,83 @@ Image-based Displacement Identification (IDI) implementation in python.

See the [documentation](https://pyidi.readthedocs.io/en/latest/index.html) for `pyIDI`.

### Use Napari UI for quick displacement identification:
## Now version 1.0!

In version 1.0, **we overhauled the package API**. With growing usage in IDEs other than
jupyter notebooks, we have made the package more user-friendly. The new API allows the
autocompletion and documentation of the package to be more accessible in IDEs like
VSCode, Cursor, PyCharm, etc.

To install the new version, use the following command:

```bash
pip install pyidi
```
or to upgrade (if already installed):
```bash
pip install -U pyidi
```

### Whats different?

For the user, the main difference is that instead of calling the `pyIDI` class where the
method is set, first, the `VideoReader` class is called. Then, this instance is passed
to the specific method class. Here is an example:

```python
from pyidi import VideoReader, SimplifiedOpticalFlow

# Read the video
video = VideoReader('video.cih')

# Pass the video to the selected method class
sof = SimplifiedOpticalFlow(video)

sof.set_points(points=[[0, 1], [1, 1], [2, 1]])
sof.configure(...)
displacements = sof.get_displacements()
```

The methods themselves have not changed, only the way they are called. Unfortunately, this
breaks the backward compatibility with the previous version. We apologize for any
inconvenience this may cause. To keep using the old version, please install the package
with the following command:

```bash
pip install pyidi==0.30.2
```

or use the legacy `pyIDI` class:

```python
from pyidi import pyIDI
```

Note that the legacy `pyIDI` class does not necessarily offer the full functionality of the new version.
The legacy `pyIDI` class is only kept for compatibility with the old version and will not be updated.


# Use Napari UI for quick displacement identification:
<img src="docs/source/quick_start/gifs/napari_full_sof.gif" width="800" />


# BASIC USAGE:
Create an instance:
Run GUI by instantiating GUI class (input is VideoReader object):
```python
from pyidi import VideoReader, GUI

# Read the video
video = VideoReader('data/data_synthetic.cih')

# Run GUI
gui = GUI(video)
```
video = pyidi.pyIDI(input_file='video.cih')

Method class (e.g. `SimplifiedOpticalFlow`) is instantiated during the use of GUI. It is accessible in `gui.method`. To get displacements:

```python
method = gui.method
displacements = method.displacements
```

The `pyIDI` method works with various formats: `.cih`, `.cihx`, `.png`, `.avi` etc. Additionally, it can also work with `numpy.ndarray` as input.
Expand All @@ -26,22 +95,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
106 changes: 17 additions & 89 deletions Showcas_LK.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"outputs": [],
"source": [
"filename = 'data/data_synthetic.cih'\n",
"video = pyidi.pyIDI(filename)"
"video = pyidi.VideoReader(filename)"
]
},
{
Expand Down Expand Up @@ -71,7 +71,7 @@
}
],
"source": [
"video.reader.info"
"video.info"
]
},
{
Expand All @@ -87,14 +87,14 @@
"metadata": {},
"outputs": [],
"source": [
"# Points = pyidi.selection.ROISelect(video, roi_size=(21, 21), noverlap=0)"
"Points = pyidi.selection.SubsetSelection(video, roi_size=(11, 11), noverlap=0)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Assigning the points"
"Create the `LucasKanade` object"
]
},
{
Expand All @@ -103,14 +103,14 @@
"metadata": {},
"outputs": [],
"source": [
"# video.set_points(Points.points)"
"idi = pyidi.LucasKanade(video)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Assign the `Lucas Kanade` method"
"Assigning the points"
]
},
{
Expand All @@ -119,17 +119,7 @@
"metadata": {},
"outputs": [],
"source": [
"video.set_method('lk')\n",
"\n",
"reference_image = video.method._set_reference_image(video, video.method.reference_image)\n",
"Gi, Gj = np.gradient(reference_image)\n",
"G = np.sqrt(Gi**2 + Gj**2)\n",
"highest_points = np.argpartition(G.flatten(), -10)[-10:]\n",
"arguments = np.unravel_index(highest_points, G.shape)\n",
"points1d = np.array(arguments).T\n",
"video.set_points(points1d)\n",
"\n",
"video.method.configure()"
"idi.set_points(Points) # The `Points` object can be passed directly to the `set_points` method"
]
},
{
Expand All @@ -147,7 +137,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "51a62fe6402f43bf923beb7de0c519e0",
"model_id": "843cc35f2b764d969e5d59eca39a6b8c",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -164,7 +154,7 @@
"text": [
"--- Starting new analysis ---\n",
" \n",
"Computation start: 2024-11-26 13:39:44.382596\n"
"Computation start: 2024-12-03 07:41:27.317520\n"
]
},
{
Expand All @@ -181,14 +171,13 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Computation duration: 00:00:2.56\n",
"data\\data_synthetic_pyidi_analysis\\analysis_006\\ analysis_006\n"
"Computation duration: 00:00:2.26\n",
"data\\data_synthetic_pyidi_analysis\\analysis_009\\ analysis_009\n"
]
}
],
"source": [
"if __name__ == '__main__':\n",
" displacementes = video.get_displacements(processes=2)"
"displacementes = idi.get_displacements(processes=2)"
]
},
{
Expand All @@ -198,86 +187,25 @@
"An existing analysis can also be loaded without computation and setting the arguments."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"d:\\git_repos\\pyidi\\pyidi\\load_analysis.py:30: ResourceWarning: unclosed file <_io.BufferedReader name='data/data_synthetic_pyidi_analysis/analysis_001\\\\points.pkl'>\n",
" points = pickle.load(open(os.path.join(analysis_path, 'points.pkl'), 'rb'))\n",
"ResourceWarning: Enable tracemalloc to get the object allocation traceback\n",
"d:\\git_repos\\pyidi\\pyidi\\load_analysis.py:32: ResourceWarning: unclosed file <_io.BufferedReader name='data/data_synthetic_pyidi_analysis/analysis_001\\\\results.pkl'>\n",
" results = pickle.load(open(os.path.join(analysis_path, 'results.pkl'), 'rb'))\n",
"ResourceWarning: Enable tracemalloc to get the object allocation traceback\n"
]
}
],
"source": [
"filename = 'data/data_synthetic_pyidi_analysis/analysis_001'\n",
"video_loaded, info_dict = pyidi.load_analysis(filename,)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(10, 101, 2)"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"video_loaded.displacements.shape"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(10, 2)"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"points1d.shape"
"filename = 'data/data_synthetic_pyidi_analysis/analysis_010'\n",
"video_loaded, idi_loaded, info_dict = pyidi.load_analysis(filename)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"d:\\git_repos\\pyidi\\pyidi\\pyidi.py:266: DeprecationWarning: `self.mraw` is deprecated and will be removed in the next version. Please use `self.reader.mraw` instead.\n",
" warnings.warn('`self.mraw` is deprecated and will be removed in the next version. Please use `self.reader.mraw` instead.', DeprecationWarning)\n"
]
},
{
"data": {
"text/plain": [
"(101, 128, 256)"
"(5, 101, 2)"
]
},
"execution_count": 11,
Expand All @@ -286,7 +214,7 @@
}
],
"source": [
"video_loaded.mraw.shape"
"idi_loaded.displacements.shape"
]
},
{
Expand Down
Loading