basicsr.data.data_util

basicsr.data.data_util.duf_downsample(x, kernel_size=13, scale=4)[source]

Downsamping with Gaussian kernel used in the DUF official code.

Parameters
  • x (Tensor) – Frames to be downsampled, with shape (b, t, c, h, w).

  • kernel_size (int) – Kernel size. Default: 13.

  • scale (int) – Downsampling factor. Supported scale: (2, 3, 4). Default: 4.

Returns

DUF downsampled frames.

Return type

Tensor

basicsr.data.data_util.generate_frame_indices(crt_idx, max_frame_num, num_frames, padding='reflection')[source]

Generate an index list for reading num_frames frames from a sequence of images.

Parameters
  • crt_idx (int) – Current center index.

  • max_frame_num (int) – Max number of the sequence of images (from 1).

  • num_frames (int) – Reading num_frames frames.

  • padding (str) – Padding mode, one of ‘replicate’ | ‘reflection’ | ‘reflection_circle’ | ‘circle’ Examples: current_idx = 0, num_frames = 5 The generated frame indices under different padding mode: replicate: [0, 0, 0, 1, 2] reflection: [2, 1, 0, 1, 2] reflection_circle: [4, 3, 0, 1, 2] circle: [3, 4, 0, 1, 2]

Returns

A list of indices.

Return type

list[int]

basicsr.data.data_util.generate_gaussian_kernel(kernel_size=13, sigma=1.6)[source]

Generate Gaussian kernel used in duf_downsample.

Parameters
  • kernel_size (int) – Kernel size. Default: 13.

  • sigma (float) – Sigma of the Gaussian kernel. Default: 1.6.

Returns

The Gaussian kernel.

Return type

np.array

basicsr.data.data_util.paired_paths_from_folder(folders, keys, filename_tmpl)[source]

Generate paired paths from folders.

Parameters
  • folders (list[str]) – A list of folder path. The order of list should be [input_folder, gt_folder].

  • keys (list[str]) – A list of keys identifying folders. The order should be in consistent with folders, e.g., [‘lq’, ‘gt’].

  • filename_tmpl (str) – Template for each filename. Note that the template excludes the file extension. Usually the filename_tmpl is for files in the input folder.

Returns

Returned path list.

Return type

list[str]

basicsr.data.data_util.paired_paths_from_lmdb(folders, keys)[source]

Generate paired paths from lmdb files.

Contents of lmdb. Taking the lq.lmdb for example, the file structure is:

lq.lmdb ├── data.mdb ├── lock.mdb ├── meta_info.txt

The data.mdb and lock.mdb are standard lmdb files and you can refer to https://lmdb.readthedocs.io/en/release/ for more details.

The meta_info.txt is a specified txt file to record the meta information of our datasets. It will be automatically created when preparing datasets by our provided dataset tools. Each line in the txt file records 1)image name (with extension), 2)image shape, 3)compression level, separated by a white space. Example: baboon.png (120,125,3) 1

We use the image name without extension as the lmdb key. Note that we use the same key for the corresponding lq and gt images.

Parameters
  • folders (list[str]) – A list of folder path. The order of list should be [input_folder, gt_folder].

  • keys (list[str]) – A list of keys identifying folders. The order should be in consistent with folders, e.g., [‘lq’, ‘gt’]. Note that this key is different from lmdb keys.

Returns

Returned path list.

Return type

list[str]

basicsr.data.data_util.paired_paths_from_meta_info_file(folders, keys, meta_info_file, filename_tmpl)[source]

Generate paired paths from an meta information file.

Each line in the meta information file contains the image names and image shape (usually for gt), separated by a white space.

Example of an meta information file: ` 0001_s001.png (480,480,3) 0001_s002.png (480,480,3) `

Parameters
  • folders (list[str]) – A list of folder path. The order of list should be [input_folder, gt_folder].

  • keys (list[str]) – A list of keys identifying folders. The order should be in consistent with folders, e.g., [‘lq’, ‘gt’].

  • meta_info_file (str) – Path to the meta information file.

  • filename_tmpl (str) – Template for each filename. Note that the template excludes the file extension. Usually the filename_tmpl is for files in the input folder.

Returns

Returned path list.

Return type

list[str]

basicsr.data.data_util.paths_from_folder(folder)[source]

Generate paths from folder.

Parameters

folder (str) – Folder path.

Returns

Returned path list.

Return type

list[str]

basicsr.data.data_util.paths_from_lmdb(folder)[source]

Generate paths from lmdb.

Parameters

folder (str) – Folder path.

Returns

Returned path list.

Return type

list[str]

basicsr.data.data_util.read_img_seq(path, require_mod_crop=False, scale=1, return_imgname=False)[source]

Read a sequence of images from a given folder path.

Parameters
  • path (list[str] | str) – List of image paths or image folder path.

  • require_mod_crop (bool) – Require mod crop for each image. Default: False.

  • scale (int) – Scale factor for mod_crop. Default: 1.

  • return_imgname (bool) – Whether return image names. Default False.

Returns

size (t, c, h, w), RGB, [0, 1]. list[str]: Returned image name list.

Return type

Tensor