Skip to content
Closed
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ uv.lock
#husky
node_modules

#uv
transforms/images/*/uv.lock

# uv lockfiles (generated; ignore in all nested projects)
**/uv.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.5.6-dev0
current_version = 0.5.4-dev0
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<dev>\d+))?
Expand Down
2 changes: 1 addition & 1 deletion transforms/images/binary-operations-tool/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Binary Operations Plugin (v0.5.6-dev0)
# Binary Operations Plugin (v0.5.4-dev0)

This WIPP plugin does Morphological Image Processing on binary and instance labelled images.
The operations available are:
Expand Down
2 changes: 1 addition & 1 deletion transforms/images/binary-operations-tool/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.6-dev0
0.5.4-dev0
4 changes: 2 additions & 2 deletions transforms/images/binary-operations-tool/plugin.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Binary Operations Plugin",
"version": "0.5.6-dev0",
"containerId": "polusai/binary-operations-tool:0.5.6-dev0",
"version": "0.5.4-dev0",
"containerId": "polusai/binary-operations-tool:0.5.4-dev0",
"title": "Binary Operations Plugin",
"description": "Everything you need to start a WIPP plugin.",
"author": "Nick Schaub (nick.schaub@nih.gov), Madhuri Vihani",
Expand Down
2 changes: 1 addition & 1 deletion transforms/images/binary-operations-tool/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ requires-python = ">=3.11"

