Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -57,6 +57,7 @@ if user_image_object is not None:
|
|
| 57 |
#H,S,V = Hue , Saturation, Value (ie color value) parameters
|
| 58 |
#Hue has range [0,179] , Saturation [0,255] , Value [0,255]
|
| 59 |
|
|
|
|
| 60 |
for i in my_hue_list:
|
| 61 |
# modify hue channel by adding difference and modulo 180 (modulo because hue parameter only goes up to index 180, shouldn't exceed that )
|
| 62 |
hnew = np.mod(h + i, 180).astype(np.uint8) #<<<<<<<<<<<<<<<< where the iter comes in
|
|
@@ -66,6 +67,8 @@ if user_image_object is not None:
|
|
| 66 |
|
| 67 |
# convert back to bgr
|
| 68 |
bgr_new = cv2.cvtColor(hsv_new, cv2.COLOR_HSV2BGR)
|
|
|
|
|
|
|
| 69 |
|
| 70 |
# put alpha back into bgr_new
|
| 71 |
#bgra = cv2.cvtColor(bgr_new, cv2.COLOR_BGR2BGRA)
|
|
@@ -77,21 +80,9 @@ if user_image_object is not None:
|
|
| 77 |
|
| 78 |
|
| 79 |
'''for this demo prob need to retain image objects bgr_new in an img_array by appending them to that then build them into a gif from the array'''
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
-
|
| 82 |
-
for i in my_hue_list:
|
| 83 |
-
output_filename = 'output_bgr_new_' + str(i) +'.png' #<<<<<<<<<<<<<<<< where the iter comes in
|
| 84 |
-
Image(filename='/main_outputs/' + output_filename)
|
| 85 |
-
|
| 86 |
-
# filepaths
|
| 87 |
-
fp_in = "/main_outputs/*.png"
|
| 88 |
-
fp_out = "/" + original_filename + "_HueShiftGIF_color_step_" + str(color_step) + "_duration_" + str(duration_parameter) + "_loop_" + str(loop_parameter) + ".gif"
|
| 89 |
-
|
| 90 |
-
# https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#gif
|
| 91 |
-
img, *imgs = [Image.open(f) for f in sorted(glob.glob(fp_in))]
|
| 92 |
-
img.save(fp=fp_out, format='GIF', append_images=imgs,
|
| 93 |
-
save_all=True, duration=duration_parameter, loop=loop_parameter)
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
st.image(fp_out)
|
|
|
|
| 57 |
#H,S,V = Hue , Saturation, Value (ie color value) parameters
|
| 58 |
#Hue has range [0,179] , Saturation [0,255] , Value [0,255]
|
| 59 |
|
| 60 |
+
img_array = []
|
| 61 |
for i in my_hue_list:
|
| 62 |
# modify hue channel by adding difference and modulo 180 (modulo because hue parameter only goes up to index 180, shouldn't exceed that )
|
| 63 |
hnew = np.mod(h + i, 180).astype(np.uint8) #<<<<<<<<<<<<<<<< where the iter comes in
|
|
|
|
| 67 |
|
| 68 |
# convert back to bgr
|
| 69 |
bgr_new = cv2.cvtColor(hsv_new, cv2.COLOR_HSV2BGR)
|
| 70 |
+
|
| 71 |
+
img_array.append(bgr_new )
|
| 72 |
|
| 73 |
# put alpha back into bgr_new
|
| 74 |
#bgra = cv2.cvtColor(bgr_new, cv2.COLOR_BGR2BGRA)
|
|
|
|
| 80 |
|
| 81 |
|
| 82 |
'''for this demo prob need to retain image objects bgr_new in an img_array by appending them to that then build them into a gif from the array'''
|
| 83 |
+
out = cv2.VideoWriter('outputvideo.mp4',cv2.VideoWriter_fourcc(*'DIVX'), 15, size)
|
| 84 |
+
for i in range(len(img_array)):
|
| 85 |
+
out.write(img_array[i])
|
| 86 |
+
out.release()
|
| 87 |
|
| 88 |
+
st.video(outputvideo.mp4)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|