Skip to content

Commit

Permalink
Merge branch 'OpenPIV:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlib authored Jul 19, 2024
2 parents aa6c444 + 713586c commit bf98c9f
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 78 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.10]
python-version: [3.12]
poetry-version: [1.5.0]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4.5.0
- uses: actions/setup-python@v5.1.1
with:
python-version: ${{ matrix.python-version }}
- name: Run image
Expand All @@ -27,4 +27,4 @@ jobs:
PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
run: |
poetry config pypi-token.pypi $PYPI_TOKEN
poetry publish --build
poetry publish --build
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4.5.0
uses: actions/setup-python@v5.1.1
with:
python-version: ${{ matrix.python-version }}
- name: Install poetry
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# OpenPIV
![Build and upload to PyPI](https://github.com/OpenPIV/openpiv-python/workflows/Build%20and%20upload%20to%20PyPI/badge.svg)
[![Python package](https://github.com/OpenPIV/openpiv-python/actions/workflows/testing.yml/badge.svg)](https://github.com/OpenPIV/openpiv-python/actions/workflows/testing.yml)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4409178.svg)](https://doi.org/10.5281/zenodo.4409178)
![PyPI](https://img.shields.io/pypi/v/openpiv)
![Anaconda](https://anaconda.org/openpiv/openpiv/badges/version.svg)
Expand Down Expand Up @@ -32,7 +32,7 @@ Use PyPI: <https://pypi.python.org/pypi/OpenPIV>:

## Or `conda`

conda install -c alexlib openpiv
conda install -c openpiv openpiv

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

Expand Down
120 changes: 58 additions & 62 deletions openpiv/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import numpy as np
from scipy.ndimage import median_filter, gaussian_filter, binary_fill_holes,\
map_coordinates
from skimage import img_as_float, exposure, img_as_ubyte
from skimage.util import img_as_float, img_as_ubyte
from skimage import exposure
from skimage import filters
from skimage.measure import find_contours, approximate_polygon, points_in_poly
from skimage.transform import rescale
Expand Down Expand Up @@ -73,7 +74,7 @@ def dynamic_masking(image, method="edges", filter_size=7, threshold=0.005):
"""
imcopy = np.copy(image)
# stretch the histogram
image = exposure.rescale_intensity(img_as_float(image), in_range=(0, 1))
image = exposure.rescale_intensity(img_as_float(image), in_range='image')
# blur the image, low-pass
blurback = img_as_ubyte(gaussian_filter(image, filter_size))
if method == "edges":
Expand Down Expand Up @@ -132,6 +133,7 @@ def mask_coordinates(image_mask, tolerance=1.5, min_length=10, plot=False):

def prepare_mask_from_polygon(x, y, mask_coords):
""" Converts mask coordinates of the image mask
to the grid of 1/0 on the x,y grid
Inputs:
x,y : grid of x,y points
Expand All @@ -148,8 +150,8 @@ def prepare_mask_on_grid(
x: np.ndarray,
y: np.ndarray,
image_mask: np.ndarray,
)->np.array:
"""_summary_
)->np.ndarray:
"""Converts mask to the grid
Args:
x (np.ndarray): x coordinates of vectors in pixels
Expand Down Expand Up @@ -371,7 +373,7 @@ def contrast_stretch(img, lower_limit = 2, upper_limit = 98):

lower = np.percentile(img, lower_limit)
upper = np.percentile(img, upper_limit)
img = exposure.rescale_intensity(img, in_range = (lower, upper))
img = exposure.rescale_intensity(img, in_range=(lower, upper)) #type:ignore
return img

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


def offset_image(img, offset_x, offset_y, pad = 'zero'):
"""
Offset an image by padding.
# Obsolete, to be removed in the future
# def offset_image(img, offset_x, offset_y, pad='constant'):
# """
# Offset an image by padding.

Parameters
----------
img: image
a two dimensional array of float32 or float64,
but can be uint16, uint8 or similar type
offset_x: int
offset an image by integer values. Positive values shifts
the image to the right and negative values shift to the left
offset_y: int
offset an image by integer values. Positive values shifts
the image to the top and negative values shift to the bottom
pad: str
pad the shift with zeros or a reflection of the shift
Returns
-------
img: image
a transformed two dimensional array of the input image
# Parameters
# ----------
# img: image
# a two dimensional array of float32 or float64,
# but can be uint16, uint8 or similar type

# offset_x: int
# offset an image by integer values. Positive values shifts
# the image to the right and negative values shift to the left

# offset_y: int
# offset an image by integer values. Positive values shifts
# the image to the top and negative values shift to the bottom

# pad: str
# pad the shift with zeros or a reflection of the shift

# Returns
# -------
# img: image
# a transformed two dimensional array of the input image

"""
if pad not in [
'zero', 'reflect'
]:
raise ValueError(f'pad method not supported: {pad}')
end_y, end_x = img.shape
start_x = 0; start_y = 0
if offset_x > 0:
offset_x1 = offset_x
offset_x2 = 0
else:
offset_x1 = 0
offset_x2 = offset_x * -1
start_x = offset_x2
end_x += offset_x2
if offset_y > 0:
offset_y1 = offset_y
offset_y2 = 0
else:
offset_y1 = 0
offset_y2 = offset_y * -1
start_y = offset_y2
end_y += offset_y2
if pad == 'zero':
pad = 'constant'
img = np.pad(
img,
((offset_y1, offset_y2),
(offset_x1, offset_x2)),
mode = pad
)
return img[start_y:end_y, start_x:end_x]
# """
# if pad not in [
# 'zero', 'reflect'
# ]:
# raise ValueError(f'pad method not supported: {pad}')
# end_y, end_x = img.shape
# start_x = 0; start_y = 0
# if offset_x > 0:
# offset_x1 = offset_x
# offset_x2 = 0
# else:
# offset_x1 = 0
# offset_x2 = offset_x * -1
# start_x = offset_x2
# end_x += offset_x2
# if offset_y > 0:
# offset_y1 = offset_y
# offset_y2 = 0
# else:
# offset_y1 = 0
# offset_y2 = offset_y * -1
# start_y = offset_y2
# end_y += offset_y2

# img = np.pad(img, (offset_y1, offset_y2),(offset_x1, offset_x2)), mode=pad)
# return img[start_y:end_y, start_x:end_x]


def stretch_image(img,
Expand Down
14 changes: 7 additions & 7 deletions openpiv/smoothn.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def smoothn(
"""
is_masked = False

if type(y) == ma.core.MaskedArray: # masked array
if type(y) == ma.MaskedArray: # masked array
is_masked = True
mask = y.mask
y = np.array(y)
Expand Down Expand Up @@ -213,7 +213,7 @@ def smoothn(
nof = IsFinite.sum() # number of finite elements
W = W * IsFinite
if any(W < 0):
error("smoothn:NegativeWeights", "Weights must all be >=0")
raise ValueError("smoothn:NegativeWeights", "Weights must all be >=0")
else:
# W = W/np.max(W)
pass
Expand Down Expand Up @@ -320,11 +320,11 @@ def smoothn(
# ---
if isauto:
try:
xpost = array([(0.9 * log10(sMinBnd) + log10(sMaxBnd) * 0.1)])
xpost = np.array([(0.9 * np.log10(sMinBnd) + np.log10(sMaxBnd) * 0.1)])
except:
array([100.0])
np.array([100.0])
else:
xpost = array([log10(s)])
xpost = array([np.log10(s)])
while RobustIterativeProcess:
# --- "amount" of weights (see the function GCVscore)
aow = sum(Wtot) / noe
Expand Down Expand Up @@ -422,7 +422,7 @@ def smoothn(
## Warning messages
# ---
if isauto:
if abs(log10(s) - log10(sMinBnd)) < errp:
if abs(np.log10(s) - np.log10(sMinBnd)) < errp:
warning(
"MATLAB:smoothn:SLowerBound",
[
Expand All @@ -431,7 +431,7 @@ def smoothn(
+ "has been reached. Put s as an input variable if required."
],
)
elif abs(log10(s) - log10(sMaxBnd)) < errp:
elif abs(np.log10(s) - np.log10(sMaxBnd)) < errp:
warning(
"MATLAB:smoothn:SUpperBound",
[
Expand Down
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bf98c9f

Please sign in to comment.