Skip to content

Instantly share code, notes, and snippets.

@merrybingo
Created November 7, 2019 09:25
Show Gist options
  • Save merrybingo/4e0c156c2320ba16129748beb5c78fad to your computer and use it in GitHub Desktop.
Save merrybingo/4e0c156c2320ba16129748beb5c78fad to your computer and use it in GitHub Desktop.
tif 파일 밴드 별 저장하기
% tif 파일 밴드 별 저장하기
clear; clc;
dir_path = "C:\Temp\";
files = dir(strcat(dir_path, '*.tif'));
for i=1:length(files)
path = strcat(files(i).folder, "\" ,files(i).name);
base_name = split(files(i).name, ".");
[img, r] = geotiffread(path);
info = geotiffinfo(path);
[w, h, c] = size(img);
for k=1:c
save_path = strcat(files(i).folder, "\", base_name(1), "_", int2str(k), ".tif");
temp_img = img(:, :, k);
geotiffwrite(save_path, temp_img, r, 'GeoKeyDirectoryTag', info.GeoTIFFTags.GeoKeyDirectoryTag);
end
end
disp("finish");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment