Skip to content

Commit bf98c9f

Browse files
authored
Merge branch 'OpenPIV:master' into master
2 parents aa6c444 + 713586c commit bf98c9f

6 files changed

Lines changed: 74 additions & 78 deletions

File tree

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ jobs:
99
strategy:
1010
fail-fast: false
1111
matrix:
12-
python-version: [3.10]
12+
python-version: [3.12]
1313
poetry-version: [1.5.0]
1414
os: [ubuntu-latest]
1515
runs-on: ${{ matrix.os }}
1616
steps:
1717
- uses: actions/checkout@v4
18-
- uses: actions/setup-python@v4.5.0
18+
- uses: actions/setup-python@v5.1.1
1919
with:
2020
python-version: ${{ matrix.python-version }}
2121
- name: Run image
@@ -27,4 +27,4 @@ jobs:
2727
PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
2828
run: |
2929
poetry config pypi-token.pypi $PYPI_TOKEN
30-
poetry publish --build
30+
poetry publish --build

.github/workflows/testing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
steps:
1515
- uses: actions/checkout@v4
1616
- name: Set up Python ${{ matrix.python-version }}
17-
uses: actions/setup-python@v4.5.0
17+
uses: actions/setup-python@v5.1.1
1818
with:
1919
python-version: ${{ matrix.python-version }}
2020
- name: Install poetry

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# OpenPIV
2-
![Build and upload to PyPI](https://github.com/OpenPIV/openpiv-python/workflows/Build%20and%20upload%20to%20PyPI/badge.svg)
2+
[![Python package](https://github.com/OpenPIV/openpiv-python/actions/workflows/testing.yml/badge.svg)](https://github.com/OpenPIV/openpiv-python/actions/workflows/testing.yml)
33
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4409178.svg)](https://doi.org/10.5281/zenodo.4409178)
44
![PyPI](https://img.shields.io/pypi/v/openpiv)
55
![Anaconda](https://anaconda.org/openpiv/openpiv/badges/version.svg)
@@ -32,7 +32,7 @@ Use PyPI: <https://pypi.python.org/pypi/OpenPIV>:
3232

3333
## Or `conda`
3434

35-
conda install -c alexlib openpiv
35+
conda install -c openpiv openpiv
3636

3737
## Or [Poetry](https://python-poetry.org/)
3838

openpiv/preprocess.py

Lines changed: 58 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import numpy as np
55
from scipy.ndimage import median_filter, gaussian_filter, binary_fill_holes,\
66
map_coordinates
7-
from skimage import img_as_float, exposure, img_as_ubyte
7+
from skimage.util import img_as_float, img_as_ubyte
8+
from skimage import exposure
89
from skimage import filters
910
from skimage.measure import find_contours, approximate_polygon, points_in_poly
1011
from skimage.transform import rescale
@@ -73,7 +74,7 @@ def dynamic_masking(image, method="edges", filter_size=7, threshold=0.005):
7374
"""
7475
imcopy = np.copy(image)
7576
# stretch the histogram
76-
image = exposure.rescale_intensity(img_as_float(image), in_range=(0, 1))
77+
image = exposure.rescale_intensity(img_as_float(image), in_range='image')
7778
# blur the image, low-pass
7879
blurback = img_as_ubyte(gaussian_filter(image, filter_size))
7980
if method == "edges":
@@ -132,6 +133,7 @@ def mask_coordinates(image_mask, tolerance=1.5, min_length=10, plot=False):
132133

133134
def prepare_mask_from_polygon(x, y, mask_coords):
134135
""" Converts mask coordinates of the image mask
136+
135137
to the grid of 1/0 on the x,y grid
136138
Inputs:
137139
x,y : grid of x,y points
@@ -148,8 +150,8 @@ def prepare_mask_on_grid(
148150
x: np.ndarray,
149151
y: np.ndarray,
150152
image_mask: np.ndarray,
151-
)->np.array:
152-
"""_summary_
153+
)->np.ndarray:
154+
"""Converts mask to the grid
153155
154156
Args:
155157
x (np.ndarray): x coordinates of vectors in pixels
@@ -371,7 +373,7 @@ def contrast_stretch(img, lower_limit = 2, upper_limit = 98):
371373

372374
lower = np.percentile(img, lower_limit)
373375
upper = np.percentile(img, upper_limit)
374-
img = exposure.rescale_intensity(img, in_range = (lower, upper))
376+
img = exposure.rescale_intensity(img, in_range=(lower, upper)) #type:ignore
375377
return img
376378

377379
def threshold_binarize(img, threshold, max_val = 255):
@@ -472,65 +474,59 @@ def gen_lowpass_background(img_list, sigma = 3, resize = None):
472474
background += img
473475
return (background / len(img_list))
474476

475-
476-
def offset_image(img, offset_x, offset_y, pad = 'zero'):
477-
"""
478-
Offset an image by padding.
477+
# Obsolete, to be removed in the future
478+
# def offset_image(img, offset_x, offset_y, pad='constant'):
479+
# """
480+
# Offset an image by padding.
479481

480-
Parameters
481-
----------
482-
img: image
483-
a two dimensional array of float32 or float64,
484-
but can be uint16, uint8 or similar type
485-
486-
offset_x: int
487-
offset an image by integer values. Positive values shifts
488-
the image to the right and negative values shift to the left
489-
490-
offset_y: int
491-
offset an image by integer values. Positive values shifts
492-
the image to the top and negative values shift to the bottom
493-
494-
pad: str
495-
pad the shift with zeros or a reflection of the shift
496-
497-
Returns
498-
-------
499-
img: image
500-
a transformed two dimensional array of the input image
482+
# Parameters
483+
# ----------
484+
# img: image
485+
# a two dimensional array of float32 or float64,
486+
# but can be uint16, uint8 or similar type
487+
488+
# offset_x: int
489+
# offset an image by integer values. Positive values shifts
490+
# the image to the right and negative values shift to the left
491+
492+
# offset_y: int
493+
# offset an image by integer values. Positive values shifts
494+
# the image to the top and negative values shift to the bottom
495+
496+
# pad: str
497+
# pad the shift with zeros or a reflection of the shift
498+
499+
# Returns
500+
# -------
501+
# img: image
502+
# a transformed two dimensional array of the input image
501503

502-
"""
503-
if pad not in [
504-
'zero', 'reflect'
505-
]:
506-
raise ValueError(f'pad method not supported: {pad}')
507-
end_y, end_x = img.shape
508-
start_x = 0; start_y = 0
509-
if offset_x > 0:
510-
offset_x1 = offset_x
511-
offset_x2 = 0
512-
else:
513-
offset_x1 = 0
514-
offset_x2 = offset_x * -1
515-
start_x = offset_x2
516-
end_x += offset_x2
517-
if offset_y > 0:
518-
offset_y1 = offset_y
519-
offset_y2 = 0
520-
else:
521-
offset_y1 = 0
522-
offset_y2 = offset_y * -1
523-
start_y = offset_y2
524-
end_y += offset_y2
525-
if pad == 'zero':
526-
pad = 'constant'
527-
img = np.pad(
528-
img,
529-
((offset_y1, offset_y2),
530-
(offset_x1, offset_x2)),
531-
mode = pad
532-
)
533-
return img[start_y:end_y, start_x:end_x]
504+
# """
505+
# if pad not in [
506+
# 'zero', 'reflect'
507+
# ]:
508+
# raise ValueError(f'pad method not supported: {pad}')
509+
# end_y, end_x = img.shape
510+
# start_x = 0; start_y = 0
511+
# if offset_x > 0:
512+
# offset_x1 = offset_x
513+
# offset_x2 = 0
514+
# else:
515+
# offset_x1 = 0
516+
# offset_x2 = offset_x * -1
517+
# start_x = offset_x2
518+
# end_x += offset_x2
519+
# if offset_y > 0:
520+
# offset_y1 = offset_y
521+
# offset_y2 = 0
522+
# else:
523+
# offset_y1 = 0
524+
# offset_y2 = offset_y * -1
525+
# start_y = offset_y2
526+
# end_y += offset_y2
527+
528+
# img = np.pad(img, (offset_y1, offset_y2),(offset_x1, offset_x2)), mode=pad)
529+
# return img[start_y:end_y, start_x:end_x]
534530

535531

536532
def stretch_image(img,

openpiv/smoothn.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def smoothn(
157157
"""
158158
is_masked = False
159159

160-
if type(y) == ma.core.MaskedArray: # masked array
160+
if type(y) == ma.MaskedArray: # masked array
161161
is_masked = True
162162
mask = y.mask
163163
y = np.array(y)
@@ -213,7 +213,7 @@ def smoothn(
213213
nof = IsFinite.sum() # number of finite elements
214214
W = W * IsFinite
215215
if any(W < 0):
216-
error("smoothn:NegativeWeights", "Weights must all be >=0")
216+
raise ValueError("smoothn:NegativeWeights", "Weights must all be >=0")
217217
else:
218218
# W = W/np.max(W)
219219
pass
@@ -320,11 +320,11 @@ def smoothn(
320320
# ---
321321
if isauto:
322322
try:
323-
xpost = array([(0.9 * log10(sMinBnd) + log10(sMaxBnd) * 0.1)])
323+
xpost = np.array([(0.9 * np.log10(sMinBnd) + np.log10(sMaxBnd) * 0.1)])
324324
except:
325-
array([100.0])
325+
np.array([100.0])
326326
else:
327-
xpost = array([log10(s)])
327+
xpost = array([np.log10(s)])
328328
while RobustIterativeProcess:
329329
# --- "amount" of weights (see the function GCVscore)
330330
aow = sum(Wtot) / noe
@@ -422,7 +422,7 @@ def smoothn(
422422
## Warning messages
423423
# ---
424424
if isauto:
425-
if abs(log10(s) - log10(sMinBnd)) < errp:
425+
if abs(np.log10(s) - np.log10(sMinBnd)) < errp:
426426
warning(
427427
"MATLAB:smoothn:SLowerBound",
428428
[
@@ -431,7 +431,7 @@ def smoothn(
431431
+ "has been reached. Put s as an input variable if required."
432432
],
433433
)
434-
elif abs(log10(s) - log10(sMaxBnd)) < errp:
434+
elif abs(np.log10(s) - np.log10(sMaxBnd)) < errp:
435435
warning(
436436
"MATLAB:smoothn:SUpperBound",
437437
[

poetry.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)