2017-12-21 13 views
0

검정색 이미지에 흰 반점을 그리기위한 샘플 코드를 작성했습니다. 한 번에 한 자리를 그릴 수있었습니다. 저는 입력으로 포인트 세트를주고 검은 이미지에 흰색 이미지 스폿을 그립니다. 누구든지 진행 방법에 대해 제안 할 수 있습니까? 당신이 무엇을 필요로하지 않습니다 같은 ImageHandler 클래스검은 색 그림에 점을 찍으십시오.

from PIL import Image,ImageDraw 
import time 
class ImageHandler(object): 
""" 
with the aspect of no distortion and looking from the same view 
""" 

    reso_width = 0 
    reso_height = 0 
    radius = 10 
    def __init__(self,width,height,spotlight_radius= 10): 
     self.reso_width = width 
     self.reso_height = height 
     self.radius = spotlight_radius 

    def get_image_spotlight(self,set_points): #function for drawing spot light 
     image,draw = self.get_black_image() 
     for (x,y) in set_points: 
      draw.ellipse((x-self.radius,y-self.radius,x+self.radius,y+self.radius),fill = 'white') 
     image.show("titel") 
     return image 

    def get_black_image(self): #function for drawing black image 
     image = Image.new('RGBA',(self.reso_width,self.reso_height),"black")#(ImageHandler.reso_width,ImageHandler.reso_height),"black") 
     draw = ImageDraw.Draw((image)) 
     return image,draw 


hi = ImageHandler(1000,1000) 
a = [] 
hi.get_image_spotlight((a)) 
for i in range(0,100): 
    a = [(500,500)] 
    hi.get_image_spotlight((a)) 
    time.sleep(1000) 
+0

원하는 것을 얻기 위해 matlabplot을 사용할 수 있습니다. [Documentation] (https://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.scatter) –

답변

0

코드는 보인다. 현재 단일 지점을 포함하는 목록이 전달되고 있습니다. 이 같은 점은 검은 색 이미지에서 한 번 그려지기 때문에 한 지점 만 보게되며 항상 같은 위치에있게됩니다.

대신 하나 이상의 점을 포함하는 목록을 get_image_spotlight()으로 전달하십시오. 임의의 점 목록을 생성 한 다음 그릴 수 있습니다.

from random import randrange 

spot_count = 10 
points = [(randrange(1000), randrange(1000)) for _ in range(spot_count)] 
img = hi.get_image_spotlight(points) 

이렇게하면 검은 색 배경에 10 개의 흰색 반점이있는 이미지가 생성됩니다. 더 많거나 적은 수의 경우 spot_count을 변경하십시오.