I have been trying to convert text outline to pixels, but unfortuantly I couldn’t reach to a good result, look at that attachment (preview), the edges appear jagged and irregular, which detracts from the overall visual quality of the text. I have even used cv2 lib but that didnt help me at all, is there a method to improve the edges,
here is my code:
from PIL import Image, ImageFilter
import numpy as np
def outline_text_to_pixelsX(obj, supersampling):
xy_pairs = []
for pixel in Convert.text_to_pixels(obj, supersampling):
x, y, alpha = int(pixel.y), int(pixel.x), pixel.alpha
xy_pairs.append([x, y])
max_x, max_y = np.max(xy_pairs, 0)
im = Image.new(mode="L", size=(max_x+1, max_y+1))
pixels = im.load()
for xy_temp in xy_pairs:
pixels[xy_temp[0], xy_temp[1]] = 255
im2 = im.filter(ImageFilter.FIND_EDGES)
edge_coords = np.argwhere(np.array(im2))
outline_pixels = [Pixel(coord[0], coord[1], 255) for coord in edge_coords]
return outline_pixels
I have tried many libs including cv2 to get a good result of converting text outline to pixels but the edges appear jagged and irregular, which detracts from the overall visual quality of the text, and I’m expecting to get help to improve my code
I don’t see you mentioning stroke width anywhere despite using PIL; is there a reason you aren’t able to use that feature?
What are you trying to do? How would a good result look?
I have use stroke width with stroke_fill but it didn’t help at all, it does not the take text outline, look at the result link compare it to the img that in my post link, I want to fix the issue that I had which is the edges appear jagged and irregular in my outline text that has been converted to pixels
Ok now I got what I want, but the text outline looks expanded or offset comparing to the original text > IMG. Here is my code in img CODE