I have two different matrices A (shape 5, 11) and B (shape 5, 2). I want to have a projected view of each of these matrices. Unfortunately, the horizontal lines that are separating different values, end up on different heights (~80px vs ~150px). Can somebody provide some insight why that is / how to fix it?
I am using numpy, matplotlib and opencv and define a desired output width and height.
import numpy as np
import cv2
import matplotlib.pyplot as plt
output_width, output_height = 1000, 600
This generates the image for matrix A.
values = 1 + np.random.rand(5, 11).astype("float32")
source_points = np.array(
[
[-0.5, -0.5], [10.5, -0.5], [-0.5, 4.5], [10.5, 4.5],
], dtype="float32"
)
target_points = np.array(
[
[1, 0], [1000, 0], [250, 250], [750, 250],
], dtype="float32"
)
transformation = cv2.getPerspectiveTransform(source_points, target_points)
warped_values = cv2.warpPerspective(
values,
transformation,
(output_width, output_height),
borderMode=cv2.BORDER_TRANSPARENT,
flags=cv2.INTER_NEAREST
)
plt.imshow(warped_values)
This generates the iamge for matrix B.
values = 1 + np.random.rand(5, 2).astype("float32")
source_points = np.array(
[
[-0.5, -0.5], [1.5, -0.5], [-0.5, 4.5], [1.5, 4.5],
], dtype="float32"
)
target_points = np.array(
[
[201, 0], [800, 0], [450, 250], [550, 250],
], dtype="float32"
)
transformation = cv2.getPerspectiveTransform(source_points, target_points)
warped_values = cv2.warpPerspective(
values,
transformation,
(output_width, output_height),
flags=cv2.INTER_NEAREST,
borderMode=cv2.BORDER_TRANSPARENT
)
plt.imshow(warped_values)

