Skip to content

Commit fc68f53

Browse files
committed
Fix visualization tests due to a deprecated function in matplotlib
Signed-off-by: Samet Akcay <[email protected]>
1 parent bcc0b43 commit fc68f53

File tree

1 file changed

+3
-2
lines changed
  • src/anomalib/utils/visualization

1 file changed

+3
-2
lines changed

src/anomalib/utils/visualization/image.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,8 @@ def generate(self) -> np.ndarray:
326326
axis.title.set_text(image_dict["title"])
327327
self.figure.canvas.draw()
328328
# convert canvas to numpy array to prepare for visualization with opencv
329-
img = np.frombuffer(self.figure.canvas.tostring_rgb(), dtype=np.uint8)
330-
img = img.reshape(self.figure.canvas.get_width_height()[::-1] + (3,))
329+
img = np.frombuffer(self.figure.canvas.buffer_rgba(), dtype=np.uint8)
330+
img = img.reshape(self.figure.canvas.get_width_height()[::-1] + (4,)) # RGBA has 4 channels
331+
img = cv2.cvtColor(img, cv2.COLOR_RGBA2RGB)
331332
plt.close(self.figure)
332333
return img

0 commit comments

Comments
 (0)