||
数字图像分析是指利用计算机对数字图像进行处理。数字图像分析的领域很广泛,但从根本上讲,它侧重于使用算法修改图像中的像素值,以提取信息或增强后期处理。本实验包括对比度处理、平滑和边缘提取等。
目标:
• Grey-level thresholding 灰度分割
• Level slicing 水平切片
• Image convolution using boxcar kernel 图像卷积
• Edge detection 边缘检测
• Pan sharpening 全色锐化
• Texture analysis 纹理分析
1 选择影像
//Create a variable to look at the Landsat 8 Top-of-atmosphere image collection
var l8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA');
//Filter the image collection spatially to select images that include the point created
var spatialFiltered = l8.filterBounds(geometry);
//Narrow the data range of interest.
var temporalFiltered = spatialFiltered.filterDate('2017-01-01', '2018-12-31');
// This may still lead to a large number of scenes so sort from least to most cloudy.
var sorted = temporalFiltered.sort('CLOUD_COVER');
// And then select the first (i.e. least cloudy) image.
var bestscene = ee.Image(sorted.first());
/*If you print the selected scene to the console you can see the image details
including the id, which can be used to directly select that image in the future */
print('Best scene', bestscene);
//Center map display on the point created with a zoom level of 12
Map.centerObject(geometry,12);
//Display image as color infrared composite.
Map.addLayer(bestscene, {bands: ['B5', 'B4', 'B3'], max: 0.5}, 'input image');
2 进行图像增强
图像增强的主要目的是通过增加场景中特征之间的区别来提高图像的可解释性。图像增强通常是在图像预处理后进行的。图像增强技术主要包括对比度处理、空间特征处理和多图像处理。
Grey-level thresholding 灰度分割
Grey-level thresholding 被用于分割图像,在下面的示例中,根据在一个图像波段中定义的阈值从图像中分离去除水像素。
//Import a top-of-atmosphere reflectance Landsat 5 image.
var image = ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_015030_20100531');
//Center map display on Syracuse with a zoom level of 12
Map.setCenter(-76.1467, 43.0458,12);
//Display image as color infrared composite.
Map.addLayer(image, {bands: ['B4', 'B3', 'B2'], max: 0.5}, 'input image');
//Define a study area that captures Onondaga Lake and the surrounding area
var studyarea = ee.Geometry.Rectangle(-76.454, 43.692,-76.40, 42.82);
//Select out the NIR band from the input image
var NIRband = image.select('B4');
//Create a histogram of the spectral response in the NIR band using the geometry identified
var histogram2 = ui.Chart.image.histogram(NIRband, studyarea);
// Display the histogram.
print(histogram2);
//Create a binary mask to filter out water based on the reflectance information
var watermask = NIRband.gte(0.07);
//Use the water mask to create an image with water pixels removed.
var nowaterimage= image.updateMask(watermask);
//Display the output water-masked image using a CIR composite
Map.addLayer(nowaterimage, {bands: ['B4', 'B3', 'B2'], max: 0.5}, 'water-masked');
近红外波段直方图
Level Slicing 水平切片
水平切片是一种增强技术,将沿图像直方图x轴分布的DNs或反射值划分为一系列的间隔(即切片)。这项技术是通过为每个数据间隔分配不同的颜色来实现的。
//Load and display a top-of-atmosphere reflectance Landsat 5 image
var image = ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_015030_20100531');
//Center map display on Syracuse with a zoom level of 12
Map.setCenter(-76.1467, 43.0458,12);
//Display image as color infrared composite.
Map.addLayer(image, {bands: ['B4', 'B3', 'B2'], max: 0.5}, 'input image');
//Create an NDWI image using band 4 (NIR) and 5 (mid-IR) from the selected Landsat 5 image,
var ndwi = image.normalizedDifference(['B4', 'B5']); //create a NDWI image
/*Create an image visualization parameter to recolor the NDWI image based on pixels values:
NDWI =< 0, display as white (FFFFFF color)
NDWI > 0 & < 0.5, display in cyan (00FFFF color)
NDWI >=0.5 & =< 1, display as blue (0000FF color)
Higher NDWI suggest higher water content, the three slices are represented with different colors
that show no water content, low water content and high water content pixels.*/
var ndwislices = ndwi.expression(
"(b('nd') < 0) ? 3" + //nd refer to the values of each pixel in the NDWI image
": (b('nd') < 0.5) ? 2" +
": (b('nd') < 1) ? 1" +
": 0"
);
//Display final image based on level sliced image.
Map.addLayer(ndwislices,
{min: 0, max: 3, palette: ["0000FF","00FFFF","FFFFFF"]},
'NDWI Slices');
Image Convolution 图像卷积
图像卷积,也称为邻域滤波,利用给定像素附近的像素值来确定其最终输出值。除了执行局部色调调整,卷积还可以用于过滤图像,以平滑、锐化细节、突出边缘或去除噪声(Szeliski 2011)。本文使用低通滤波器平滑图像。低通滤波器的设计目的是强调图像的低光谱频率特征(亮度的大范围变化)和减少高频成分(局部细节)的表现。
//Load and display a top-of-atmosphere reflectance Landsat 5 image
var image = ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_015030_20100531');
//Center map display on Syracuse with a zoom level of 12
Map.setCenter(-76.1467, 43.0458,12);
//Display image as color infrared composite.
Map.addLayer(image, {bands: ['B4', 'B3', 'B2'], max: 0.5}, 'input image');
/*Define a low-pass kernel. This kernel creates a 7x7 square, the normalize parameter means the
sum of values in the kernel will be 1 */
var lowpass = ee.Kernel.square({radius: 7, units: 'pixels', normalize: true});
//Smooth the image by convolving with the low-pass kernel.
var smooth = image.convolve(lowpass);
Map.addLayer(smooth, {bands: ['B4', 'B3', 'B2'], max: 0.5}, 'smoothed');
Edge Detection/Enhancement 边缘检测/增强
边缘检测或增强试图同时保留局部对比度和低频亮度信息。Canny边缘检测算法(Canny 1986)使用四个单独的过滤器来识别对角线、垂直和水平边缘。计算提取水平方向和垂直方向的一阶导数值,计算梯度大小。较小幅度的梯度被抑制。对于从一个边缘检测器提取线,GEE嵌入了霍夫变换(Duda和Hart 1972)。
/*Load a Landsat 8 image and select only the panchromatic band. The panchromatic band
includes reflectance in the 0.503–0.676 μm wavelength range with a ground sample distance of
15 m. */
var image = ee.Image('LANDSAT/LC08/C01/T1/LC08_015030_20140307').select("B8");
//Center map display on Syracuse with a zoom level of 12
Map.setCenter(-76.1467, 43.0458,12);
//Display image as color infrared composite.
Map.addLayer(image, '', 'input image');
/* Perform Canny edge detection and display the result. This function uses the threshold parameter
to determine the minimum gradient magnitude; the sigma parameter is the standard deviation (SD)
of a Gaussian pre-filter to remove high-frequency noise. A sigma of 0 means apply no filtering.*/
var canny = ee.Algorithms.CannyEdgeDetector({
image: image, threshold: 200, sigma: 1 });
//Display the outcome of the canny edge detection.
Map.addLayer(canny, {}, 'canny');
/* Perform a Hough transform of the Canny result. In this function gridSize means size of grid for
analysis (default is 256), inputThreshold is the value threshold for the input image (pixels at or
above this value are considered active) and lineThreshold is the threshold for line detection
(values at or above this threshold on the Hough transform are considered detected lines). Each of
these parameters can be determined experimentally. The defaults provided in GEE for the
parameters are intended as a starting point for use with unsigned 8-bit integers.*/
var hough = ee.Algorithms.HoughTransform(canny, 256, 7000, 80);
//Display the outcome of the Hough transformed canny edge detection.
Map.addLayer(hough, {}, 'hough');
Pan Sharpening using HSV space 全色锐化
全色锐化技术用于合并全色(高空间、低光谱分辨率)和多光谱(低空间、高光谱分辨率)图像。全色锐化的一种方法是通过RGB和强度-色调-饱和度(IHS)或色调-饱和度-值(HSV)空间之间的转换。
// Import a Landsat 8 top-of-atmosphere reflectance image
var image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_015030_20140307');
//Display image as normal color composite.
Map.addLayer(image,{bands: ['B4', 'B3', 'B2']}, 'RGB image');
// Convert the visible bands from the input image to HSV color space.
var hsv = image.select(['B4', 'B3', 'B2']).rgbToHsv();
/* Create a new image by concatenating the hue and saturation bands (HSV image) with the panchr
omatic band from the original image and converting back to RGB. */
//Concatenate bands
var combined = ee.Image.cat([hsv.select('hue'), hsv.select('saturation'), image.select('B8')]);
//Convert back to RGB space
var sharpened = ee.Image(combined).hsvToRgb();
//Set the map display to center at City of Syracuse and a zoom level of 14
Map.setCenter(-76.14, 43.04,14);
// Display the pan-sharpened result.
Map.addLayer(sharpened,'','pan-sharpened');
锐化前
锐化后
Performing visual interpretation through texture analysis 目视解译和纹理分析
纹理是指图像上色调变化的频率。它是由可能太小而无法在图像内单独识别的单元特征聚合而产生的。一个例子是绿色草地的光滑纹理与航空照片上的绿色树冠的粗糙纹理。谷歌地球引擎有多种方法来计算纹理。其中之一是熵,它提供了一个空间无序度的度量。
//Import a high-resolution NAIP image.
var image = ee.Image('USDA/NAIP/DOQQ/m_4307663_se_18_1_20130619');
//Zoom map to Oakwood Cemetary at level 16 and display input image.
Map.setCenter(-76.13, 43.03,16);
//The catch with entropy is that it needs discrete values, hence the image is rescaled.
Map.addLayer(image, {max: 255}, 'Input image');
//Select NIR band from input image.
var nir = image.select('N');
//Define size and shape of neighborhood for deriving the texture information.
var square = ee.Kernel.square({radius: 3});
//Compute entropy (texture) using the defined neighborhood information.
var entropy = nir.entropy(square);
//Display computed image texture outcome.
Map.addLayer(entropy,{min: 1, max: 5, palette: ['0000CC', 'CC0000']}, 'entropy');
【参考】
https://zhuanlan.zhihu.com/p/149409447?from_voters_page=true
Lab 3 – Image processing techniques using Google Earth Engine.pdf
点滴分享,福泽你我!Add oil!
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-11-30 13:51
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社