Mosaic Effect source code (opencv-python)
You can get mosaic effect image.
The zip files is included python source code and test image(result).
The source code has below functions:
- superpixel function
- subdiv function
- delaunay function
- voronoi function
I think you can apply these functions for your project properly.
Thank you.
*github: https://github.com/MareArts/Mosaic_effect
This is main code (how to use):
##############################################
img = cv.imread('iu.jpg')
height,width,channels = img.shape
mask = getSuperpixelMask(img, 500) #500 segmentation
polygons, centers = getPolygonNCenters(mask)
subdiv = getSubDiv(centers, width, height)
delaunayImg = np.ones((height, width, 3), dtype = "uint8")*255 #3channel
delaunayImg_l = draw_delaunay(delaunayImg, subdiv, img)
voronoiImg = np.ones((height, width, 3), dtype = "uint8")*255 #3channel
voronoiImg_l = draw_voronoi(voronoiImg, subdiv, img)
## show and save images ##
cv.imwrite('delaunayImg.jpg',delaunayImg)
cv.imwrite('delaunayImg_l.jpg',delaunayImg_l)
cv.imwrite('voronoiImg.jpg',voronoiImg)
cv.imwrite('voronoiImg_l.jpg',voronoiImg_l)
cv.imwrite('mask.jpg',mask)
##############################################
€1.00Price