<jupyter_start><jupyter_text>Libraries and function to show imagesImport the libaries<jupyter_code>import numpy as np
import cv2
from matplotlib import pyplot as plt<jupyter_output><empty_output><jupyter_text>The function to show image for the demo<jupyter_code># showing the demo images
def showImage(titles, images):
    fig=plt.figure()
    l = len(images)
    for i in range(l):
        fig.add_subplot(1, l, i+1)
        plt.imshow(images[i]/255.0, interpolation='nearest')
        plt.title(titles[i])
        plt.axis("off")<jupyter_output><empty_output><jupyter_text>Pick the random position and define patch SizeThe random positon **P** is picked with the following parameters:1. pValue = 322. Patch Size = 128<jupyter_code>pValue = 32
patchSize = 128
img = cv2.imread('example.jpg', flags=cv2.IMREAD_COLOR)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

title = ["The original image"]
image = [img]
showImage(title, image)

img = np.array(img, np.float32)
height, width, _ = img.shape
x = np.random.randint(low=pValue, high= width - pValue - patchSize)
y = np.random.randint(low=pValue, high= height - pValue - patchSize)
pos = np.array([x, y], dtype=np.int)<jupyter_output><empty_output><jupyter_text>Get the 4-point P and the perturbed 4-point perturbedP<jupyter_code>def randomCreatePatch(image, position):
        patchImage = image[position[1]: position[1] + patchSize, position[0]:position[0] + patchSize]
        H = np.random.randint(-pValue, pValue, size=(4, 2))
        p = np.array([
            position
            , [position[0] + patchSize, position[1]]
            , [position[0] + patchSize, position[1] + patchSize]
            , [position[0], position[1] + patchSize]
        ], dtype=np.float32)

        perturbedP = np.array(p + H, dtype=np.float32)
        H_AB = cv2.getPerspectiveTransform(p, perturbedP)
        H_BA = np.linalg.inv(H_AB)
        warpedImage = cv2.warpPerspective(image, H_BA, dsize=(image.shape[1], image.shape[0]))
        perturbedPatchImage = warpedImage[position[1]: position[1] + patchSize,
                              position[0]:position[0] + patchSize]
        return patchImage, perturbedPatchImage, H, H_AB, warpedImage, p, perturbedP
source, dst, H, H_AB, warpedImage, p, perturbedP = randomCreatePatch(img, pos)<jupyter_output><empty_output><jupyter_text>Show the results<jupyter_code>p = np.array([p], dtype=np.int32)
perturbedP = np.array([perturbedP], dtype=np.int32)
warpedImage = np.array(warpedImage, dtype=np.int32)
warpedImage = cv2.polylines(warpedImage, p, True, 255, 3, cv2.LINE_AA)

img = np.array(img, np.int32)
img0 = cv2.polylines(img.copy(), p , True, 255, 3, cv2.LINE_AA)
img1 = cv2.polylines(img.copy(), perturbedP , True, (100, 125, 255), 3, cv2.LINE_AA)


titles = ["The patch image", "The perturbed patch image"]
images = [img0, img1]
showImage(titles, images)

titles = ["The warped image"]
images = [warpedImage]
showImage(titles, images)

titles = ["The cropped-patch", "The perturbed cropped-patch"]
images = [source, dst]
showImage(titles, images)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1346153846153846, 'fraction_numerical': 0.028683181225554105, 'mean_word_length': 4.356020942408377, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '557918', 'license': 'MIT', 'n_tokens_mistral': 1137, 'n_tokens_neox': 1085, 'n_words': 247, 'path': 'Data_Generation_DEMO.ipynb', 'repo_name': 'humming-an/deepHomography_trail', 'size': '3068'}