matlab绘制遥感影像tiff将经纬度后添加°N和°E标识并在图中每隔一°绘制网格线颜色为白色
以下是使用MATLAB绘制遥感影像的代码,其中添加了经纬度标识和网格线:
% 读取遥感影像
image = imread('path_to_image.tif');
% 绘制影像
figure;
imshow(image);
hold on;
% 获取影像的尺寸
[height, width, ~] = size(image);
% 设置经纬度范围
lat_range = [min_latitude, max_latitude];
lon_range = [min_longitude, max_longitude];
% 绘制网格线
step = 1; % 设置网格线的间隔
for lat = min_latitude:step:max_latitude
% 绘制纵向网格线
x = linspace(1, width, height);
y = ones(1, height) * round(lat_to_pixel(lat, lat_range, height));
plot(x, y, 'Color', 'w');
end
for lon = min_longitude:step:max_longitude
% 绘制横向网格线
x = ones(1, width) * round(lon_to_pixel(lon, lon_range, width));
y = linspace(1, height, width);
plot(x, y, 'Color', 'w');
end
% 添加经纬度标识
text_padding = 10; % 设置经纬度标识与图像边界的间距
text_size = 10; % 设置经纬度标识的字体大小
text_color = 'w'; % 设置经纬度标识的颜色
% 添加纬度标识
for lat = min_latitude:step:max_latitude
x = width - text_padding;
y = round(lat_to_pixel(lat, lat_range, height));
text(x, y, [num2str(lat) '°N'], 'HorizontalAlignment', 'right', 'VerticalAlignment', 'middle', 'Color', text_color, 'FontSize', text_size);
end
% 添加经度标识
for lon = min_longitude:step:max_longitude
x = round(lon_to_pixel(lon, lon_range, width));
y = text_padding;
text(x, y, [num2str(lon) '°E'], 'HorizontalAlignment', 'center', 'VerticalAlignment', 'bottom', 'Color', text_color, 'FontSize', text_size);
end
function pixel = lat_to_pixel(latitude, lat_range, height)
% 将纬度转换为像素坐标
lat_min = lat_range(1);
lat_max = lat_range(2);
pixel = (latitude - lat_min) / (lat_max - lat_min) * (height - 1) + 1;
end
function pixel = lon_to_pixel(longitude, lon_range, width)
% 将经度转换为像素坐标
lon_min = lon_range(1);
lon_max = lon_range(2);
pixel = (longitude - lon_min) / (lon_max - lon_min) * (width - 1) + 1;
end
请注意,您需要将'path_to_image.tif'替换为实际的遥感影像文件路径,并根据需要调整经纬度范围和网格线间隔
原文地址: https://www.cveoy.top/t/topic/hZbb 著作权归作者所有。请勿转载和采集!