-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathFlit2jpg.py
86 lines (60 loc) · 1.83 KB
/
Flit2jpg.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 9 18:27:19 2020
@author: dlsaavedra
"""
#! /usr/bin/env python
import argparse
import os
import numpy as np
import errno
import flirimageextractor
import matplotlib.pyplot as plt
argparser = argparse.ArgumentParser(
description = 'Change flirt image to jpg image')
argparser.add_argument(
'-i',
'--input',
help='path to an folder of image')
def mkdir(filename):
if not os.path.exists(os.path.dirname(filename)):
try:
os.makedirs(os.path.dirname(filename))
except OSError as exc: # Guard against race condition
if exc.errno != errno.EEXIST:
raise
def _main_(args):
input_path = args.input
files = []
# r=root, d=directories, f = files
for r, d, f in os.walk(input_path):
for file in f:
if '.jpg' in file:
files.append(os.path.join(r, file))
for f in files:
flir = flirimageextractor.FlirImageExtractor()
print(f)
try:
flir.process_image(f)
I = flirimageextractor.FlirImageExtractor.get_thermal_np(flir)
except:
I = plt.imread(f)
#flir.save_images()
#flir.plot()
#img = img.astype(np.int8)
W = np.where(np.isnan(I))
if np.shape(W)[1] > 0:
#xmax = np.max(np.amax(W,axis=0))
ymax = np.max(np.amin(W,axis=1))
img = I[:ymax,:]
else:
img = I
list_string = f.split('/')
list_string[-3]+= '_jpg'
f_aux = '/'.join(list_string)
mkdir(f_aux)
plt.imsave(f_aux, img, cmap = 'gray')
if __name__ == '__main__':
args = argparser.parse_args()
_main_(args)