Masking utilities

Simple methods to help in manipulating images.

library.utilities.utilities_mask.apply_mask(img, mask, infile)

Apply image mask to image.

Parameters:
  • img – numpy array of image

  • mask – numpy array of mask

  • infile – path to file

Returns:

numpy array of cleaned image

library.utilities.utilities_mask.clean_and_rotate_image(file_key)

The main function that uses the user edited mask to crop out the tissue from surrounding debris. It also rotates the image to a usual orientation (where the olfactory bulb is facing left and the cerebellum is facing right. The hippocampus is facing up and the brainstem is facing down)

Parameters:

file_key – is a tuple of the following:

  • infile file path of image to read

  • outpath file path of image to write

  • mask binary mask image of the image

  • rotation number of 90 degree rotations

  • flip either flip or flop

  • max_width width of image

  • max_height height of image

  • scale used in scaling. Gotten from the histogram

Returns:

nothing. we write the image to disk

library.utilities.utilities_mask.combine_dims(a)

Combines dimensions of a numpy array

Parameters:

a – numpy array

Returns:

numpy array

library.utilities.utilities_mask.crop_image(img, mask)

Crop image to remove parts of image not in mask

Parameters:
  • img – numpy array of image

  • mask – numpy array of mask

Returns:

numpy array of cropped image

library.utilities.utilities_mask.equalized(fixed, cliplimit=5)

Takes an image that has already been scaled and uses opencv adaptive histogram equalization. This cases uses 5 as the clip limit and splits the image into rows and columns. A higher cliplimit will make the image brighter. A cliplimit of 1 will do nothing.

Parameters:

fixed – image we are working on

Returns:

a better looking image

library.utilities.utilities_mask.merge_mask(image, mask)

Merge image with mask [so user can edit] stack 3 channels on single image (black background, image, then mask)

Parameters:
  • image – numpy array of the image

  • mask – numpy array of the mask

Returns:

merged numpy array

library.utilities.utilities_mask.normalize16(img)
library.utilities.utilities_mask.normalize8(img)
library.utilities.utilities_mask.normalize_image(img)

This is a simple opencv image normalization for 16 bit images.

Parameters:

img – the numpy array of the 16bit image

Return img:

the normalized image

library.utilities.utilities_mask.place_image(img, file: str, max_width, max_height, bgcolor=None)

Places the image in a padded one size container with the correct background

Parameters:
  • img – image we are working on.

  • file – file name and path location

  • max_width – width to pad

  • max_height – height to pad

  • bgcolor – background color of image, 0 for NTB, white for thionin

Returns:

placed image centered in the correct size.

library.utilities.utilities_mask.rotate_image(img, file: str, rotation: int)

Rotate the image by the number of rotation(s)

Rotate the image by the number of rotation :param img: image to work on :param file: file name and path :param rotation: number of rotations, 1 = 90degrees clockwise :return: rotated image

library.utilities.utilities_mask.scaled(img, mask, scale=30000)

First we find really high values, which are the bright spots and turn them down

library.utilities.utilities_mask.scaledXXX(img, mask, scale=30000)

This scales the image to the limit specified. You can get this value by looking at the combined histogram of the image stack. It is quite often less than 30000 for channel 1. One of the reasons this takes so much RAM is a large float64 array is being multiplied by another large array. That is WHERE all the RAM is going!!!!!

Parameters:
  • img – image we are working on.

  • mask – binary mask file

  • epsilon

  • limit – max value we wish to scale to

Returns:

scaled image in 16bit format

library.utilities.utilities_mask.smooth_image(gray)