Advertisement
tuomasvaltanen

Untitled

Oct 3rd, 2022 (edited)
1,142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.63 KB | None | 0 0
  1. # DEOLDIFY, use a photo from Drive instead of Internet URL
  2. # notice the line "image_path", uses transformed_image instead of transformed_image_from_url
  3. # also, the parameter is not "path" instead of "url"
  4.  
  5. source_url = '/content/drive/MyDrive/machinelearninginthecloud2022/exercise2b/originals/pic1.jpg' #@param {type:"string"}
  6. render_factor = 36  #@param {type: "slider", min: 7, max: 40}
  7. watermarked = False #@param {type:"boolean"}
  8.  
  9. if source_url is not None and source_url !='':
  10.     image_path = colorizer.plot_transformed_image(path=source_url, render_factor=render_factor, compare=True, watermarked=watermarked)
  11.     show_image_in_notebook(image_path)
  12. else:
  13.     print('Provide an image url and try again.')
  14.  
  15. # GETTING ALL PHOTOS IN A FOLDER
  16.  
  17. # THE LOGIC IS THIS:
  18.  
  19. # get the paths of the photos in our Google Drive old photos folder into a list
  20. # import the os-module
  21. import os
  22.  
  23. # some folder in Google Drive
  24. image_folder = '/content/drive/MyDrive/machinelearninginthecloud2022/exercise2b/originals'
  25.  
  26. # get file names
  27. image_files = os.listdir(image_folder)
  28.  
  29. # initialize a list for the photo paths
  30. photos = []
  31.  
  32. for i in image_files:
  33.   photos.append(image_folder + "/" + i)
  34.  
  35. # check out the results
  36. print(photos)
  37.  
  38. for photo in photos:
  39.   print(photo)
  40.   image_path = colorizer.plot_transformed_image(path=photo, render_factor=render_factor, compare=True, watermarked=watermarked)
  41.   show_image_in_notebook(image_path)
  42.  
  43. # use a for-loop to go through each photo in the list
  44. #   use DeOldify to colorize each photo at a time
  45. #   save the colorized photo into a folder
  46.  
  47. # ANOTHER VERSION
  48.  
  49. # THE LOGIC IS THIS:
  50.  
  51. # get the paths of the photos in our Google Drive old photos folder into a list
  52. # import the os-module
  53. import os
  54.  
  55. from PIL import Image
  56.  
  57. # some folder in Google Drive
  58. image_folder = '/content/drive/MyDrive/machinelearninginthecloud2022/exercise2b/originals'
  59.  
  60. # get file names
  61. image_files = os.listdir(image_folder)
  62.  
  63. # initialize a list for the photo paths
  64. photos = []
  65.  
  66. for i in image_files:
  67.   photos.append(image_folder + "/" + i)
  68.  
  69. # check out the results
  70. print(photos)
  71. number = 1
  72.  
  73. for photo in photos:
  74.   print(photo)
  75.   image_path = colorizer.plot_transformed_image(path=photo, render_factor=render_factor, compare=True, watermarked=watermarked)
  76.   show_image_in_notebook(image_path)
  77.   img = Image.open(image_path)
  78.   img.save("/content/drive/MyDrive/machinelearninginthecloud2022/exercise2b/colorized/photo" + str(number) + ".jpg")
  79.   number = number + 1
  80.  
  81.  
  82. # use a for-loop to go through each photo in the list
  83. #   use DeOldify to colorize each photo at a time
  84. #   save the colorized photo into a folder
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement