def METHOD_NAME(index, num_patches):
    """Generate data sample.
    Extract patches and apply preprocessing tricks.
    """
    # Read image from file
    file_name, _ = samples[index]
    file_name = os.path.join(data_dir, file_name)
    img = cv2.imdecode(np.fromfile(file_name, dtype=np.uint8),
                       cv2.IMREAD_COLOR)
    # Crop to get square image
    size = min(img.shape[0], img.shape[1])
    y = (img.shape[0] - size) // 2
    x = (img.shape[1] - size) // 2
    img = img[y:y+size, x:x+size, :]
    # Extract patches
    patterns = None
    if num_patches == 2:
        patterns = patterns_2patch
    if num_patches == 3:
        patterns = patterns_3patch
    if num_patches == 4:
        patterns = patterns_4patch
    if num_patches == 5:
        patterns = patterns_5patch
    patches, label = extract_patches(img, patterns)
    # Randomly rotate patches
    rotate_type = random.randint(0, 3)
    for i, patch in enumerate(patches):
        patch = np.rot90(patch, rotate_type, axes=(0,1))
        patches[i] = patch
    label = label + rotate_type * len(patterns)
    # Convert patch to float32
    for i, patch in enumerate(patches):
        if patch.dtype == np.uint8:
            patches[i] = patch.astype(np.float32) / 255
    # Chroma blur
    for i, patch in enumerate(patches):
        patches[i] = chroma_blur(patch)
    # Transform to CHW format and normalize
    for i, patch in enumerate(patches):
        patch = np.transpose(patch, axes=(2, 0, 1))
        means = np.array([0.406, 0.456, 0.485]).reshape((3,1,1))
        stdevs = np.array([0.225, 0.224, 0.229]).reshape((3,1,1))
        patch -= means
        patch /= stdevs
        patches[i] = patch
    # Random aperture
    for i, patch in enumerate(patches):
        if i == 0:
            continue
        size = random.randint(64, 96)
        y = random.randint(0, 96-size)
        x = random.randint(0, 96-size)
        new_patch = np.zeros((3, 96, 96), dtype=np.float32)
        new_patch[:, y:y+size, x:x+size] = patch[:, y:y+size, x:x+size]
        patches[i] = new_patch
    # Construct one-hot label vector
    label_vec = np.zeros(num_labels(num_patches), dtype=np.float32)
    label_vec[label] = 1
    # Return flattened data tensors
    flat_data = []
    for patch in patches:
        flat_data.append(patch.reshape(-1))
    flat_data.append(label_vec)
    return np.concatenate(flat_data)