Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F110752326
augmentation_tools.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
Sun, Apr 27, 23:11
Size
1 KB
Mime Type
text/x-objective-c
Expires
Tue, Apr 29, 23:11 (2 d)
Engine
blob
Format
Raw Data
Handle
25836825
Attached To
R8797 solarPV
augmentation_tools.py
View Options
import
os
#import tensorflow
import
numpy
as
np
import
scipy
#import cv2
from
scipy
import
ndimage
#from matplotlib import pyplot as plt
from
PIL
import
Image
def
change_contrast
(
img
,
level
):
factor
=
(
259
*
(
level
+
255
))
/
(
255
*
(
259
-
level
))
def
contrast
(
c
):
return
128
+
factor
*
(
c
-
128
)
return
img
.
point
(
contrast
)
def
change_contrast_multi
(
img
,
steps
):
result
=
[]
for
n
,
level
in
enumerate
(
steps
):
img_filtered
=
change_contrast
(
img
,
level
)
result
.
append
(
img_filtered
)
return
result
def
rotatedImages
(
image_array
):
return
[
ndimage
.
rotate
(
image_array
,
degree
)
for
degree
in
range
(
0
,
360
,
90
)]
## rotated image, 4 times 90 degree
def
rgb2gray
(
rgb
):
return
np
.
dot
(
rgb
[
...
,:
3
],
[
0.299
,
0.587
,
0.114
])
def
sobel
(
image_array
):
image_gray
=
rgb2gray
(
image_array
)
.
astype
(
'int'
)
dx
=
ndimage
.
sobel
(
image_gray
,
axis
=
0
,
mode
=
'constant'
)
# horizontal derivative
dy
=
ndimage
.
sobel
(
image_gray
,
axis
=
1
,
mode
=
'constant'
)
# vertical derivative
mag
=
np
.
hypot
(
dx
,
dy
)
# magnitude
return
mag
Event Timeline
Log In to Comment