Reputation: 85
I wrote a python code to transform a color image into a gray image and then apply a threshold to calculate after contours of each big white circles. the objectif are the big circles.
As you see I can filter the image but I dont know how to erase the little points or circles in the image. Each big circle has around more than 250pixels.
I was thinking 2 things:
Write a python code to eliminate all of objects (white points) below 250pixels area. I dont know how to do that.
apply a black mask on those little white points. But still I dont know how to do that
Anyone of you has another suggestion that can help me to finish the code?
Thanks!!
import os
#from skimage import measure, io, img_as_ubyte
from skimage.color import label2rgb, rgb2gray
from skimage.segmentation import clear_border
import matplotlib.pyplot as plt
import numpy as np
import cv2
import pandas as pd
import sys
import glob
original = cv2.imread('D:/2022/Python program/NBC_new2022_/images/image1.jpg',-1)
original = cv2.resize(original, (864, 648)) #resize of original image
img = cv2.cvtColor(original, cv2.COLOR_BGR2GRAY)
median = cv2.medianBlur(img, 3)
ret, th = cv2.threshold(median, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)
kernel = np.ones((5,5), np.uint8)
opening = cv2.morphologyEx(th, cv2.MORPH_OPEN, kernel)
edge_touching_removed = clear_border(opening)
contours, hierarchy = cv2.findContours(edge_touching_removed, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cv2.imshow('original', original)
cv2.imshow("Theshrold image", edge_touching_removed)
cv2.waitKey(0)
cv2.destroyAllWindows()
Upvotes: 0
Views: 626