- transforms bugfix: swap xy
- save as movie: progress bar - swap command line argument out for --write
This commit is contained in:
@@ -18,7 +18,7 @@ pip install ndbioimage
|
|||||||
```
|
```
|
||||||
|
|
||||||
### Installation with option to write mp4 or mkv:
|
### Installation with option to write mp4 or mkv:
|
||||||
Work in progress!
|
Work in progress! Make sure ffmpeg is installed.
|
||||||
|
|
||||||
```
|
```
|
||||||
pip install ndbioimage[write]
|
pip install ndbioimage[write]
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import numpy as np
|
|||||||
import yaml
|
import yaml
|
||||||
from numpy.typing import ArrayLike, DTypeLike
|
from numpy.typing import ArrayLike, DTypeLike
|
||||||
from ome_types import OME, from_xml, model, ureg
|
from ome_types import OME, from_xml, model, ureg
|
||||||
|
from parfor import pmap
|
||||||
from pint import set_application_registry
|
from pint import set_application_registry
|
||||||
from tiffwrite import IFD, IJTiffFile # noqa
|
from tiffwrite import IFD, IJTiffFile # noqa
|
||||||
from tqdm.auto import tqdm, trange
|
from tqdm.auto import tqdm, trange
|
||||||
@@ -963,7 +964,7 @@ class Imread(np.lib.mixins.NDArrayOperatorsMixin, ABC):
|
|||||||
c: int | Sequence[int] = None, z: int | Sequence[int] = None, # noqa
|
c: int | Sequence[int] = None, z: int | Sequence[int] = None, # noqa
|
||||||
t: int | Sequence[int] = None, # noqa
|
t: int | Sequence[int] = None, # noqa
|
||||||
colors: tuple[str] = None, brightnesses: tuple[float] = None,
|
colors: tuple[str] = None, brightnesses: tuple[float] = None,
|
||||||
scale: int = None) -> None:
|
scale: int = None, bar: bool = True) -> None:
|
||||||
""" saves the image as a mp4 or mkv file """
|
""" saves the image as a mp4 or mkv file """
|
||||||
from matplotlib.colors import to_rgb
|
from matplotlib.colors import to_rgb
|
||||||
from skvideo.io import FFmpegWriter
|
from skvideo.io import FFmpegWriter
|
||||||
@@ -995,7 +996,7 @@ class Imread(np.lib.mixins.NDArrayOperatorsMixin, ABC):
|
|||||||
f'scale={self.shape["x"] * scale}:{self.shape["y"] * scale}:flags=neighbor'}
|
f'scale={self.shape["x"] * scale}:{self.shape["y"] * scale}:flags=neighbor'}
|
||||||
) as movie:
|
) as movie:
|
||||||
im = self.transpose('tzcyx')
|
im = self.transpose('tzcyx')
|
||||||
for t in trange(self.shape['t'], desc='Saving movie'):
|
for t in trange(self.shape['t'], desc='Saving movie', disable=not bar):
|
||||||
movie.writeFrame(np.max([cframe(yx, c, a, b / s, scale)
|
movie.writeFrame(np.max([cframe(yx, c, a, b / s, scale)
|
||||||
for yx, a, b, c, s in zip(im[t].max('z'), *ab, colors, brightnesses)], 0))
|
for yx, a, b, c, s in zip(im[t].max('z'), *ab, colors, brightnesses)], 0))
|
||||||
|
|
||||||
@@ -1281,8 +1282,9 @@ class AbstractReader(Imread, metaclass=ABCMeta):
|
|||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
parser = ArgumentParser(description='Display info and save as tif')
|
parser = ArgumentParser(description='Display info and save as tif')
|
||||||
parser.add_argument('file', help='image_file')
|
parser.add_argument('-v', '--version', action='version', version=__version__)
|
||||||
parser.add_argument('out', help='path to tif/movie out', type=str, default=None, nargs='?')
|
parser.add_argument('file', help='image_file', type=str, nargs='*')
|
||||||
|
parser.add_argument('-w', '--write', help='path to tif/movie out', type=str, default=None)
|
||||||
parser.add_argument('-o', '--extract_ome', help='extract ome to xml file', action='store_true')
|
parser.add_argument('-o', '--extract_ome', help='extract ome to xml file', action='store_true')
|
||||||
parser.add_argument('-r', '--register', help='register channels', action='store_true')
|
parser.add_argument('-r', '--register', help='register channels', action='store_true')
|
||||||
parser.add_argument('-c', '--channel', help='channel', type=int, default=None)
|
parser.add_argument('-c', '--channel', help='channel', type=int, default=None)
|
||||||
@@ -1296,23 +1298,28 @@ def main() -> None:
|
|||||||
parser.add_argument('-S', '--movie-scale', help='upscale movie xy size, int', type=int)
|
parser.add_argument('-S', '--movie-scale', help='upscale movie xy size, int', type=int)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
with Imread(args.file) as im:
|
def fun(file: Path) -> str: # noqa
|
||||||
|
with Imread(file) as im: # noqa
|
||||||
if args.register:
|
if args.register:
|
||||||
im = im.with_transform()
|
im = im.with_transform() # noqa
|
||||||
print(im.summary)
|
if args.write:
|
||||||
if args.out:
|
write = Path(args.write).absolute() # noqa
|
||||||
out = Path(args.out).absolute()
|
write.parent.mkdir(parents=True, exist_ok=True)
|
||||||
out.parent.mkdir(parents=True, exist_ok=True)
|
if write.exists() and not args.force:
|
||||||
if out.exists() and not args.force:
|
|
||||||
print(f'File {args.out} exists already, add the -f flag if you want to overwrite it.')
|
print(f'File {args.out} exists already, add the -f flag if you want to overwrite it.')
|
||||||
elif out.suffix in ('.mkv', '.mp4'):
|
elif write.suffix in ('.mkv', '.mp4'):
|
||||||
im.save_as_movie(out, args.channel, args.zslice, args.time,
|
im.save_as_movie(write, args.channel, args.zslice, args.time, args.movie_colors,
|
||||||
args.movie_colors, args.movie_brightnesses, args.movie_scale)
|
args.movie_brightnesses, args.movie_scale, bar=len(args.file) == 1)
|
||||||
else:
|
else:
|
||||||
im.save_as_tiff(out, args.channel, args.zslice, args.time, args.split)
|
im.save_as_tiff(write, args.channel, args.zslice, args.time, args.split, bar=len(args.file) == 1)
|
||||||
if args.extract_ome:
|
if args.extract_ome:
|
||||||
with open(im.path.with_suffix('.ome.xml'), 'w') as f:
|
with open(im.path.with_suffix('.ome.xml'), 'w') as f:
|
||||||
f.write(im.ome.to_xml())
|
f.write(im.ome.to_xml())
|
||||||
|
return im.summary
|
||||||
|
|
||||||
|
summaries = pmap(fun, args.file)
|
||||||
|
if len(args.file) == 1:
|
||||||
|
print(summaries[0])
|
||||||
|
|
||||||
|
|
||||||
from .readers import * # noqa
|
from .readers import * # noqa
|
||||||
|
|||||||
@@ -565,7 +565,7 @@ class OmeParse:
|
|||||||
exposure_times = [None] * len(self.channels_im)
|
exposure_times = [None] * len(self.channels_im)
|
||||||
delta_ts = self.attachments['TimeStamps'].data()
|
delta_ts = self.attachments['TimeStamps'].data()
|
||||||
dt = np.diff(delta_ts)
|
dt = np.diff(delta_ts)
|
||||||
if np.std(dt) / np.mean(dt) > 0.02:
|
if len(dt) and np.std(dt) / np.mean(dt) > 0.02:
|
||||||
dt = np.median(dt[dt > 0])
|
dt = np.median(dt[dt > 0])
|
||||||
delta_ts = dt * np.arange(len(delta_ts))
|
delta_ts = dt * np.arange(len(delta_ts))
|
||||||
warnings.warn(f'delta_t is inconsistent, using median value: {dt}')
|
warnings.warn(f'delta_t is inconsistent, using median value: {dt}')
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ class Transforms(dict):
|
|||||||
in the horizontal direction """
|
in the horizontal direction """
|
||||||
from . import Imread
|
from . import Imread
|
||||||
|
|
||||||
with Imread(bead_file, axes='zcxy') as im: # noqa
|
with Imread(bead_file, axes='zcyx') as im: # noqa
|
||||||
max_ims = im.max('z')
|
max_ims = im.max('z')
|
||||||
goodch = [c for c, max_im in enumerate(max_ims) if not im.is_noise(max_im)]
|
goodch = [c for c, max_im in enumerate(max_ims) if not im.is_noise(max_im)]
|
||||||
if not goodch:
|
if not goodch:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "ndbioimage"
|
name = "ndbioimage"
|
||||||
version = "2024.5.2"
|
version = "2024.7.0"
|
||||||
description = "Bio image reading, metadata and some affine registration."
|
description = "Bio image reading, metadata and some affine registration."
|
||||||
authors = ["W. Pomp <w.pomp@nki.nl>"]
|
authors = ["W. Pomp <w.pomp@nki.nl>"]
|
||||||
license = "GPLv3"
|
license = "GPLv3"
|
||||||
|
|||||||
Reference in New Issue
Block a user