The completed code is shown below
import cv2
import numpy as np
#1)Load the image
loadedimage = cv2.imread('volumetricflask.png')
if loadedimage is None:
print("There is no image with the specified name")
else:
#2) Adjust the image size
escala = 0.5
new_width = int(loadedimage.shape[1] * escala)
new_height = int(loadedimage.shape[0] * escala)
new_size = (new_width, new_height)
resizedimage = cv2.resize(loadedimage, new_size)
#3) Black and white image
grayimage = cv2.cvtColor(resizedimage, cv2.COLOR_BGR2GRAY)
#4) White image
margen = 60
height, width = grayimage.shape
canvas_height = height + 2 * margen
canvas_width = width + 2 * margen
#5) Dotimage
dotimage = np.ones((canvas_height, canvas_width, 1), dtype=np.uint8) * 255
#6) Center of image
centro_x = canvas_width // 2
centro_y = canvas_height // 2
dotradius = 3
for y in range(0, height, 10):
for x in range(0, width, 10):
pixel_value = grayimage[y, x]
dotcolor = (0, 0, 0) if pixel_value < 100 else (255, 255, 255)
cv2.circle(dotimage, (x + margen, y + margen), dotradius, dotcolor, -1)
#7) Image axes
blackoutline = (0, 0, 0)
cv2.line(dotimage, (margen, canvas_height - margen), (canvas_width - margen, canvas_height - margen), blackoutline, 2)
cv2.line(dotimage, (margen, margen), (margen, canvas_height - margen), blackoutline, 2)
spacing = 50
font = cv2.FONT_HERSHEY_SIMPLEX
for x in range(margen, canvas_width - margen, spacing):
valor_x = x - centro_x
cv2.line(dotimage, (x, canvas_height - margen - 5), (x, canvas_height - margen), blackoutline, 1)
cv2.putText(dotimage, str(valor_x), (x - 10, canvas_height - margen + 20), font, 0.5, blackoutline, 1)
for y in range(margen, canvas_height - margen, spacing):
valor_y = centro_y - y
cv2.line(dotimage, (margen - 5, y), (margen, y), blackoutline, 1)
cv2.putText(dotimage, str(valor_y), (margen - 40, y + 5), font, 0.5, blackoutline, 1)
cv2.putText(dotimage, "0", (centro_x - 10, canvas_height - margen + 20), font, 0.6, blackoutline, 2) # Correcto en el eje X
cv2.putText(dotimage, "0", (margen - 25, centro_y + 5), font, 0.6, blackoutline, 2) # Correcto en el eje Y
borderthickness = 2
cv2.rectangle(dotimage, (margen, margen), (canvas_width - margen - 1, canvas_height - margen - 1), blackoutline, borderthickness)
#8) Save image
cv2.imwrite('Dotimagepaulromero.png', dotimage)
#9) Show image
cv2.imshow('Dotimage', dotimage)
cv2.waitKey(0)
cv2.destroyAllWindows()
The generated dot images are shown below
Volumetric Flask
.png)

Animated bacteria
import cv2
import numpy as np
#1)Load the image
loadedimage = cv2.imread('bacteria.png')
if loadedimage is None:
print("There is no image with the specified name")
else:
#2) Adjust the image size
escala = 0.5
new_width = int(loadedimage.shape[1] * escala)
new_height = int(loadedimage.shape[0] * escala)
new_size = (new_width, new_height)
resizedimage = cv2.resize(loadedimage, new_size)
#3) Black and white image
grayimage = cv2.cvtColor(resizedimage, cv2.COLOR_BGR2GRAY)
#4) White image
margen = 60
height, width = grayimage.shape
canvas_height = height + 2 * margen
canvas_width = width + 2 * margen
#5) Dotimage
dotimage = np.ones((canvas_height, canvas_width, 1), dtype=np.uint8) * 255
#6) Center of image
centro_x = canvas_width // 2
centro_y = canvas_height // 2
dotradius = 3
for y in range(0, height, 10):
for x in range(0, width, 10):
pixel_value = grayimage[y, x]
dotcolor = (0, 0, 0) if pixel_value < 130 else (255, 255, 255)
cv2.circle(dotimage, (x + margen, y + margen), dotradius, dotcolor, -1)
#7) Image axes
blackoutline = (0, 0, 0)
cv2.line(dotimage, (margen, canvas_height - margen), (canvas_width - margen, canvas_height - margen), blackoutline, 2)
cv2.line(dotimage, (margen, margen), (margen, canvas_height - margen), blackoutline, 2)
spacing = 50
font = cv2.FONT_HERSHEY_SIMPLEX
for x in range(margen, canvas_width - margen, spacing):
valor_x = x - centro_x
cv2.line(dotimage, (x, canvas_height - margen - 5), (x, canvas_height - margen), blackoutline, 1)
cv2.putText(dotimage, str(valor_x), (x - 10, canvas_height - margen + 20), font, 0.5, blackoutline, 1)
for y in range(margen, canvas_height - margen, spacing):
valor_y = centro_y - y
cv2.line(dotimage, (margen - 5, y), (margen, y), blackoutline, 1)
cv2.putText(dotimage, str(valor_y), (margen - 40, y + 5), font, 0.5, blackoutline, 1)
cv2.putText(dotimage, "0", (centro_x - 10, canvas_height - margen + 20), font, 0.6, blackoutline, 2) # Correcto en el eje X
cv2.putText(dotimage, "0", (margen - 25, centro_y + 5), font, 0.6, blackoutline, 2) # Correcto en el eje Y
borderthickness = 2
cv2.rectangle(dotimage, (margen, margen), (canvas_width - margen - 1, canvas_height - margen - 1), blackoutline, borderthickness)
#8) Save image
cv2.imwrite('Dotimagepaulromero.png', dotimage)
#9) Show image
cv2.imshow('Dotimage', dotimage)
cv2.waitKey(0)
cv2.destroyAllWindows()



When I executed a program called LabRobot in Python and adjusted the dot image, I got the following result