[tool.poetry]
name = "polus-images-transforms-images-binary-operations"
version = "0.5.6-dev0"
version = "0.5.4-dev0"
description = ""
authors = ["nicholas-schaub <nick.schaub@nih.gov>", "Madhuri Vihani"]
readme = "README.md"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Binary operations tool."""
__version__ = "0.5.6-dev0"
__version__ = "0.5.4-dev0"

from . import utils
from .binops import Operation
Expand Down
2 changes: 1 addition & 1 deletion transforms/images/image-calculator-tool/.bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.2.4-dev0
current_version = 0.2.3-dev0
commit = False
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<dev>\d+))?
Expand Down
2 changes: 1 addition & 1 deletion transforms/images/image-calculator-tool/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Image Calculator (v0.2.4-dev0)
# Image Calculator (v0.2.3-dev0)

This plugin performs pixel-wise operations between two image collections.
For example, images in one image collection can be subtracted from images in another collection.
Expand Down
2 changes: 1 addition & 1 deletion transforms/images/image-calculator-tool/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.4-dev0
0.2.3-dev0
4 changes: 2 additions & 2 deletions transforms/images/image-calculator-tool/plugin.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "Image Calculator",
"version": "0.2.4-dev0",
"version": "0.2.3-dev0",
"title": "Image Calculator",
"description": "Perform simple mathematical operations on images.",
"author": "Nick Schaub (nick.schaub@nih.gov)",
"institution": "National Center for Advancing Translational Sciences, National Institutes of Health",
"repository": "https://github.com/labshare/polus-plugins",
"website": "https://ncats.nih.gov/preclinical/core/informatics",
"citation": "",
"containerId": "polusai/image-calculator-tool:0.2.4-dev0",
"containerId": "polusai/image-calculator-tool:0.2.3-dev0",
"baseCommand": [
"python3",
"-m",
Expand Down
2 changes: 1 addition & 1 deletion transforms/images/image-calculator-tool/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ requires-python = ">=3.11"

[tool.poetry]
name = "polus-images-transforms-images-image-calculator"
version = "0.2.4-dev0"
version = "0.2.3-dev0"
description = ""
authors = [
"Nicholas Schaub <nick.schaub@nih.gov>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
from .calculator import Operation
from .calculator import process_image

__version__ = "0.2.4-dev0"
__version__ = "0.2.3-dev0"
18 changes: 18 additions & 0 deletions transforms/images/polus-apply-flatfield-plugin/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[project]
name = "polus-apply-flatfield-plugin"
version = "1.2.0"
requires-python = ">=3.13"
dependencies = [
"bfio>=2.5.0",
"filepattern>=2.2.1",
]

[build-system]
requires = ["setuptools>=61.0", "wheel"]
build-backend = "setuptools.build_meta"

[tool.setuptools.package-dir]
"" = "src"

[tool.setuptools]
py-modules = ["main"]
137 changes: 65 additions & 72 deletions transforms/images/polus-apply-flatfield-plugin/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import logging
import os
import typing
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
from pathlib import Path

from bfio import BioReader, BioWriter
from filepattern import FilePattern
import numpy as np
from preadator import ProcessManager

FILE_EXT = os.environ.get("POLUS_EXT", None)
FILE_EXT = FILE_EXT if FILE_EXT is not None else ".ome.tif"
Expand All @@ -21,61 +21,57 @@ def unshade_images(
flatfield: np.ndarray,
darkfield: np.ndarray = None,
):
with ProcessManager.process():

# Initialize the output
X = flatfield.shape[1]
Y = flatfield.shape[0]
N = len(flist)

img_stack = np.zeros((N, Y, X), dtype=np.float32)

# Load the images
def load_and_store(fname, ind):
with ProcessManager.thread() as active_threads:
with BioReader(fname["file"], max_workers=active_threads.count) as br:
img_stack[ind, ...] = np.squeeze(br[:, :, 0, 0, 0])

for ind, fname in enumerate(flist):
ProcessManager.submit_thread(load_and_store, fname, ind)

ProcessManager.join_threads(5)

# Apply flatfield correction
if darkfield is not None:
img_stack -= darkfield

img_stack /= flatfield

# Save outputs
def save_output(fname, ind):
with ProcessManager.thread() as active_threads:
with BioReader(fname["file"], max_workers=active_threads.count) as br:

# replace the file name extension if needed
inp_image = fname["file"]
extension = "".join(
[
suffix
for suffix in inp_image.suffixes[-2:]
if len(suffix) < 6
]
)
out_path = out_dir.joinpath(
inp_image.name.replace(extension, FILE_EXT)
)

with BioWriter(
out_path,
metadata=br.metadata,
max_workers=active_threads.count,
) as bw:
bw[:] = img_stack[ind].astype(bw.dtype)

for ind, fname in enumerate(flist):
ProcessManager.submit_thread(save_output, fname, ind)

ProcessManager.join_threads(5)
max_workers = 5
# Initialize the output
X = flatfield.shape[1]
Y = flatfield.shape[0]
N = len(flist)

img_stack = np.zeros((N, Y, X), dtype=np.float32)

# Load the images
def load_and_store(fname, ind):
with BioReader(fname["file"], max_workers=max_workers) as br:
img_stack[ind, ...] = np.squeeze(br[:, :, 0, 0, 0])

with ThreadPoolExecutor(max_workers=max_workers) as executor:
futures = [
executor.submit(load_and_store, fname, ind)
for ind, fname in enumerate(flist)
]
for f in futures:
f.result()

# Apply flatfield correction
if darkfield is not None:
img_stack -= darkfield

img_stack /= flatfield

# Save outputs
def save_output(fname, ind):
with BioReader(fname["file"], max_workers=max_workers) as br:
inp_image = fname["file"]
extension = "".join(
[suffix for suffix in inp_image.suffixes[-2:] if len(suffix) < 6]
)
out_path = out_dir.joinpath(
inp_image.name.replace(extension, FILE_EXT)
)
with BioWriter(
out_path,
metadata=br.metadata,
max_workers=max_workers,
) as bw:
bw[:] = img_stack[ind].astype(bw.dtype)

with ThreadPoolExecutor(max_workers=max_workers) as executor:
futures = [
executor.submit(save_output, fname, ind)
for ind, fname in enumerate(flist)
]
for f in futures:
f.result()


def unshade_batch(
Expand All @@ -97,17 +93,19 @@ def unshade_batch(
if batches[-1] != len(files):
batches.append(len(files))

for i_start, i_end in zip(batches[:-1], batches[1:]):

ProcessManager.submit_process(
unshade_images,
files[i_start:i_end],
out_dir,
brightfield_image,
darkfield_image,
)

ProcessManager.join_processes()
with ProcessPoolExecutor() as executor:
futures = [
executor.submit(
unshade_images,
files[i_start:i_end],
out_dir,
brightfield_image,
darkfield_image,
)
for i_start, i_end in zip(batches[:-1], batches[1:])
]
for f in futures:
f.result()


def main(
Expand All @@ -134,9 +132,6 @@ def main(
group_by = [v for v in fp.variables if v not in ff_files.variables]
GROUPED = group_by + ["file"]

ProcessManager.init_processes("main", "unshade")
logger.info(f"Running with {ProcessManager.num_processes()} processes.")

for files in fp(group_by=group_by):

flat_path = ff_files.get_matching(
Expand Down Expand Up @@ -168,8 +163,6 @@ def main(

unshade_batch(files, outDir, flat_path, dark_path, photo_path)

# ProcessManager.join_processes()


if __name__ == "__main__":
"""Initialize the logger"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
bfio==2.1.9
filepattern==1.4.7
preadator==0.2.0
bfio>=2.5.0
filepattern>=2.2.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
"""Helpers for tiles, strips, distograms, gradients, and bounding boxes."""
from collections.abc import Generator
from pathlib import Path
from typing import Optional
Expand Down
12 changes: 12 additions & 0 deletions transforms/images/polus-ftl-label-plugin/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[project]
name = "polus-ftl-label-plugin"
version = "0.3.10"
requires-python = ">=3.13"
dependencies = [
"numpy>=2.4.3",
"bfio>=2.5.0",
]

[build-system]
requires = ["setuptools>=41.0.0", "wheel", "setuptools_rust>=0.10.2"]
build-backend = "setuptools.build_meta"
Loading
Loading