【发布时间】:2014-07-05 18:05:12
【问题描述】:
我有兴趣将单个高斯形状的对象添加到现有图像中,类似于附加图像中的内容。我想将对象添加到的基本图像是 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)
【问题讨论】:
标签: image matlab image-processing