scico.flax.examples.data_preprocessing#
Image manipulation utils.
Functions
|
Construct a blur kernel as specified. |
|
Preprocess and assemble dataset for training. |
|
Horizontal flip of an image or a batch of images. |
|
Download BSDS500 data from the BSDB project. |
|
Read a collection of color images from a set of files. |
|
Preprocess (scale, crop, etc.) set of images. |
|
Rotate an image, or a batch of images, by 90 degrees. |
Classes
|
Crop central part of an image to a specified size. |
|
Define padded convolutional operator. |
|
Crop an image from a given corner to a specified size. |
|
Add Gaussian noise to an image or a batch of images. |
- scico.flax.examples.data_preprocessing.rotation90(img)[source]#
Rotate an image, or a batch of images, by 90 degrees.
Rotate an image or a batch of images by 90 degrees counterclockwise. An image is an array with size H x W x C with H and W spatial dimensions and C number of channels. A batch of images is an array with size N x H x W x C with N number of images.
- scico.flax.examples.data_preprocessing.flip(img)[source]#
Horizontal flip of an image or a batch of images.
Horizontally flip an image or a batch of images. An image is an array with size H x W x C with H and W spatial dimensions and C number of channels. A batch of images is an array with size N x H x W x C with N number of images.
- class scico.flax.examples.data_preprocessing.CenterCrop(output_size)[source]#
Bases:
object
Crop central part of an image to a specified size.
Crop central part of an image. An image is an array with size H x W x C with H and W spatial dimensions and C number of channels.
- class scico.flax.examples.data_preprocessing.PositionalCrop(output_size)[source]#
Bases:
object
Crop an image from a given corner to a specified size.
Crop an image from a given corner. An image is an array with size H x W x C with H and W spatial dimensions and C number of channels.
- class scico.flax.examples.data_preprocessing.RandomNoise(noise_level, range_flag=False)[source]#
Bases:
object
Add Gaussian noise to an image or a batch of images.
Add Gaussian noise to an image or a batch of images. An image is an array with size H x W x C with H and W spatial dimensions and C number of channels. A batch of images is an array with size N x H x W x C with N number of images. The Gaussian noise is a Gaussian random variable with mean zero and given standard deviation. The standard deviation can be a fix value corresponding to the specified noise level or randomly selected on a range between 50% and 100% of the specified noise level.
- Parameters:
- scico.flax.examples.data_preprocessing.preprocess_images(images, output_size, gray_flag=False, num_img=None, multi_flag=False, stride=None, dtype=<class 'numpy.float32'>)[source]#
Preprocess (scale, crop, etc.) set of images.
Preprocess set of images, converting to gray scale, or cropping or sampling multiple patches from each one, or selecting a subset of them, according to specified setup.
- Parameters:
images (
Array
) – Array of color images.output_size (
Union
[Tuple
[int
,...
],int
]) – Desired output size. If int, square crop is made.gray_flag (
bool
) – IfTrue
, converts to gray scale.num_img (
Optional
[int
]) – If specified, reads that number of images, if not reads all the images in path.multi_flag (
bool
) – IfTrue
, samples multiple patches of specified size in each image.stride (
Union
[Tuple
[int
,...
],int
,None
]) – Stride between patch origins (indexed from left-top corner). If int, the same stride is used in h and w.
- Return type:
- Returns:
Preprocessed array.
- scico.flax.examples.data_preprocessing.build_image_dataset(imgs_train, imgs_test, config, transf=None)[source]#
Preprocess and assemble dataset for training.
Preprocess images according to the specified configuration and assemble a dataset into a structure that can be used for training machine learning models. Keep training and testing partitions. Each dictionary returned has images and labels, which are arrays of dimensions (N, H, W, C) with N: number of images; H, W: spatial dimensions and C: number of channels.
- Parameters:
imgs_train – 4D array (NHWC) with images for training.
imgs_test – 4D array (NHWC) with images for testing.
config (
ConfigImageSetDict
) – Configuration of image data set to read.transf (
Optional
[Callable
]) – Operator for blurring or other non-trivial transformations. Default:None
.
- Return type:
- Returns:
tuple –
A tuple (train_ds, test_ds) containing:
train_ds : Dictionary of training data (includes images and labels).
test_ds : Dictionary of testing data (includes images and labels).
- scico.flax.examples.data_preprocessing.images_read(path, ext='jpg')[source]#
Read a collection of color images from a set of files.
Read a collection of color images from a set of files in the specified directory. All files with extension ext (i.e. matching glob *.ext) in directory path are assumed to be image files and are read. Images may have different aspect ratios, therefore, they are transposed to keep the aspect ratio of the first image read.
- scico.flax.examples.data_preprocessing.get_bsds_data(path, verbose=False)[source]#
Download BSDS500 data from the BSDB project.
Download the BSDS500 dataset, a set of 500 color images of size 481x321 or 321x481, from the Berkeley Segmentation Dataset and Benchmark project.
The downloaded data is converted to .npz format for convenient access via
numpy.load
. The converted data is saved in a file bsds500.npz in the directory specified by path. Note that train and test folders are merged to get a set of 400 images for training while the val folder is reserved as a set of 100 images for testing. This is done in multiple works such as [58].
- scico.flax.examples.data_preprocessing.build_blur_kernel(kernel_size, blur_sigma, dtype=<class 'numpy.float32'>)[source]#
Construct a blur kernel as specified.
- class scico.flax.examples.data_preprocessing.PaddedCircularConvolve(output_size, channels, kernel_size, blur_sigma, dtype=<class 'numpy.float32'>)[source]#
Bases:
LinearOperator
Define padded convolutional operator.
The operator pads the signal with a reflection of the borders before convolving with the kernel provided at initialization. It crops the result of the convolution to maintain the same signal size.
- Parameters: