I am developing a GUI using TKinter that allows users to interactively set parameters that are used for processing some images. The GUI displays the image that is being analyzed so that users can see how changing the parameters changes the result of the image processing. After realizing that the method I am using to process images does not perform well, I decided to create another GUI that I can use to debug the method. This debugging GUI will display two images – the original one being processed, and a binary mask that will be used to isolate features on the original. After developing this GUI, I noticed that when displaying the images, there is now a strange white box in the center of the image that was not there on the original one.
Here are examples to illustrate the issue:
original code for displaying image on a TK label:
def display_image(img):
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = Image.fromarray(img)
img = ImageTk.PhotoImage(image=img)
photo_label.imgtk = img
photo_label.config(image=img)
resulting image (cropped only to show area near the center where the issue is occurring):
how it should look
code for displaying image on the debugging GUI that allows for selecting whether I am showing an image on the original photo label or the label for the binary mask:
def display_image(img, window = "photo"):
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = Image.fromarray(img)
img = ImageTk.PhotoImage(image=img)
if window == "photo":
photo_label.imgtk = img
photo_label.config(image=img)
elif window == "mask":
mask_label.imgtk = img
mask_label.config(image=img)
resulting image with issue:
image with new white rectangle on the issue
Does anyone know why this may be happening and if there is anything that I can do to get rid of it?
mrfraud is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.