Tiff遥感影像提取RBG波段

我的图像为5通道的tiff文件,RBG分别是第1,2,3波段,想要使用这三个波段作为底层影像观测输出结果,因此首先提取它们:

这里仅列举单个图像的

import tifffile
import numpy as np
from PIL import Image


# 读取多波段图像
image = tifffile.imread("E:/Nomal data/training_data_v3/compressed/images/17784962.tiff")

# 提取RGB三层
red_channel = image[:, :, 0]  # 假设第一个波段为红色通道
green_channel = image[:, :, 1]  # 假设第二个波段为绿色通道
blue_channel = image[:, :, 2]  # 假设第三个波段为蓝色通道

# 创建RGB图像
rgb_image = np.stack([red_channel, green_channel, blue_channel], axis=-1)

# 保存RGB图像
tifffile.imwrite("E:/picture/rgb.tif", rgb_image)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是基于GUI界面的MATLAB遥感图像配准软件的代码,包括人工选取控制点和自动选择控制点两种配准方式,并能生成配准后的遥感影像: ```matlab % 创建GUI界面 fig = uifigure('Name', '遥感图像配准软件'); % 创建菜单栏和文件菜单 menu = uimenu(fig, 'Text', '文件'); uimenu(menu, 'Text', '打开', 'MenuSelectedFcn', @openImage); uimenu(menu, 'Text', '保存', 'MenuSelectedFcn', @saveImage); % 创建选择配准方式的单选框 rbg = uibuttongroup(fig, 'Position', [0.05 0.7 0.9 0.2], 'Title', '选择配准方式'); uicontrol(rbg, 'Style', 'radiobutton', 'String', '人工选取控制点', 'Position', [10 50 200 30], 'HandleVisibility', 'off'); uicontrol(rbg, 'Style', 'radiobutton', 'String', '自动选择控制点', 'Position', [10 20 200 30], 'HandleVisibility', 'off'); % 创建图像显示区域 ax1 = uiaxes(fig, 'Position', [0.05 0.2 0.4 0.4]); ax2 = uiaxes(fig, 'Position', [0.55 0.2 0.4 0.4]); % 创建控制点设置区域 pnl = uipanel(fig, 'Title', '控制点设置', 'Position', [0.05 0.05 0.9 0.1]); uicontrol(pnl, 'Style', 'text', 'String', '控制点数量:', 'Position', [10 40 100 20]); uicontrol(pnl, 'Style', 'edit', 'String', '4', 'Position', [110 40 50 20], 'Callback', @setControlPoint); uicontrol(pnl, 'Style', 'text', 'String', '控制点位置:', 'Position', [10 10 100 20]); uicontrol(pnl, 'Style', 'pushbutton', 'String', '手动选择', 'Position', [110 10 100 20], 'Callback', @manualControlPoint); uicontrol(pnl, 'Style', 'pushbutton', 'String', '自动选择', 'Position', [220 10 100 20], 'Callback', @autoControlPoint); % 全局变量 global img1 img2 cp; cp = []; % 打开图像 function openImage(src, event) [file, path] = uigetfile({'*.jpg;*.png;*.tif', '图像文件 (*.jpg,*.png,*.tif)'}); if isequal(file, 0) || isequal(path, 0) return; end img = imread(fullfile(path, file)); global img1 img2 cp; if isempty(img1) img1 = img; else img2 = img; end imshow(img, 'Parent', ax1); end % 保存图像 function saveImage(src, event) [file, path] = uiputfile({'*.jpg;*.png;*.tif', '图像文件 (*.jpg,*.png,*.tif)'}); if isequal(file, 0) || isequal(path, 0) return; end global img2; imwrite(img2, fullfile(path, file)); end % 设置控制点数量 function setControlPoint(src, event) global cp; cp = []; n = str2double(src.String); if ~isnan(n) && n > 0 cp = zeros(n, 2); end end % 手动选择控制点 function manualControlPoint(src, event) global img1 img2 cp; if isempty(cp) || size(cp, 1) ~= str2double(pnl.Children(2).String) warndlg('请先设置控制点数量!'); return; end [x1, y1] = ginput(size(cp, 1)); [x2, y2] = ginput(size(cp, 1)); cp(:, 1) = x1; cp(:, 2) = y1; tform = fitgeotrans(cp, [x2, y2], 'affine'); img2 = imwarp(img1, tform, 'OutputView', imref2d(size(img1))); imshow(img2, 'Parent', ax2); end % 自动选择控制点 function autoControlPoint(src, event) global img1 img2 cp; if isempty(cp) || size(cp, 1) ~= str2double(pnl.Children(2).String) warndlg('请先设置控制点数量!'); return; end pts1 = detectSURFFeatures(rgb2gray(img1)); pts2 = detectSURFFeatures(rgb2gray(img2)); [f1, vpts1] = extractFeatures(rgb2gray(img1), pts1); [f2, vpts2] = extractFeatures(rgb2gray(img2), pts2); indexPairs = matchFeatures(f1, f2, 'MaxRatio', 0.7); matchedPoints1 = vpts1(indexPairs(:, 1)); matchedPoints2 = vpts2(indexPairs(:, 2)); if size(matchedPoints1, 1) >= size(cp, 1) matchedPoints1 = matchedPoints1(1:size(cp, 1)); matchedPoints2 = matchedPoints2(1:size(cp, 1)); end cp(:, 1) = matchedPoints1.Location(:, 1); cp(:, 2) = matchedPoints1.Location(:, 2); tform = fitgeotrans(cp, matchedPoints2.Location, 'affine'); img2 = imwarp(img1, tform, 'OutputView', imref2d(size(img1))); imshow(img2, 'Parent', ax2); end ``` 注意,以上代码仅为示例,实际的代码实现可能会因需求和环境等不同而有所改变。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值