0

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.

enter image description here

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()
Hamed
  • 73
  • 2
  • 10
  • I am not sure if you can pass a plot to `blur` (i.e. `cv.blur(b,(5,5))`). – SKPS Feb 02 '20 at 21:39
  • 1
    Perhaps you can save the plot as image, read and specify region for blurring like here? https://stackoverflow.com/questions/52365190/blur-a-specific-part-of-an-image – SKPS Feb 02 '20 at 21:42
  • @Sathish I did that before and it's not proper way for my problem since this approach apply the Gaussian blur on the selected box. As I mentioned in my question I just want to apply it exactly on the particular edge for each polygon. – Hamed Feb 03 '20 at 19:12
  • you want to apply only on that particular edge every time or the edge can be top or bottom or right as well. Also can you post an image without the green line. – Vardan Agarwal Feb 15 '20 at 20:19

0 Answers0