While using PIL draw rectangles on an image in the canvas. I wish to change the fill rectangle depending on the pixel color of my image in the canvas.
I have referred one of the cross posts (link pasted below) to create rectangles with mouse events in Tkinter.
create_rectangle fills the rectangle with a color specified with mouse events (example: the rectangle is filled with black in this example). Is there a way to logically change the fill color depending on the existing pixel color of the background image? I mean, while drawing a rectangle, I need only the white colored pixels of the background image to be turning red and the rest with a different color.
Drawing rectangle using mouse events in Tkinter
[1]: https://i.stack.imgur.com/W41kX.jpg
def rec_on_button_press(self,event):
self.start_x = event.x
self.start_y = event.y
self.rect=self.image_canvas.create_rectangle(self.x, self.y, 1, 1,fill=self.python_red)
def rec_on_move(self, event):
curX, curY = (event.x, event.y)
imagenp= np.array(image)
if imagenp[curY,curX]==255:
self.python_red="#EE204D"
else:
self.python_red=None
self.image_canvas.coords(self.rect, self.start_x, self.start_y, curX, curY)
def rec_on_button_release(self, event):
pass