TransWikia.com

Produce RGB image of satellite image mosaic or merge images with negative dimensions

Geographic Information Systems Asked by Kelsey on September 14, 2020

I am new to image processing with python and would like some help with a particular problem.

I am trying to create a mosaic of raster satellite images using the code extracted from this link https://automating-gis-processes.github.io/CSC18/lessons/L6/raster-mosaic.html, the code works fine when I merge images with a uint16 data type however when I convert the images to uint8 and try to merge them the following error appears:

    src_files_to_mosaic = []
    for fp in Im_fps:
      src = rasterio.open(fp)
      src_files_to_mosaic.append(src) 
      src_files_to_mosaic

   In [8]:

   mosaic, results = merge(src_files_to_mosaic)
   results
   ---------------------------------------------------------------------------
   ValueError                                Traceback (most recent call last)
   <ipython-input-8-b81f0f4272f5> in <module>
   ----> 1 mosaic, results = merge(src_files_to_mosaic)
   2 results

   C:ProgramDataAnaconda3libsite-packagesrasteriomerge.py in merge(datasets, bounds, res, 
   nodata, dtype, precision, indexes, output_count, method)
   158 
   159     # create destination array
   --> 160     dest = np.zeros((output_count, output_height, output_width), dtype=dt)
   161 
   162     if nodata is not None:
   ValueError: negative dimensions are not allowed

In order to convert the uint16 images to uint8 I am using the following code which produces the image displayed below:

  image = [band2.read(1), band3.read(1), band4.read(1)]

  image = np.array(image)

  image.shape

  Out[59]:
   (3, 10980, 10980)

   rgb=np.zeros((10980,10980,3))
   rgb[...,0] = band4.read(1)
   rgb[...,1] = band3.read(1)
   rgb[...,2] = band2.read(1)

   rgb2 = np.clip(np.array((rgb - np.min(rgb))/(np.max(rgb) - np.min(rgb))*255).astype(np.uint8)*4, 
   0, 
   255)
   #Reverse Red-Blue Channels as open cv will reverse again upon writing image on disk
   cv2.imwrite('C:/Users/student/Documents/Output/Sardinia - 
   1.08.2020/Sardinia24.jpg',rgb2[...,::-1])

  

enter image description here

Is there a possibility to try and apply the above code to the image mosaic, since when I tried to extract the bands of the image mosaic and convert the data type I obtained the following result instead since the values of the bands were arrays of zero and if I try to merge the converted images I get the error mentioned above that negative dimensions are not allowed:
enter image description here

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP