I have some data. I visualize and then save it as image.
import cv2
import numpy as np
import matplotlib.pyplot as plt
data = np.array([
[1,2,0,1],
[0,1,2,1],
[0,0,2,1]])
fig, ax = plt.subplots()
ax.imshow(data)
ax.axis('off')
fig.savefig("test.png", bbox_inches='tight', pad_inches=0)
Next, I load the image and read the shape:
img = cv2.imread('test.png')
print(img.shape)
Output:
(217, 289, 3)
But I want to keep the original resolution and my expected output:
(3, 4, 3)
Any solution?
Upd.:
With dpi=1:
data = np.array([
[1,2,0,1],
[0,1,2,1],
[0,0,2,1],
[1,0,2,1],
[4,1,0,2],
])
fig, ax = plt.subplots()
ax.imshow(data)
ax.axis('off')
fig.savefig("test.png", bbox_inches='tight', pad_inches=0, dpi = 1)
img = cv2.imread('test.png')
img.shape
print(data.shape, img.shape)
Output:
(5, 4)
(3, 2, 3)