Recently downloaded some remote sensing image data , These data contain a large number of peripheral background data , As shown in the figure below :
The peripheral background values are 0 value .
This article describes the use of python Batch process peripheral background , Keep only the smallest peripheral background area .
Here's the picture :
The basic idea is as follows :
Firstly, the coordinates of the four corners of the data area in the remote sensing image are obtained , The coordinates here are represented by row and column numbers , Upper left corner (x1,y1), Upper right corner (x2,y2), The lower left corner (x3,y3), The lower right corner (x4,y4). We need to get the row and column numbers of the four corners by traversing the remote sensing data .
then , Calculate the range of four ranges according to the quadrangular coordinates , namely left,top,right,bottom value .
Method 1 : after , Obtain the coordinates of the upper left corner and the lower right corner respectively :(left,top),(right,bottom). Last read (left,top),(right,bottom) Data in scope , Rewrite and save to a new image . There is a problem with the result of this calculation , The coordinate range of the image will change . Therefore, it is not advisable , It should be calculated as the latitude and longitude coordinate range , Then cut according to the longitude and latitude range .
Method 2: Calculate the boundary range with longitude and latitude as the unit according to the above coordinate values of four points