Skip to content

首谷阴影检测

原文链接: https://www.nv5geospatialsoftware.com/Learn/Blogs/Blog-Details/first-valley-shadow-detection

8143 评价本文:

5.0

首谷阴影检测

匿名 2017年2月9日,星期四

当阴影被引入分析流程时,处理起来可能颇具挑战。尽管存在多种处理阴影的方法,但我发现最简便的方式之一就是直接将其掩蔽。我主要处理农业数据,尤其是行播作物数据。在此类数据中,阴影投射在行间的裸露土地上,因此如果您的目标物是植被本身,就可以相对轻松地将其掩蔽。根据所用影像类型,阴影通常是影像中最暗的表面之一(如果不是最暗的话)。这一假设可被我们利用——在影像的直方图中,阴影应位于较低端。

例如,在这幅柑橘园影像中,阴影是最暗的特征,因此位于直方图的底部。

图1:柑橘园近红外影像

图2:图1的直方图

通过观察影像,您可以看到两个主要特征之间存在一个明显的低谷。使用近红外首谷方法(Jan-Chang, Yi-Ta, Chaur-Tzuhn, & Shou-Tsung, 2016),您可以分离出局部最小值,然后将其用作阴影掩蔽阈值的上限。局部最小值可以轻松地通过支持文档《使用IDL查找2D图的多个局部最大值/最小值》中介绍的方法获得。

图3:以红色显示的阴影

图4:识别出的首谷


function local_max_finder, datax, datay, minima = minima compile_opt idl2 ;initialize list max_points = list() data_x = datax data_y = datay

 ;check for keyword, flip the sign of the y values if keyword_set(minima) then data_y = -datay ;iterate through elements for i=1, n_elements(data_y)-2 do begin

 ;previous point less than i-th point and next point less than i-th point if ( (data_y[i-1] le data_y[i]) AND (data_y[i] ge data_y[i+1])) then max_ points.add, i endfor ;return an array of the indices where the extrema occur return, max_points.toarray() end

pro ShadowFinder compile_opt IDL2 ; Select your image e = envi(/current) oRaster = e.UI.SelectInputData(/Raster, bands = bands) ; Check for single band if N_ELEMENTS(bands) gt 1 then begin MESSAGE, 'Input raster may only contain 1 band', /INFORMATIONAL return endif ; Pull the data out of the image data = oRaster.GetData(bands = bands, pixel_state = pixel_state) ; Convert data to float data = float(bytscl(data)) ; Mask all values in the image bkgrd_pos = where(pixel_state ne 0) data[bkgrd_pos] = !VALUES.F_NAN ; find all local minima based off the histogram of the image h = histogram(data, LOCATIONS=xbin) ; Remove zero values non_zeros = where(h ne 0) h = h[non_zeros] xbin = xbin[non_zeros] ; Get the number of points n_pts = n_elements(h) ; Smooth data (7 pixel moving average) boxcar = 7 p1 = (boxcar - 1) / 2 p2 = boxcar - p1 for i = 0 , n_pts-1 do begin pos = [i-p1:i+p1] pos = pos[where((pos ge 0) and (pos le n_pts-1))] h[i] = mean(h[pos]) endfor MINIMA = local_max_finder(xbin, h, /MINIMA) x_extrema = xbin[MINIMA] y_extrema = h[MINIMA] ; Plot all local minima p = plot(xbin, h) p3 = scatterplot(x_extrema, y_extrema, /current, /overplot, $ symbol = 'o', sym_color = 'b', sym_thick = 2) ; Create a shadow mask mask = bytarr(oRaster.ns, oRaster.nl) mask[where(data le x_extrema[0])] = 1 ; create a new metadata object metadata = ENVIRasterMetadata() metadata.AddItem, 'classes', 2 metadata.AddItem, 'class names', ['Background', 'Shadow'] metadata.AddItem, 'class lookup', [[0,0,0],[255,0,0]] metadata.AddItem, 'data ignore value', 0 metadata.AddItem, 'band names', 'Shadows' ; Create a classification image oClass = e.CreateRaster(e.GetTemporaryFileName(), mask, SPATIALREF = oRaster.SPATIALREF, $ data_type = 1, metadata = metadata) oClass.save ; Add the new class image to envi e.data.add, oClass end

参考文献

Jan-Chang, C., Yi-Ta, H., Chaur-Tzuhn, C., & Shou-Tsung, W. (2016). Evaluation of Automatic Shadow Detection Approaches Using ADS-40 High Radiometric Resolution Aerial Images at High Mountainous Region. Journal of Remote Sensing & GIS.

IDL中正浮点数的Base 60编码 用于自动目标检测的机器学习训练