Pan sharpening an image
To pan sharpen an image, follow these steps:
- Create Raster objects from both multispectral and panchromatic raster datasets.
- Create a Raster object that contains only the near-infrared band (the fourth band used by the pan sharpening filter).
- Set the pan sharpened raster's properties.
- Create a pan sharpening filter and set its parameters.
- Set the filter to the multispectral raster (cast).
- Save as a pan sharpened image.
public static void PanSharpening(IRasterDataset panDataset, IRasterDataset
multiDataset)
{
//panDataset—A raster dataset created from a single-band, higher-resolution image.
//multiDataset—A raster dataset created from a multiband image.
//Assuming four bands: R,G,B, and NIR.
//Create raster objects from pan/multi raster datasets.
IRaster panRaster = ((IRasterDataset2)panDataset).CreateFullRaster();
IRaster multiRaster = ((IRasterDataset2)multiDataset).CreateFullRaster();
//Set infrared image.
IRasterBandCollection rasterbandCol = (IRasterBandCollection)multiRaster;
IRasterBandCollection infredRaster = new RasterClass();
infredRaster.AppendBand(rasterbandCol.Item(3));
//Set the pan sharpened raster's properties.
IRasterProps panSharpenRasterProps = (IRasterProps)multiRaster;
IRasterProps panRasterProps = (IRasterProps)panRaster;
panSharpenRasterProps.Width = panRasterProps.Width;
panSharpenRasterProps.Height = panRasterProps.Height;
panSharpenRasterProps.Extent = panRasterProps.Extent;
multiRaster.ResampleMethod = rstResamplingTypes.RSP_BilinearInterpolation;
//Create the pan sharpening filter and set its parameters.
IPansharpeningFilter pansharpenFilter = new PansharpeningFilterClass();
pansharpenFilter.InfraredImage = (IRaster)infredRaster;
pansharpenFilter.PanImage = (IRaster)panRaster;
pansharpenFilter.PansharpeningType = esriPansharpeningType.esriPansharpeningESRI;
pansharpenFilter.PutWeights(0.166, 0.167, 0.167, 0.5);
//Set the pan sharpen filter to multispectral raster.
IPixelOperation pixelOperation = (IPixelOperation)multiRaster;
pixelOperation.PixelFilter = (IPixelFilter)pansharpenFilter;
//Save the pan sharpened image.
ISaveAs saveas = (ISaveAs)pixelOperation;
saveas.SaveAs(@"c:\temp\pansharpentest.tif", null, "TIFF");
}
[VB.NET]
Public Shared Sub PanSharpening(panDataset As IRasterDataset, multiDataset As IRasterDataset)
'panDataset—A raster dataset created from a single-band, higher-resolution image.
'multiDataset—A raster dataset created from a multiband image.
'Assuming four bands: R,G,B, and NIR.
'Create raster objects from pan/multi raster datasets.
Dim panRaster As IRaster = CType(panDataset, IRasterDataset2).CreateFullRaster()
Dim multiRaster As IRaster = CType(multiDataset, IRasterDataset2).CreateFullRaster()
'Set infrared image.
Dim rasterbandCol As IRasterBandCollection = CType(multiRaster, IRasterBandCollection)
Dim infredRaster As IRasterBandCollection = New RasterClass()
infredRaster.AppendBand(rasterbandCol.Item(3))
'Set the pan sharpening raster's properties.
Dim panSharpenRasterProps As IRasterProps = CType(multiRaster, IRasterProps)
Dim panRasterProps As IRasterProps = CType(panRaster, IRasterProps)
panSharpenRasterProps.Width = panRasterProps.Width
panSharpenRasterProps.Height = panRasterProps.Height
panSharpenRasterProps.Extent = panRasterProps.Extent
multiRaster.ResampleMethod = rstResamplingTypes.RSP_BilinearInterpolation
'Create the pan sharpening filter and set its parameters.
Dim pansharpenFilter As IPansharpeningFilter = New PansharpeningFilterClass()
pansharpenFilter.InfraredImage = CType(infredRaster, IRaster)
pansharpenFilter.PanImage = CType(panRaster, IRaster)
pansharpenFilter.PansharpeningType = esriPansharpeningType.esriPansharpeningESRI
pansharpenFilter.PutWeights(0.166, 0.167, 0.167, 0.5)
'Set the pan sharpen filter to multispectral raster.
Dim pixelOperation As IPixelOperation = CType(multiRaster, IPixelOperation)
pixelOperation.PixelFilter = CType(pansharpenFilter, IPixelFilter)
'Save the pan sharpened image.
Dim saveas As ISaveAs = CType(pixelOperation, ISaveAs)
saveas.SaveAs("c:\temp\pansharpentest.tif", Nothing, "TIFF")
End Sub
To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
ESRI.ArcGIS.System (ESRI.ArcGIS.esriSystem)ESRI.ArcGIS.Display ESRI.ArcGIS.Geometry ESRI.ArcGIS.Geodatabase ESRI.ArcGIS.DataSourcesRaster
Development licensing | Deployment licensing |
---|---|
ArcGIS for Desktop Advanced | ArcGIS for Desktop Advanced |
ArcGIS for Desktop Standard | ArcGIS for Desktop Standard |
ArcGIS for Desktop Basic | ArcGIS for Desktop Basic |
Engine Developer Kit | Engine |