简体   繁体   中英

splitting image and merging

I have a polygon points like below:


geometry = [
    [
      [
        38.752152,
        37.208675
      ],
      [
        39.224913,
        37.208675
      ],
      [
        39.224913,
        36.686262
      ],
      [
        38.752152,
        36.686262
      ],
      [
        38.752152,
        37.208675
      ]
    ]
  ]

I take an image by this coordinates and assume its size is 5000x5000. I want to split it into four images that their sizes are 2500x2500 and merge them. To do that, I split the geometry into some pieces by sampling it until reach maximum value of the coordinates.

step_x = round(size[0]/2500+1)
step_y = round(size[1]/2500+1)
points_x = numpy.linspace(x_min,x_max,step_x)
points_y = numpy.linspace(y_min,y_max,step_y)
combinedImage = numpy.zeros((step_x*2500,step_y*2500,3)) #To merge the images

Then I get images from an api

size_x = len(points_x)
size_y = len(points_y)




for y in range(size_y-1):
    for x in range(size_x-2,-1,-1):
        tmpGeometry = [[[points_x[x],points_y[y]],[points_x[x+1],points_y[y]],[points_x[x],points_y[y+1]],[points_x[x+1],points_y[y+1]]]]
        x_min, y_min = numpy.min(tmpGeometry, axis = 1)[0]#like left top coordinates.
        x_max, y_max = numpy.max(tmpGeometry, axis = 1)[0]#like right bottom coordinates.
        sentinelhub.setBBox(x_min,y_min,x_max,y_max)
        image = sentinelhub.sendRequest()# I got image at here
        combinedImage[2500*y:2500*(y+1),2500*x:2500*(x+1)] = image# I try to merge the images
      
        print((x,y),(x,y+1),(x+1,y),(x+1,y+1))
        


After everything is done, I get image but it is little bit mixed, look at red lines. It is like two part, top and bottom part and their place are wrong. On the top one should be bottom and on the bottom should be top.

在此处输入图像描述

My problem was solved when I change my code with that:

for y in range(size_y-1):
    images = []
    rows = []
    for x in range(size_x-1):
        tmpGeometry = [[[points_x[x],points_y[y]],[points_x[x],points_y[y+1]],[points_x[x+1],points_y[y]],[points_x[x+1],points_y[y+1]]]]
        x_min, y_min = numpy.min(tmpGeometry, axis = 1)[0]
        x_max, y_max = numpy.max(tmpGeometry, axis = 1)[0]
        sentinelhub.setBBox(x_min,y_min,x_max,y_max)
        image = sentinelhub.getCombinedImage()
        rows.append(image)

        
    
        print((x,y),(x,y+1),(x+1,y),(x+1,y+1))
    rows = numpy.concatenate(rows, axis = 1)
    images.append(rows)


images = images[::-1]
images = numpy.concatenate(images,axis =0)
cv2.imwrite("concatenate.jpg",images)


The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM