Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions .github/workflows/httomolib_tests_run.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ jobs:

steps:
- name: Checkout repository code
uses: actions/checkout@v4
uses: actions/checkout@v5

# setup Python 3.10
- name: Setup Python 3.10
uses: actions/setup-python@v4
# setup Python 3.12
- name: Setup Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: '3.12'

# install httomolib
- name: Install httomolib
run: |
run: |
pip install -e .
pip list

Expand Down
21 changes: 14 additions & 7 deletions httomolib/misc/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,15 @@ def save_to_images(

# after saving the image we check if the watermark needs to be added to that image
if watermark_vals is not None:
dec_points = __find_decimals(watermark_vals[idx])
string_to_format = "." + str(dec_points) + "f"
if isinstance(watermark_vals[idx], str):
formatted_string = watermark_vals[idx]
else:
dec_points = __find_decimals(watermark_vals[idx])
string_to_format = "." + str(dec_points) + "f"
formatted_string = format(watermark_vals[idx], string_to_format)
_add_watermark(
filepath_name,
format(watermark_vals[idx], string_to_format),
formatted_string,
fill_val,
stroke_val,
)
Expand All @@ -206,15 +210,18 @@ def save_to_images(

# after saving the image we check if the watermark needs to be added to that image
if watermark_vals is not None:
dec_points = __find_decimals(watermark_vals[0])
string_to_format = "." + str(dec_points) + "f"
if isinstance(watermark_vals[0], str):
formatted_string = watermark_vals[0]
else:
dec_points = __find_decimals(watermark_vals[0])
string_to_format = "." + str(dec_points) + "f"
formatted_string = format(watermark_vals[0], string_to_format)
_add_watermark(
filepath_name,
format(watermark_vals[0], string_to_format),
formatted_string,
fill_val,
stroke_val,
)

if asynchronous:
# Start the event loop to save the images - and wait until it's done
assert queue is not None
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ authors = [
]
classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.12",
]
requires-python = ">=3.10"
requires-python = ">=3.12"
dynamic = ["version"]
dependencies = [
"numpy",
Expand Down
21 changes: 21 additions & 0 deletions tests/test_misc/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,27 @@ def test_save_to_images_watermark(
assert Image.open(f).size == (host_data.shape[2], host_data.shape[0])


@pytest.mark.parametrize(
"dtype", [np.uint8, np.uint16, np.uint32, np.float32, np.float64]
)
def test_save_to_images_watermark_strings(
host_data: np.ndarray, tmp_path: pathlib.Path, dtype: np.dtype
):

images = host_data[:, 50:53, :].astype(dtype)
watermark_vals = ("one", "two", "three")
save_to_images(images, tmp_path / "save_to_images", watermark_vals=watermark_vals)

folder = tmp_path / "save_to_images" / f"images{dtype(0).nbytes * 8}bit_tif"
assert folder.exists()
files = list(folder.glob("*"))

assert len(files) == 3
for f in files:
assert f.name[-3:] == "tif"
assert Image.open(f).size == (host_data.shape[2], host_data.shape[0])


@pytest.mark.parametrize("dtype", [np.uint8])
@pytest.mark.parametrize("file_format", ["jpeg", "png"])
def test_save_to_images_jpeg_png_uint8(
Expand Down
Loading