Add Colors to Black-White picture with DDColor
1 min readJan 27, 2024
DDColor can provide vivid and natural colorization for historical black and white old photos.
In this post, I’ll introduce how to run DDColor on Google Colab free-tier, T4.
Step 1. Clone the repo & install dependencies
First we need to install dependencies and this step will take some time.
!git clone https://github.com/piddnad/DDColor
!cd DDColor
!pip install -r requirements.txt
!python setup.py develop
!pip install "modelscope[cv]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html
Step 2. Adding Colors to Image
import cv2
from modelscope.outputs import OutputKeys
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks
from google.colab.patches import cv2_imshow
img_colorization = pipeline(Tasks.image_colorization, model='damo/cv_ddcolor_image-colorization')
result = img_colorization('https://th.bing.com/th/id/R.bfff865861dc593b14fa030a9ac2aee5?rik=Of2Q7oLKe0r0fg&riu=http%3a%2f%2fstatic.guim.co.uk%2fsys-images%2fGuardian%2fPix%2fpictures%2f2013%2f2%2f18%2f1361186749737%2fblack-and-white-picture-o-005.jpg&ehk=zoDQaeRIcKRivy%2fXZH7lZa3ixweCv47WKzD8uJGwZgw%3d&risl=&pid=ImgRaw&r=0')
cv2.imwrite('result.png', result[OutputKeys.OUTPUT_IMG])
cv2_imshow(result[OutputKeys.OUTPUT_IMG])
Original
Colorized
My Google Colab note is 👇
https://colab.research.google.com/drive/1heF4BYz0Y35TNsmshseaD37USDSp3jY0?usp=sharing