()There will be white edges on the top, bottom, left and right pictures saved to the local area
(datalistall[i]) ('off') # ().xaxis.set_major_locator(()) # ().yaxis.set_major_locator(()) (0, 0) ('Change the address you want to save yourself', bbox_inches='tight', dpi=300, pad_inches=0.0) ()
After testing, if only bbox_inches='tight' is just the image saved, the white edge will only narrow. Also add pad_inches=0.0.
The two sentences commented out in the middle have no effect.
() Must be written at the end, otherwise it will be saved as a blank space.
() The image removes the blank area next to it and uses CV2 to read and candy to identify it
When making a picture, you need to arrange the output pictures closely, remove the coordinate axes, and set the output picture size.
But I found that matplotlib saved images using()
There is a circle of blank space around it. So how to remove the blank?
First, turn off the axis display:
('off')
However, this just turns off the display, and the transparent coordinate axes will still occupy the lower left corner, causing the output image to be on the right. To completely remove the coordinate axis, you need to change it to the following code:
('off') fig = () fig.set_size_inches(7.0/3,7.0/3) #dpi = 300, output = 700*700 pixels ().xaxis.set_major_locator(()) ().yaxis.set_major_locator(()) plt.subplots_adjust(top = 1, bottom = 0, right = 1, left = 0, hspace = 0, wspace = 0) (0,0) (out_png_path, format='png', transparent=True, dpi=300, pad_inches = 0)
You can complete the removal of the blanks.
Note: If you do not use subplot_adjust + margin(0,0), but add bbox_inches = 'tight' to the parameter of(), you can also achieve
The effect of removing blanks; however, this will cause the setting of image output size to be invalid.
import h5py import as plt import numpy as np import cv2 # train_imgs = ("./datafuse/test_images.hdf5", 'r') img = train_imgs['input_DEM'][0][...] ('off') fig = () fig.set_size_inches(7.0/3,7.0/3) ().xaxis.set_major_locator(()) ().yaxis.set_major_locator(()) plt.subplots_adjust(top = 1, bottom = 0, right = 1, left = 0, hspace = 0, wspace = 0) (0,0) (img, cmap='gray') ('', pad_inches = 0) () img = ('', 0) # The original image is a color image, the second parameter can be changed to 0 and is a grayscale image# # (img, cmap='gray') # () edges = (img, 100, 200) (121), (img, cmap='gray') ('raw'), ([]), ([]) (122), (edges, cmap='gray') ('Canny detecetion'), ([]), ([]) ()
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.