我有興趣在現有圖像中添加單個高斯形狀對象,如附加圖像中的內容。我想添加對象的基本圖像是8位無符號值,範圍從0-255。附圖中的明亮對象實際上是一個由歸一化植被指數(NDVI)數據表示的樹。所附的腳本是我迄今爲止所擁有的。如何將一個高斯形狀的對象(即一棵樹)的值從110-155加到現有的NDVI圖像上?如何在圖像中添加高斯形狀的物體?
Sample data available here可與該腳本可以用來計算NDVI
file = 'F:\path\to\fourband\image.tif';
[I R] = geotiffread(file);
outputdir = 'F:\path\to\output\directory\'
%% Make NDVI calculations
NIR = im2single(I(:,:,4));
red = im2single(I(:,:,1));
ndvi = (NIR - red) ./ (NIR + red);
ndvi = double(ndvi);
%% Stretch NDVI to 0-255 and convert to 8-bit unsigned integer
ndvi = floor((ndvi + 1) * 128); % [-1 1] -> [0 256]
ndvi(ndvi < 0) = 0; % not really necessary, just in case & for symmetry
ndvi(ndvi > 255) = 255; % in case the original value was exactly 1
ndvi = uint8(ndvi); % change data type from double to uint8
%% Need to add a random tree in the image here
%% Write to geotiff
tiffdata = geotiffinfo(file);
outfilename = [outputdir 'ndvi_' '.tif'];
geotiffwrite(outfilename, ndvi, R, 'GeoKeyDirectoryTag', tiffdata.GeoTIFFTags.GeoKeyDirectoryTag)
+1不錯的答案。下面是一些構建高斯濾波器的更多方法:http://stackoverflow.com/a/1835663/97160(注意它是一個[可分離濾波器](http://blogs.mathworks.com/steve/2006/10)/04/separable-convolution /),所以我們可以從1D中獲得2D濾鏡) – Amro