Skip to content

Commit

Permalink
adding anisotropy param to make_train.py
Browse files Browse the repository at this point in the history
  • Loading branch information
carsen-stringer committed Sep 12, 2024
1 parent f10df0d commit d35083d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
5 changes: 5 additions & 0 deletions cellpose/gui/make_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def main():
input_img_args.add_argument(
'--all_channels', action='store_true', help=
'use all channels in image if using own model and images with special channels')
input_img_args.add_argument("--anisotropy", required=False, default=1.0, type=float,
help="anisotropy of volume in 3D")


# algorithm settings
algorithm_args = parser.add_argument_group("algorithm arguments")
Expand Down Expand Up @@ -74,6 +77,8 @@ def main():
print(npm[p], img[0].shape)
Ly, Lx = img.shape[1:3]
imgs = img[np.random.permutation(img.shape[0])[:args.nimg_per_tif]]
if args.anisotropy > 1.0:
imgs = transforms.resize_image(imgs, Ly=int(args.anisotropy * Ly), Lx=Lx)
for k, img in enumerate(imgs):
if args.tile_norm:
img = transforms.normalize99_tile(img, blocksize=args.tile_norm)
Expand Down
15 changes: 10 additions & 5 deletions docs/train.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,18 @@ the overall normalization scaling on the full images, e.g. ``normalize={"percent
a notebook for example with ``from cellpose import transforms; plt.imshow(transforms.normalize99(img, lower=3, upper=98))``. The default
that will be used for training on the image crops is ``[1, 99]``.

You can create image crops from z-stacks (in XY, YZ and XZ) using the script ``cellpose/gui/make_train.py``:
You can create image crops from z-stacks (in YX, YZ and XZ) using the script ``cellpose/gui/make_train.py``.
If you have anisotropic volumes, then set the ``--anisotropy`` flag to the ratio between pixel size in Z and in YX,
e.g. set ``--anisotropy 5`` for pixel size of 1.0 um in YX and 5.0 um in Z.
See the help message for more information:

::
python cellpose/gui/make_train.py --help
python cellpose\gui\make_train.py --help
usage: make_train.py [-h] [--dir DIR] [--image_path IMAGE_PATH] [--look_one_level_down] [--img_filter IMG_FILTER]
[--channel_axis CHANNEL_AXIS] [--z_axis Z_AXIS] [--chan CHAN] [--chan2 CHAN2] [--invert]
[--all_channels] [--sharpen_radius SHARPEN_RADIUS] [--tile_norm TILE_NORM]
[--nimg_per_tif NIMG_PER_TIF] [--crop_size CROP_SIZE]
[--all_channels] [--anisotropy ANISOTROPY] [--sharpen_radius SHARPEN_RADIUS]
[--tile_norm TILE_NORM] [--nimg_per_tif NIMG_PER_TIF] [--crop_size CROP_SIZE]

cellpose parameters

Expand All @@ -164,6 +167,8 @@ You can create image crops from z-stacks (in XY, YZ and XZ) using the script ``c
--chan2 CHAN2 nuclear channel (if cyto, optional); 0: NONE, 1: RED, 2: GREEN, 3: BLUE. Default: 0
--invert invert grayscale channel
--all_channels use all channels in image if using own model and images with special channels
--anisotropy ANISOTROPY
anisotropy of volume in 3D

algorithm arguments:
--sharpen_radius SHARPEN_RADIUS
Expand All @@ -173,4 +178,4 @@ You can create image crops from z-stacks (in XY, YZ and XZ) using the script ``c
--nimg_per_tif NIMG_PER_TIF
number of crops in XY to save per tiff. Default: 10
--crop_size CROP_SIZE
size of random crop to save. Default: 512
size of random crop to save. Default: 512

0 comments on commit d35083d

Please sign in to comment.