Python Forum

Full Version: How do I apply a Gaussian blur to a particular edge of geometry in Matplotlib?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want to apply Gaussian blur to a particular edge of polygons. The code below generates 4 white polygons in black rectangle which the left edge in green (fig below). I want to apply the Gaussian blur just to that green edge.Please note that I can't apply cv.circle or cv.rectangle since the location of green edge is changing in each polygon.

[Image: mjXc4.png]


Quote:import numpy as np
import matplotlib.pyplot as plt
import cv2 as cv

pixels = 600
my_dpi = 100
num_geo=3

coord = np.array([[[-150, -200], [300, -200], [300, 0], [150, 200], [-150, 200]],
[[-300, -200], [200, -300], [200, -50], [200, 300], [-150, 200]],
[[-140, -230], [350, -260], [350, 0], [140, 200], [-180, 220]],
[[-180, -240], [370, -270], [370, 0], [170, 200], [-190, 230]]])

for i in range(4):
geo = coord[i, :, :]
fig = plt.figure(num_geo,figsize=( pixels/my_dpi, pixels/my_dpi),facecolor='k', dpi=my_dpi)
plt.axes([0,0,1,1])
rectangle = plt.Rectangle((-300, -300), 600, 600, fc='k')
plt.gca().add_patch(rectangle)
polygon = plt.Polygon(coord[i],color='w')
plt.gca().add_patch(polygon)
b=plt.plot([coord[i][0][0], coord[i][-1][0]], [coord[i][0][1], coord[i][-1][1]], color='#008000', lw=4)
img = cv.blur(b,(5,5))
plt.axis('off')
plt.axis([-300,300,-300,300])
plt.savefig('figure2/%d.png' % i, dpi=my_dpi)
plt.close()