forked from facebookresearch/segment-anything
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjpeg_to_tif.py
More file actions
54 lines (42 loc) · 1.45 KB
/
jpeg_to_tif.py
File metadata and controls
54 lines (42 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
"""
The program converts .jpg/.png to tif and also generates a .gif animation.
@author: Siddharth Shankar
"""
import imageio
from fnmatch import fnmatch
import os
from datetime import datetime as dt
from tqdm import tqdm
import pandas as pd
from osgeo import gdal
import rasterio as ras
images = []
# DIRECTORY STRUCTURE for Labels and Images
# BASE_PATH = r'C:/ICEYE/2023/subsets/subset_0_of_ICEYE_X7_GRD_SM_59797_20210620T052843_M_256'
BASE_PATH = r'C:/segment-anything/images/icebergs'
# BASE_PATH = r'C:\ICEYE\2023\clipped'
pattern = '*_T24WWU_20190507T144439.tif'
# Setting up path structure based on fjord and satellite sensor used
fileNames = []
for _,dirs,files in os.walk(BASE_PATH,topdown=True):
dirs.clear() #excludes the files in subdirectories
for name in files:
if fnmatch(name,pattern):
fileNames.append(name)
options_ = [
'-ot Byte',
'-of PNG',
'-b 1 -b 2 -b 3',
'-scale'#' #0 255', #120 150
]
options_string = " ".join(options_)
# Defining output path directory for all sensor .jpg created
out_path = BASE_PATH#+'/jpgs'
# Converting each geotiff into .jpg
for file_ in fileNames:
outfile = file_.split('.')[0]+'.png'
print(outfile)
img = gdal.Open(os.path.join(BASE_PATH,file_))
gdal.Translate(os.path.join(out_path,outfile),img,format='PNG',
options=options_string)