数据集存储地址:https://pan.baidu.com/s/1dwKOuq-kDVAXebV8jy-DaQ?pwd=91jn
裁剪和拼接程序:https://github.com/HaiLei-Fly/CHLandsat8
CHLandsat8 数据集: 本文创建的一个中国Landsat 8 高分辨率云检测数据集,其中包含了 2021年 1 月至 2021 年 12 月 Landsat 8 卫星从中国不同地区采集的 64 个全场景。据我们所知,CHLandsat8 可能是从 Landsat 8 卫星最早收集中国地区的遥感图像云检测数据集。而且与以往的数据集相比,CHLandsat8 中的场景更加复杂多样,实现高精度的云检测更具挑战性。 该数据集覆盖中国西北地区、 北方地区、 青藏地区和南方地区, 包含各种土地覆盖类
型,包括城市、冰雪、草原、山川、森林、海洋和沙漠。数据集是自然彩色图像,尺寸大约为 8000*8000像素。此外,数据集的参考云 mask 已进行标注,并可在网上查阅。我们相信,开放的 CHLandsat8 数据集有助于促进云检测的研究。
在建立数据集的过程中,专家手动逐个像素地标记云在图像中的位置,并通过分别用 1 和 0 标记云和背景的像素值来创建参考 mask。为了确保标签的准确性,参考 mask 已经过迭代检查和校正。在实验中,本文从数据集中随机选取 44 幅图像作为训练集 CHLandsat8-TR , 20 幅 图 像 作 为 测 试 集CHLandsat8-TE。
由于 GPU 的内存有限,数据集不同场景图像被裁剪成 352×352 大小,详细数据如表所示。
Dataset | Scene | Image | Train/Test |
---|---|---|---|
CHLandsat8-TR | 44 | 22616 | Train |
CHLandsat8-TE | 22 | 10080 | Test |
图像裁剪程序:
# -*- coding:utf-8 -*-
import os
import matplotlib.pyplot as plt
import cv2
import numpy as np
import math
import glob
"""
输入:图片路径(path+filename),裁剪获得小图片的列数、行数(也即宽、高)
输出:无
"""
def crop_one_picture(path,filename,cols,rows):
img=cv2.imread(path+filename,1)##读取彩色图像,图像的透明度(alpha通道)被忽略,默认参数;灰度图像;读取原始图像,包括alpha通道;可以用1,0,-1来表示
# img=cv2.imread(path+filename,-1) # mask
# img= cv2.copyMakeBorder(img, top=97, bottom=98, left=152, right=153,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 1
# img= cv2.copyMakeBorder(img, top=87, bottom=88, left=147, right=148,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 2
# img= cv2.copyMakeBorder(img, top=137, bottom=138, left=36, right=37,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 3
# img= cv2.copyMakeBorder(img, top=132, bottom=133, left=31, right=32,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 4
# img= cv2.copyMakeBorder(img, top=12, bottom=13, left=62, right=63,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 5
# img= cv2.copyMakeBorder(img, top=107, bottom=108, left=6, right=7,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 6
# img= cv2.copyMakeBorder(img, top=107, bottom=108, left=167, right=168,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 7
# img= cv2.copyMakeBorder(img, top=97, bottom=98, left=162, right=163,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 8
# img= cv2.copyMakeBorder(img, top=82, bottom=83, left=152, right=153,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 9
# img= cv2.copyMakeBorder(img, top=57, bottom=58, left=122, right=123,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 10
# img= cv2.copyMakeBorder(img, top=6, bottom=7, left=81, right=82,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 11
# img= cv2.copyMakeBorder(img, top=62, bottom=63, left=112, right=113,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 12
# img= cv2.copyMakeBorder(img, top=22, bottom=23, left=67, right=68,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 13
# img= cv2.copyMakeBorder(img, top=127, bottom=128, left=16, right=17,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 14
# img= cv2.copyMakeBorder(img, top=21, bottom=22, left=101, right=102,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 15
# img= cv2.copyMakeBorder(img, top=158, bottom=159, left=27, right=28,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 16
# img= cv2.copyMakeBorder(img, top=31, bottom=32, left=106, right=107,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 17
# img= cv2.copyMakeBorder(img, top=97, bottom=98, left=152, right=153,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 18
# img= cv2.copyMakeBorder(img, top=152, bottom=153, left=51, right=52,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 19
# img= cv2.copyMakeBorder(img, top=142, bottom=143, left=51, right=52,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 20
img= cv2.copyMakeBorder(img, top=167, bottom=168, left=61, right=62,
borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 21
# img= cv2.copyMakeBorder(img, top=132, bottom=133, left=31, right=32,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 22
# img= cv2.copyMakeBorder(img, top=152, bottom=153, left=41, right=42,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 23
# img= cv2.copyMakeBorder(img, top=82, bottom=83, left=147, right=148,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 24
# img= cv2.copyMakeBorder(img, top=16, bottom=17, left=91, right=92,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 25
# img= cv2.copyMakeBorder(img, top=57, bottom=58, left=122, right=123,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 26
# img= cv2.copyMakeBorder(img, top=82, bottom=83, left=147, right=148,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 27
# img= cv2.copyMakeBorder(img, top=52, bottom=53, left=117, right=118,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 28
# img= cv2.copyMakeBorder(img, top=137, bottom=138, left=36, right=37,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 29
# img= cv2.copyMakeBorder(img, top=132, bottom=133, left=26, right=27,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 30
# img= cv2.copyMakeBorder(img, top=47, bottom=48, left=102, right=103,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 31
# img= cv2.copyMakeBorder(img, top=172, bottom=173, left=66, right=67,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 32
# img= cv2.copyMakeBorder(img, top=1, bottom=2, left=61, right=62,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 33
# img= cv2.copyMakeBorder(img, top=16, bottom=17, left=91, right=92,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 34
# img= cv2.copyMakeBorder(img, top=152, bottom=153, left=51, right=52,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 35
# img= cv2.copyMakeBorder(img, top=107, bottom=108, left=172, right=173,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 36
# img= cv2.copyMakeBorder(img, top=112, bottom=113, left=167, right=168,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 37
# img= cv2.copyMakeBorder(img, top=92, bottom=93, left=147, right=148,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 38
# img= cv2.copyMakeBorder(img, top=87, bottom=88, left=147, right=148,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 39
# img= cv2.copyMakeBorder(img, top=12, bottom=13, left=72, right=73,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 40
# img= cv2.copyMakeBorder(img, top=127, bottom=128, left=11, right=12,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 41
# img= cv2.copyMakeBorder(img, top=112, bottom=113, left=1, right=2,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 42
# img= cv2.copyMakeBorder(img, top=11, bottom=12, left=76, right=77,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 43
# img= cv2.copyMakeBorder(img, top=157, bottom=158, left=51, right=52,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 44
####### Test
# img= cv2.copyMakeBorder(img, top=142, bottom=143, left=46, right=47,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 1
# img= cv2.copyMakeBorder(img, top=67, bottom=68, left=127, right=128,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 2
# img= cv2.copyMakeBorder(img, top=132, bottom=133, left=36, right=37,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 3
# img= cv2.copyMakeBorder(img, top=127, bottom=128, left=16, right=17,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 4
# img= cv2.copyMakeBorder(img, top=21, bottom=22, left=106, right=107,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 5
# img= cv2.copyMakeBorder(img, top=127, bottom=128, left=11, right=12,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 6
# img= cv2.copyMakeBorder(img, top=102, bottom=103, left=167, right=168,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 7
# img= cv2.copyMakeBorder(img, top=97, bottom=98, left=162, right=163,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 8
# img= cv2.copyMakeBorder(img, top=132, bottom=133, left=16, right=17,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 9
# img= cv2.copyMakeBorder(img, top=107, bottom=108, left=1, right=2,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 10
# img= cv2.copyMakeBorder(img, top=31, bottom=32, left=111, right=112,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 11
# img= cv2.copyMakeBorder(img, top=107, bottom=108, left=1, right=2,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 12
# img= cv2.copyMakeBorder(img, top=21, bottom=22, left=96, right=97,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 13
# img= cv2.copyMakeBorder(img, top=6, bottom=7, left=76, right=77,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 14
# img= cv2.copyMakeBorder(img, top=152, bottom=153, left=46, right=47,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 15
# img= cv2.copyMakeBorder(img, top=92, bottom=93, left=152, right=153,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 16
# img= cv2.copyMakeBorder(img, top=6, bottom=7, left=81, right=82,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 17
# img= cv2.copyMakeBorder(img, top=162, bottom=163, left=51, right=52,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 18
# img= cv2.copyMakeBorder(img, top=162, bottom=163, left=61, right=62,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 19
# img= cv2.copyMakeBorder(img, top=1, bottom=2, left=66, right=67,
# borderType=cv2.BORDER_CONSTANT, value=[0, 0, 0]) # 20
sum_rows=img.shape[0] #高度
sum_cols=img.shape[1] #宽度
save_path=path+"\\crop{0}_{1}\\".format(cols,rows) #保存的路径
if not os.path.exists(save_path):
os.makedirs(save_path)
print("裁剪所得{0}列图片,{1}行图片.".format(int(sum_cols/cols),int(sum_rows/rows)))
k = 0
for i in range(int(sum_rows/rows)):
for j in range(int(sum_cols/cols)):
k += 1
# cv2.imwrite(save_path+'patch_{}_{}_by_{}_'.format(k, i+1, j+1)+ filename.split('.')[0] + os.path.splitext(filename)[1],img[i*cols:(i+1)*cols,j*rows:(j+1)*rows,:]) # L image
cv2.imwrite(save_path+'patch_{}_{}_by_{}_'.format(k, i+1, j+1)+ filename.split('.')[0] + os.path.splitext(filename)[1],img[i*cols:(i+1)*cols,j*rows:(j+1)*rows]) # mask
print("裁剪完成,得到{0}张图片.".format(int(sum_cols/cols)*int(sum_rows/rows)))
print("文件保存在{0}".format(save_path))
if __name__ == '__main__':
path='G:\\CHLandsat8\\LandsatNC\\Train\\patch\\' #要裁剪的图片所在的文件夹
picture_names = sorted(glob.glob(path + '*.png'))
num = 0
for picture_name in picture_names:
print(picture_name)
name = picture_name.split('\\')[5]
print(name)
crop_one_picture(path,name,352,352)
图像拼接程序:
from cv2 import cv2
import numpy as np
import os
# 分割后的图片的文件夹,以及拼接后要保存的文件夹
pic_path = 'H:/FAANet/Pre/CHLandsat8/joint/'
pic_target = 'H:/FAANet/Pre/38_Cloud_Train/CHLandsat8-joint/'
# 数组保存分割后图片的列数和行数,注意分割后图片的格式为x_x.jpg,x从1开始
num_width_list = []
num_lenght_list = []
# 读取文件夹下所有图片的名称
picture_names = os.listdir(pic_path)
if len(picture_names)==0:
print("没有文件")
else:
# 获取分割后图片的尺寸
img_1_1 = cv2.imread(pic_path + 'patch_1_1_by_1_LC08_L1TP_117040_20210625_20210630_01_T1.png')
(width, length, depth) = img_1_1.shape
# 分割名字获得行数和列数,通过数组保存分割后图片的列数和行数
for picture_name in picture_names:
num_width_list.append(int(picture_name.split("_")[-10]))
num_lenght_list.append(int((picture_name.split("_")[-8])))
# 取其中的最大值
num_width = max(num_width_list)
num_length = max(num_lenght_list)
# 预生成拼接后的图片
splicing_pic = np.zeros((num_width*width, num_length*length, depth))
# 循环复制
for idx in range(0, 1):
k = 0
splicing_pic = np.zeros((num_width*width, num_length*length, depth))
for i in range(1, num_width+1):
for j in range(1, num_length+1):
k += 1
img_part = cv2.imread(pic_path + 'patch_{}_{}_by_{}_LC08_L1TP_117040_20210625_20210630_01_T1.png'.format(k, i, j),1)
splicing_pic[ width*(i-1) : width*i, length*(j-1) : length*j, :] = img_part
print(splicing_pic.shape)
cv2.imwrite(pic_target + 'LC08_L1TP_' + picture_names[idx].split("_")[-5] + '_' + picture_names[idx].split("_")[-4] + '_' + picture_names[idx].split("_")[-3] + '_01_T1.png', splicing_pic)
print("done!!!")
彩色图像示例
彩色图像裁剪示例
GT图像示例
GT图像裁剪示例
希望本文对大家有帮助,上文若有不妥之处,欢迎指正
分享决定高度,学习拉开差距