高光谱图像加载、归一化和增强(jupyter book)

1.获取高光谱图像:我用的是indian_pines的数据集,感兴趣的兄弟可以自行去官方网下载,gt的那个是它的标签哦,别搞错了。

2.图像加载:

(1)从本地路径加载

python 复制代码
import scipy.io as sio

# 文件路径
file_path = '你的本地路径'

# 使用scipy加载.mat文件
data = sio.loadmat(file_path)

# 提取高光谱图像数据
spectral_image = data['indian_pines']

(2)记得查看打印下你的数据集维度,print("数据集维度:", spectral_image.shape),后面有用到。

3.归一化处理:

归一化处理:将数据集的值缩放到一个特定的范围内的过程。在显示图像时,归一化处理可以使得图像的亮度和对比度更加均衡,以便更好地观察图像中的细节。

python 复制代码
#数据集归一化处理
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
matplotlib.use('TkAgg')#将 Matplotlib 的后端设置为一个支持图像显示的后端
%matplotlib inline#将图像嵌入jupyter book中


# 对每个通道进行归一化
normalized_image = spectral_image / np.max(spectral_image)

# 将每个通道转换为灰度图像
gray_image = np.mean(normalized_image, axis=-1)

# 将灰度图像堆叠在一起来创建伪彩色图像
colorized_image = np.stack([gray_image] * 3, axis=-1)

# 显示图像
plt.imshow(colorized_image)
plt.axis('off')
plt.show()

4.图像增强:前面显示的图像太模糊了,我觉得很难受,给它弄增强了,就明显一些。

python 复制代码
#图像增强
import cv2
# 将灰度图像转换为伪彩色图像
colorized_image = cv2.applyColorMap((gray_image * 255).astype(np.uint8), cv2.COLORMAP_JET)
# 显示图像
plt.imshow(colorized_image)
plt.axis('off')
plt.show()
相关推荐
叫我:松哥11 分钟前
基于Python的共享单车租赁数据分析与预测系统,技术栈flask+boostrap+随机森林+XGBoost
人工智能·python·深度学习·算法·随机森林·数据分析·flask
utf8mb4安全女神12 分钟前
HTML网页【vscode】【Linux】
ide·vscode·编辑器
Li#20 分钟前
web端电商项目自动下单发货评价晒图需要用到的能力
python·自动化
雨辰AI40 分钟前
从零搭建大模型本地运行环境|Python+CUDA 基础配置避坑大全
大数据·开发语言·人工智能·python·ai·ai编程·ai写作
DogDaoDao1 小时前
【第 05 篇】Python的字典与集合
开发语言·python·集合·字典
涛声依旧-底层原理研究所1 小时前
混合检索 + 重排:让 AI Agent 拥有「既全又准」的认知骨架
人工智能·python
努力写A题的小菜鸡1 小时前
01-PyTorch加载数据初认识(dataset运用)
人工智能·pytorch·python
abcy0712131 小时前
python fastapi celery hdfs 异步上传
python·hdfs·fastapi
Dxy12393102161 小时前
Python多线程如何操作全局变量:从踩坑到最佳实践
python
SilentSamsara1 小时前
RAG 系统入门:LangChain/LlamaIndex + Chroma 向量数据库的检索增强实战
数据库·人工智能·python·青少年编程·langchain