How to write text over an image using scikit-image?

Viewed 2208

I know how to do this with OpenCV and PIL. I can't use OpenCV in this project and if I use PIL I have to convert in between image PIL Image and numpy array. I don't want to do that. I'm already using skimage so...

How do I write text on top of an image using skimage?

I've looked at the skimage draw functions, but they seem to only handle shapes and lines not text. Maybe I'm searching the wrong words, but I don't see anything in the docs.

2 Answers

I agree with Sarim. You should use opencv here

import cv2
font = cv2.FONT_HERSHEY_SIMPLEX

#img is your image in below line
cv2.putText(img,'Text on image goes here',(10,500), font, 1,(255,255,255),2)
#Display the image
cv2.imshow("img",img)

cv2.waitKey(0)
%matplotlib inline
from skimage.draw import *
import numpy as np
import matplotlib.pyplot as plt 
rr, cc = rectangle(start=(0, 0), extent=(1, 4))
img = np.zeros((5, 5, 3), dtype=np.int32)
img[rr, cc, 0] = 0
img[rr, cc, 1] = 255
img[rr, cc, 2] = 255
plt.text(2, 2, "some text", dict(color='red', va='center', ha='center'))
plt.imshow(img)
plt.axis('off')

You can use matplotlib to draw text, since scikit-image is also using matplotlib as backend

Related