import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)import cv2
import matplotlib.pyplot as plt
im1 = cv2.imread("/kaggle/input/blood-cells-image-dataset/bloodcells_dataset/lymphocyte/LY_10361.jpg")

im = im1.copy()

plt.imshow(im)
<matplotlib.image.AxesImage at 0x7e451e1c7730>
mask = cv2.inRange(im1, (0, 120, 0), (255, 255, 255))
plt.imshow(mask)
<matplotlib.image.AxesImage at 0x7e451c031840>
ed = cv2.Canny(im, 50, 50)
im2 = cv2.bitwise_and(ed, ed, mask=mask)
plt.imshow(im2)
<matplotlib.image.AxesImage at 0x7e451c0c80d0>
im = im1.copy()

contours, h = cv2.findContours(im2, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

a = 0
for c in contours:
    area = cv2.contourArea(c)
    if area > 35:
        a = a + 1
        cv2.drawContours(im, [c], -1, (100, 255, 100), 2)

print(a)
plt.imshow(im)
11
<matplotlib.image.AxesImage at 0x7e450c1fc8e0>
print(len(contours))
379
 

Остання зміна: неділя 16 лютого 2025 22:18 PM