繁体   English   中英

分割图像和合并

[英]splitting image and merging

我有一个多边形点,如下所示:


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

我通过这个坐标拍摄图像并假设它的大小是 5000x5000。 我想把它分成四个尺寸为 2500x2500 的图像并将它们合并。 为此,我通过对其进行采样将几何图形分成几部分,直到达到坐标的最大值。

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

然后我从 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))
        


一切都完成后,我得到了图像,但它有点混杂,看看红线。 这就像两个部分,顶部和底部,它们的位置是错误的。 在顶部应该是底部,在底部应该是顶部。

在此处输入图像描述

当我改变我的代码时,我的问题得到了解决:

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)


暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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