Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F110275246
data_loaders.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Apr 25, 11:53
Size
3 KB
Mime Type
text/x-objective-c
Expires
Sun, Apr 27, 11:53 (2 d)
Engine
blob
Format
Raw Data
Handle
25752640
Attached To
R8797 solarPV
data_loaders.py
View Options
import
os
#import tensorflow
import
numpy
as
np
import
scipy
import
json
#import cv2
from
scipy
import
ndimage
#from matplotlib import pyplot as plt
from
PIL
import
Image
import
augmentation_tools
#Cluster paths:
'''
images under:
/work/hyenergy/raw/SwissTopo/RGB_25cm/data_resized/SI_25_2015_1301-13/original/PV/xxx.png
/work/hyenergy/raw/SwissTopo/RGB_25cm/data_resized/SI_25_2015_1301-13/labels/PV/xxxx_label.png
'''
## ========= CHANGE HERE THE PATH ===============================
## ==============================================================
#image_path = "/work/hyenergy/raw/SwissTopo/RGB_25cm/data_resized/"
## ==============================================================
## ==============================================================
#image_folders = ['SI_25_2015_1301-13', 'SI_25_2015_1301-14', 'SI_25_2015_1301-32', 'SI_25_2015_1261-33']
def
read_json
():
with
open
(
'parameters.json'
)
as
json_file
:
json_data
=
json
.
load
(
json_file
)
return
json_data
def
path_label
(
filename
,
label_name
,
extension_name
):
"""
returns the path to the label from a filename of the form :
'SI_25_2015_1242-13_0_750' or 'SI_25_2015_1242-13_0_750.png'
"""
filename
=
filename
.
replace
(
label_name
,
''
)
.
replace
(
extension_name
,
''
)
return
filename
+
label_name
+
extension_name
#TODO improve loading of rotations
def
load_images
(
lights
=
False
,
rotations
=
False
):
'''
Returns the loaded images, takes 2 arguments, lights and rotations to
give the option to return the different lightnings and/or the rotations
N.B. Images are returned as additional images, not as additional layer (features). Maybe we should add the lighting as a layer?
For sure Sobel filter should be added as layer... # RC
'''
json_data
=
read_json
()
image_path
=
json_data
[
'image_path'
]
image_folders
=
json_data
[
'image_folders'
]
original_folder
=
"/original/PV/"
labels_folder
=
"/labels/PV/"
label_name
=
"_label"
extension_name
=
'.png'
original_images
=
[]
labeled_images
=
[]
for
folder
in
image_folders
:
for
imagefile
in
os
.
listdir
(
image_path
+
folder
+
original_folder
):
label_dir
=
os
.
listdir
(
image_path
+
folder
+
labels_folder
)
labelfile
=
path_label
(
imagefile
,
label_name
,
extension_name
)
if
imagefile
.
startswith
(
'SI'
)
and
labelfile
in
label_dir
:
original_image
=
Image
.
open
(
image_path
+
folder
+
original_folder
+
imagefile
)
labeled_image
=
Image
.
open
(
image_path
+
folder
+
labels_folder
+
labelfile
)
if
lights
:
for
image
in
augmentation_tools
.
change_contrast_multi
(
original_image
,
[
-
80
,
0
,
100
]):
original_images
.
append
(
np
.
array
(
image
,
dtype
=
'uint8'
))
labeled_images
.
append
(
np
.
array
(
labeled_image
,
dtype
=
'uint8'
))
else
:
original_images
.
append
(
np
.
array
(
original_image
,
dtype
=
'uint8'
))
labeled_images
.
append
(
np
.
array
(
labeled_image
,
dtype
=
'uint8'
))
if
rotations
:
original_images_rotations
=
[]
labeled_images_rotations
=
[]
for
idx
in
range
(
len
(
original_images
)):
original_images_rotations
=
original_images_rotations
+
augmentation_tools
.
rotatedImages
(
original_images
[
idx
])
labeled_images_rotations
=
labeled_images_rotations
+
augmentation_tools
.
rotatedImages
(
labeled_images
[
idx
])
return
original_images_rotations
,
labeled_images_rotations
return
original_images
,
labeled_images
def
add_sobel_layer
(
images
):
'''
Adds sobel layer to all images
:param images: an array of 3 layer numpy images(RGB)
:return: sobel_images: same array with a 4th layer
'''
return
0
def
add_light_layer
(
images
):
'''
Adds 3 new layers
:param images: array of 3 layer numpy images(RGB)
:return: light_images: same array with 3 new layers of the altered image
'''
return
0
Event Timeline
Log In to Comment