0

I am using the following code to calculate the frequency or the MFCC coefficients of a wavelet signal. When I have calculated my signals (frequency over time) in 2D numpy arrays I am trying to store it locally into a .png images. I am trying to do so with two different possible ways. Firstly, by using:

matplotlib.image.imsave("my_img.png", filter_banks)

That leads to:

enter image description here

and the second way using librosa tool:

import librosa.display
from matplotlib import cm
fig = plt.figure(figsize=(..., ...), dpi=1)
librosa.display.specshow(filter_banks.T, cmap=cm.jet)
plt.tight_layout()
plt.savefig("_plot_static_conv.png")
plt.show()

and the result is look like:

enter image description here

My issue is that I am having some white margin over the image which are not desired. How can I have the same size also in the second case and avoid the white margin over the image that I guess is caused by the plt.figure?

EDIT: I tried to use the answer from the following post but it did not solve my issue.

Jose Ramon
  • 5,572
  • 25
  • 76
  • 152

1 Answers1

1

probably as a workaround, your white margin is 4 pixel, could you save your second image with 8 more pixel in height and width.

then crop it using c2v

import cv2
img = cv2.imread("image.png")
crop_img = img[y:y+h, x:x+w]
cv2.imshow("cropped", crop_img)
cv2.waitKey(0)

as proposed in: https://stackoverflow.com/a/15589825/4610938

PandaBlue
  • 331
  • 1
  • 6
  • I am not sure it is really good work around to store and crop the image. I guess there is a solution that i can save it already cropped. – Jose Ramon Oct 16 '18 at 12:32
  • I have found here: https://stackoverflow.com/a/9295367/4610938 an answer where the figure white padding is removed, hope it'll help – PandaBlue Oct 16 '18 at 14:17