32 votes
Accepted

Using Rasterio or GDAL to stack multiple bands without using subprocess commands

Using rasterio you could do import rasterio file_list = ['file1.tif', 'file2.tif', 'file3.tif'] # Read metadata of first file with rasterio.open(file_list[0]) as src0: meta = src0.meta # ...
Loïc Dutrieux's user avatar
16 votes

Using Rasterio or GDAL to stack multiple bands without using subprocess commands

If using GDAL 2.1+ it's as simple as gdal.BuildVRT then gdal.Translate: from osgeo import gdal outvrt = '/vsimem/stacked.vrt' #/vsimem is special in-memory virtual "directory" outtif = '/tmp/stacked....
user2856's user avatar
  • 65.4k
16 votes
Accepted

How to edit the metadata for individual bands of a multiband raster, preferably with GDAL?

You can use a simple python script that uses the Band.SetDescription method to set the band names: """ Set Band descriptions Usage: python set_band_desc.py /path/to/file.ext band desc [band desc.....
user2856's user avatar
  • 65.4k
15 votes
Accepted

Multiband to single band raster

You could use gdal_translate from the new workflow, which is under: Raster > Conversion > Rearrange bands... You won't be able to select the pencil as in the past, but you can select only the ...
Joseph's user avatar
  • 75.6k
10 votes

How to use gdal_calc.py for multi-band images?

To calculate a grey-scale from the same input file using different bands u can open the file multiple times and define the band which you want to use with --A_band=n. See my example for calculating ...
Gert's user avatar
  • 717
9 votes
Accepted

Extracting 5 bands geotiff file into RGB file using GDAL?

Your values aren't in 0,255 since they are UInt16. You can try rescaling to 0,255 (GDAL works it out by default from input min/max and output default 0,255): gdal_translate -b 1 -b 2 -b 3 -mask "...
mdsumner's user avatar
  • 8,186
9 votes
Accepted

Save multiband raster with gdal

i've found a way using a gdal object supported by numpy arrays.. import gdal import numpy as np from affine import Affine def save_multiband (output_name, dataset, raster_data, driver, ...
Italo Moletto Lobos's user avatar
9 votes
Accepted

How to visualize multiband imagery using rasterio?

The Rasterio Plotting documentation describes how to visualize multiband imagery. For example, using 4-band NAIP imagery: import rasterio from rasterio.plot import show src = rasterio.open("path/to/...
Aaron's user avatar
  • 51.6k
8 votes

Layer stacking rasters in QGIS?

Geoprocessing was moved to processing toolbar in QGIS 2.16, as you can see below:
ahmadhanb's user avatar
  • 40.7k
8 votes
Accepted

Converting 4-band TIF to PNG while keeping all 4 bands?

This is a limitation of the PNG format. It only has 3 information channels (RGB), so one of your bands will be suppressed. If you really need to, you can save your NIR band as an alpha channel, but ...
Roberto Ribeiro's user avatar
7 votes
Accepted

Displaying single band from multi-band raster using QGIS

This is a display issue: you want to display a continuous band using categories. You do not need to split your image to create a new new image: this can be done directly on the multiple band image, ...
radouxju's user avatar
  • 49.6k
6 votes
Accepted

Using multiband images in ArcGIS Raster Calculator?

You need to use each single band as an image to do raster calculator in ArcGIS. Raster calculator cannot give you access to the multiple bands composited into a one image. However, you can access each ...
ahmadhanb's user avatar
  • 40.7k
6 votes
Accepted

Viewing bands of landsat 8 images in QGIS for NDVI calculation?

You have downloaded the data and you can find it if you unpack the .tar.gz file using 7zip or similar software for unpacking files. The .tar.gz file is the fourth file from the top that can be seen in ...
Mikkel Lydholm Rasmussen's user avatar
6 votes
Accepted

Is it possible to read in specific bands from a multi-band raster with gdal or rasterio?

You can read specific bands in a single call using rasterio by passing a list/tuple of band numbers (Following the GDAL convention, bands are indexed from 1): import rasterio rasterio.__version__ '1....
user2856's user avatar
  • 65.4k
6 votes

Getting multiband raster's min and max values with Python in QGIS?

Next code works with multi band raster. It uses QgsRasterDataProvider objects to calculate statistic through QgsRasterBandStats objects. layer = iface.activeLayer() extent = layer.extent() provider ...
xunilk's user avatar
  • 29.8k
6 votes

Sum over Bands, Google Earth Engine

Here is another approach: // Make a (toy) 3 bands image var image = ee.Image([1,2,3]).rename(['one', 'two', 'three']) Map.addLayer(image, null, '3 bands image') // Sum all bands var sum_bands = ...
Rodrigo E. Principe's user avatar
5 votes
Accepted

NIR, R, G, B multiband (4 Band) GeoTIFF gdal_translate colorinterp issues

Using the creation option -co "ALPHA=NO" param in the gdal_translate command prevented the 4th band being set as alpha (its set as undefined now) which solved the issue. This solution was found here:...
beaorn's user avatar
  • 295
5 votes

Converting 4-band TIF to PNG while keeping all 4 bands?

I will just answer my own question here, if anyone runs into the same problem with multiband images and TensorFlow. I ended up using Keras on top of TensorFlow and instead of feeding the image files ...
Chrisnizz's user avatar
  • 410
5 votes
Accepted

Get colortable from three-band RGB raster (brick) with R

There's a function in rgdal for this SGDF2PCT, so here I coerce to SpatialGridDataFrame, build the colour table and rebuild the raster. Note that indexing in raster is assuming [0, 255]. Control ...
mdsumner's user avatar
  • 8,186
5 votes
Accepted

Identifying cells overlapping in multiple rasters using QGIS

If you want to SUM the cells of your raster data, then you can use Cell Statistics, and use Sum under Statistic. From the help: The Cell statistics algorithm computes a value for each cell of the ...
ahmadhanb's user avatar
  • 40.7k
5 votes
Accepted

Dropping one band in multi-band raster using ArcGIS Pro

One way is to use the Extract Band function. In your example: Use your 5 band raster as the input raster Select the 4 bands you want to retain by name or ID Specify the output raster for the ...
lambertj's user avatar
  • 3,037
4 votes
Accepted

Retrieve single band from multiband raster served by Geoserver

From the GeoServer user manual: <RasterSymbolizer> <Opacity>1.0</Opacity> <ChannelSelection> <GrayChannel> <SourceChannelName&...
Andrea Aime's user avatar
  • 17.3k
4 votes
Accepted

Convert a multiband raster to a polygon in qgis

I just figured it out... Use Raster Calculator: band@1 * 0 + band@2 * 0 + band@3 * 0 Then will get a raster of two values, then vectorizing this raster will only take a second.
benchenggis's user avatar
  • 1,406
4 votes

Process of Radiometric Calibration

With more than one calibration target, you can estimate the relationship between your measurement and the albedo/reflectance with a linear regression. If you have only one calibration target, you ...
radouxju's user avatar
  • 49.6k
4 votes

Is it possible to read in specific bands from a multi-band raster with gdal or rasterio?

This appears to work with rasterio import rasterio import numpy as np vstack = '/path/to/virtual_stack.vrt' bands = [2,4,6,14,35] # define cropping window ((row_start, row_stop), (col_start, ...
Loïc Dutrieux's user avatar
4 votes
Accepted

Open a mutliband raster, edit values in one of the bands, and overwrite the raster using Python/Rasterio?

You can write to selected bands using the indexes keyword. If you want your array to contain only zeros you can also create a new numpy array. This way you don't need to read any data at all. ...
Thomas's user avatar
  • 1,197
4 votes
Accepted

R Code for Hyperspectral Indices

You may consider using the R package hsdar as a starting point to carry out transformation of spectral response data as well calculation of vegetation indices. You will find additional information ...
dmci's user avatar
  • 4,872
4 votes
Accepted

Downloading only one band in Google Earth Engine without the RGB bands

If you do not want RGB visualization bands, then you should not call image.visualize({}). The visualize algorithm creates RGB bands. Simply replace image.visualize({}).addBands(image), which adds the ...
Kevin Reid's user avatar
  • 10.3k
4 votes

How to make a VRT with an input raster containing multi bands?

I couldn't find a better solution than the following, which uses intermediate vrts : 1) extract the one band raster vrt's that you need, e.g. gdalbuildvrt -b 2 input2b2.vrt input2.tif 2) build the ...
radouxju's user avatar
  • 49.6k

Only top scored, non community-wiki answers of a minimum length are eligible