I have this circuit obtained using MatplotLib:

Now I want to use it as a regular Python image (PIL or array), because I want to apply it to a mask (obtained using OpenCV).
The problem is that with MatplotLib the image with the outline changes and an edge is added (for the axis, even if I don’t draw the axis), so the image that I get from the MatplotLib figure does not match the mask obtained with OpenCV.
I tried to get the same outline with OpenCV, but I don't get any result with the functions cv2.FindContours and cv2.DrawContours (if you know how to do this, please tell me ... in this previous topic you can see the original image and the outline that I want)
Another possible solution would be to convert the outline obtained with MatplotLib into an image (PIL or array) with the same size as the original and without borders.
I hope you could help me with at least one of these solutions!
--------------------------- EDIT ------------------- --- -----
Answer Rutger Kassies is right. This did not work for me because I wrote this line ...
ax = plt.axes([0, 0, 1, 1], frame_on=False, xticks=[], yticks=[])
... after using the contour function, and it should be before using the contour function. Remember this!
Xithias
source share