login.py
This module emulates MATLAB functions using our chosen library suite
bwareaopen = skimage.morphology.remove_small_objects module-attribute
Just skimage.morphology.remove_small_objects() see docs for more
bwlabel = scipy.ndimage.label module-attribute
just scipy.ndimage.label() see docs for more
histeq = skimage.exposure.equalize_hist module-attribute
Just skimage.exposure.equalize_hist() see docs for more
imbothat = skimage.morphology.black_tophat module-attribute
just skimage.morphology.black_tophat() see docs for more
imclose = skimage.morphology.closing module-attribute
just skimage.morphology.closing() see docs for more
imdilate = skimage.morphology.dilation module-attribute
Just skimage.morphology.dilation() see docs for more
imerode = skimage.morphology.erosion module-attribute
Just skimage.morphology.erosion() see docs for more
imfill = skimage.morphology.remove_small_holes module-attribute
Just skimage.morphology.remove_small_holes() see docs for more
imgaussfilt = scipy.ndimage.gaussian_filter module-attribute
just scipy.ndimage.gaussian_filter() see docs for more
imopen = skimage.morphology.opening module-attribute
just skimage.morphology.opening() see docs for more
impyramid_expand = skimage.transform.pyramid_expand module-attribute
just skimage.transform.pyramid_expand() see docs for more
impyramid_reduce = skimage.transform.pyramid_reduce module-attribute
just skimage.transform.pyramid_reduce() see docs for more
imreconstruct = skimage.morphology.reconstruction module-attribute
just skimage.morphology.reconstruction() see docs for more
imtophat = skimage.morphology.white_tophat module-attribute
just skimage.morphology.white_tophat() see docs for more
medfilt2 = skimage.filters.rank.median module-attribute
just skimage.filters.rank.median() see docs for more
regionprops = skimage.measure.regionprops module-attribute
just skimage.measure.regionprops() see docs for more
rgb2gray = skimage.color.rgb2gray module-attribute
Just skimage.color.rgb2gray() see docs for more
watershed = skimage.segmentation.watershed module-attribute
just skimage.segmentation.watershed() see docs for more
EdgeDetectionMethods
Bases: Enum
List of available edge detection methods
Source code in lavlab/imsuite.py
32 33 34 35 36 37 38 | |
apply_mask(img, mask)
Applies a binary mask to an image using PyVips.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img | ndarray | Image as a NumPy array. | required |
mask | ndarray | Binary mask as a NumPy array (same dimensions as img). | required |
Returns:
| Type | Description |
|---|---|
ndarray | Image with the mask applied. |
Source code in lavlab/imsuite.py
856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 | |
dicomread(image_path, as_dataset=False)
Reads a dicom from a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_path | PathLike or str | Path to a dicom file. | required |
Returns:
| Type | Description |
|---|---|
ndarray or Dataset | Array of pixel values, or Dataset if as_dataset=True. |
Source code in lavlab/imsuite.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
dicomread_volume(dicom_dir, as_sequence=False)
Reads a dicom series from a directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dicom_dir | PathLike or str or list[BytesIO or PathLike or str] | Path to directory with the dicoms or list of dicoms as path or bytes. | required |
as_sequence | bool | If True, returns a pydicom sequence of pydicom datasets, by default False. | False |
Returns:
| Type | Description |
|---|---|
ndarray or Sequence | Dicom series as numpy volume, or Sequence if as_sequence=True. |
Source code in lavlab/imsuite.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
dicomseg_to_nifti_vol(dicom_seg_ds)
Converts a DICOM Segmentation object to a 3D numpy array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dicom_seg_ds | Segmentation | DICOM Segmentation object. | required |
Returns:
| Type | Description |
|---|---|
ndarray | 3D numpy array of the segmentation. |
Source code in lavlab/imsuite.py
929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 | |
dicomsegread(image_path, as_volume)
Reads a dicom segmentation from a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_path | PathLike or str | Path to a dicom segmentation file. | required |
Returns:
| Type | Description |
|---|---|
ndarray | Array of pixel values. |
Source code in lavlab/imsuite.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
dicomwrite(img, path, write_like_original=False)
Writes an image to path. kwargs are passthrough to wrapped function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img | ndarray or Dataset | Numpy array or Dicom dataset. If array, Dicom dataset is created. | required |
path | PathLike or str | Path to desired file. | required |
kwargs | dict | Additional arguments to pass to pydicom.dcmwrite. | required |
Returns:
| Type | Description |
|---|---|
str | Path of newly created file. |
Source code in lavlab/imsuite.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
draw_shapes(img, shape_points)
Draws a list of shape points onto the input image using PyVips with SVG xml.
Warnings
No safety checks! Make sure img and shape_points are for the same downsample factor!
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img | Union[ndarray, Image] | Input image as a NumPy array or pyvips Image. | required |
shape_points | List[Tuple[int, Tuple[int, int, int], List[Tuple[int, int]]]] | List of tuples containing shape ID, RGB color, and list of points. Expected to use output from lavlab.omero_util.getShapesAsPoints. | required |
Returns:
| Type | Description |
|---|---|
Union[ndarray, Image] | Modified image with shapes drawn, same type as input. |
Source code in lavlab/imsuite.py
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 | |
edge(img_arr, method='SOBEL', **kwargs)
Edge detection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_arr | ndarray | Input image as a numpy array. | required |
method | str | One of the enumerated methods: SOBEL, PREWITT, ROBERTS, CANNY. Defaults to SOBEL. | 'SOBEL' |
Returns:
| Type | Description |
|---|---|
ndarray | Edge map. |
Source code in lavlab/imsuite.py
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 | |
get_color_region_contours(img_arr, rgb_val, axis=-1)
Finds the contours of all areas with a given rgb value. Useful for finding drawn ROIs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_arr | ndarray | Image with ROIs. Converts PIL Image to np array for processing. | required |
rgb_val | tuple[int, int, int] | Red, Green, and Blue values for the roi color. | required |
axis | Which axis is the color channel. Default is the last axis [:,:,color] | -1 |
Returns:
| Type | Description |
|---|---|
list[tuple[int(None), rgb_val, contours]] | Returns list of lavlab shapes. |
Source code in lavlab/imsuite.py
898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 | |
get_downsample_from_dimensions(base_shape, sample_shape)
Essentially an alias for np.divide().
Finds the ratio between a base array shape and a sample array shape by dividing each axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_shape | tuple[int, ...] | Shape of the larger image. (Image.size / base_nparray.shape) | required |
sample_shape | tuple[int, ...] | Shape of the smaller image. (Image.size / sample_nparray.shape) | required |
Raises:
| Type | Description |
|---|---|
AssertionError | Asserts that the input shapes have the same amount of axes |
Returns:
| Type | Description |
|---|---|
tuple(int) * x | Returns a tuple containing the downsample factor of each axis for the sample array. |
Source code in lavlab/imsuite.py
965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 | |
imadjust(img_arr, tol=1, vin=(0, 255), vout=(0, 255))
Matlab's imadjust in Python.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_arr | ndarray | Grayscale image. | required |
tol | int | Tolerance, from 0 to 100, defaults to 1. | 1 |
vin | tuple[int, int] | Input image bounds, defaults to (0,255). | (0, 255) |
vout | tuple[int, int] | Output image bounds, defaults to (0,255). | (0, 255) |
Returns:
| Type | Description |
|---|---|
ndarray | Intensity adjusted image. |
Source code in lavlab/imsuite.py
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 | |
imbinarize(image)
Generates a binary image from a grayscale image using Otsu's thresholding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image | ndarray | numpy array | required |
Returns:
| Type | Description |
|---|---|
ndarray | binary image |
Source code in lavlab/imsuite.py
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 | |
imcomplement(img_arr)
Generates the image's complement (inverts the image).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_arr | ndarray | Input image. | required |
Returns:
| Type | Description |
|---|---|
ndarray | Inverted image. |
Source code in lavlab/imsuite.py
669 670 671 672 673 674 675 676 677 678 679 680 681 682 | |
imcrop(img_arr, dims)
Crops a region from an image using pyvips
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_arr | Union[ndarray, Image] | Input image as a NumPy array or pyvips Image. | required |
dims | tuple[int, int, int, int] | Desired dimensions: left, top, width, height. | required |
Returns:
| Type | Description |
|---|---|
Union[ndarray, Image] | Cropped image. |
Source code in lavlab/imsuite.py
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 | |
imhist(img_arr, bins=256)
Plots and displays histogram of image intensity values
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_arr | ndarray | Input image. | required |
bins | int | Number of bins, defaults to 256. | 256 |
Returns:
| Type | Description |
|---|---|
None | |
Source code in lavlab/imsuite.py
643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 | |
imread(image_path, wild=False)
Loads an image from a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_path | Union[PathLike, BinaryIO] | Path to image. | required |
wild | bool | If True, will not warn about niche formats, by default False. | False |
Returns:
| Type | Description |
|---|---|
ndarray | Array of pixel values. |
Warnings
This function can cause an OOM error if the image is too large! Use wsiread if your image is large.
Source code in lavlab/imsuite.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
imresize(img, factor)
Convenience wrapper for resize functions. Uses pyvips for 2D and skimage for 3D.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img | Union[ndarray, Image] | Input image as a NumPy array or pyvips Image. | required |
factor | Union[int, float, Tuple[int, ...]] | Scale factor (if int or float) or desired dimensions (if tuple). | required |
Returns:
| Type | Description |
|---|---|
Union[ndarray, Image] | Resized image as a NumPy array or pyvips Image. |
Source code in lavlab/imsuite.py
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 | |
imresize2d(img, scale)
Resizes a 2D image using pyvips' resize function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img | Image | Input 2D image. | required |
target_size | Tuple[int, int] | Scale factor h and v. | required |
Returns:
| Type | Description |
|---|---|
Image | Resized image as a pyvips Image. |
Source code in lavlab/imsuite.py
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 | |
imresize3d(img, target_size)
Resizes a 3D image using skimage's resize function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img | ndarray | Input 3D image. | required |
target_size | Tuple[int, int, int] | Desired dimensions as a tuple of (depth, height, width). | required |
Returns:
| Type | Description |
|---|---|
ndarray | Resized image as a NumPy array. |
Source code in lavlab/imsuite.py
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | |
imrotate(img_arr, degrees)
Rotates an input image using pyvips.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_arr | Union[ndarray, Image] | Input image as a NumPy array or pyvips Image. | required |
degrees | int or float | Rotation in degrees. | required |
Returns:
| Type | Description |
|---|---|
Union[ndarray, Image] | Rotated image. |
Source code in lavlab/imsuite.py
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 | |
imshow(image, **kwargs)
Just matplotlib.pyplot.imshow() see docs for more
Source code in lavlab/imsuite.py
706 707 708 709 | |
imwarp(img_arr, affine_matrix)
Affine warps a region from an image using pyvips
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_arr | Union[ndarray, Image] | Input image as a NumPy array or pyvips Image. | required |
affine | tuple[float, float, float, float] | 4 element affine transform matrix | required |
Returns:
| Type | Description |
|---|---|
Union[ndarray, Image] | Warped image |
Source code in lavlab/imsuite.py
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | |
imwrite(img, path, **kwargs)
Writes an image to path. kwargs are passthrough to wrapped function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img | Union[ndarray, Image] | Numpy array or PyVips image. | required |
path | PathLike or str | Path to desired file. | required |
Returns:
| Type | Description |
|---|---|
str | Path of newly created file. |
Source code in lavlab/imsuite.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
niftiread(image_path, as_nib=False)
Loads a nifti from a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_path | PathLike or str | Path to nifti. | required |
as_nib | bool | If True, returns a nibabel image class, by default False. | False |
Returns:
| Type | Description |
|---|---|
ndarray or FileBasedImage | Array of pixel values or appropriate Nifti image class when as_nib=True. |
Source code in lavlab/imsuite.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
niftiwrite(img, path, affine=None, **kwargs)
Writes an image to path. kwargs are passthrough to wrapped function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img | ndarray or Nifti1Image or Nifti2Image | Numpy array or Nifti image. If array, Nifti image is created. | required |
path | PathLike or str | Path to desired file. | required |
affine | ndarray | Affine matrix for the image, by default uses nibabel's default. | None |
kwargs | dict | Additional arguments to pass to nib.save. | {} |
Returns:
| Type | Description |
|---|---|
str | Path of newly created file. |
Source code in lavlab/imsuite.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | |
wsiread(image_path)
Reads a Whole Slide Image from a file.
Allows operations on images larger than memory. wrapper for pyvips.Image.new_from_file()
Warnings
This function does not return a numpy array! You'll need to use proper WSI workflows (like tilewise operations) to do analyses on this! See the pyvips documentation for more information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_path | os.PathLike or string representing a file | Path to WSI. | required |
Returns:
| Type | Description |
|---|---|
Image | PyVips Image, see documentation for usage. |
Source code in lavlab/imsuite.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
wsiwrite(img, path, use_fast_compression=None, **kwargs)
Writes an image to path. kwargs are passthrough to wrapped function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img | Image | PyVips image. | required |
path | PathLike or str | Path to desired file. | required |
use_fast_compression | bool | Use fast compression as configured in context, by default uses bool from config. | None |
Returns:
| Type | Description |
|---|---|
str | Path of newly created file. |
Source code in lavlab/imsuite.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |