Reputation: 82
I am trying to detect the large yellow and red circles (not the small ones at the bottom) using scikit. It seems to be very accurate for the red circles (after filtering for larger radii), but it can't seem to detect the yellow circles.
What I've tried, based on this. I am only interested in the array of x, y, and radius, so the code doesn't need the image with the circles overlaying.
I've tried the three methods in the scikit example, but found the doh (Determinant of Hessian) worked best for at least identifying the red circles, as the other 2 methods didn't work for them.
I've also tried using the scikit Hough circles from here, but the same problem exists where it doesn't detect the yellow circles.
from skimage import data, io
from skimage.feature import blob_doh
from skimage.color import rgb2gray
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
image = io.imread("2-9.jpg")
image_gray = rgb2gray(image)
blobs_doh = blob_doh(image_gray, max_sigma=30, threshold=.01)
df_doh = pd.DataFrame(blobs_doh[:, :], columns=["y", "x", "radius"])
df_doh.to_csv('doh.csv')
I then imported the data as a csv and plotted using R (to show accuracy)
df <- fread('doh.csv')
library(imager)
im <- load.image("2-9.jpg")
plot(im)
points(df$x, df$y)
df_filtered <- filter(df, radius >= 4.22) #radius of any less gives too many points
plot(im)
points(df_filtered$x, df_filtered$y)
Upvotes: 0
Views: 506
Reputation: 5738
Probably the yellow blobs are too lightly colored to be picked by blob_doh
. Since you appear to have strong prior knowledge with these images (exact yellow and exact red, based on my color picker), you can make an image with just the target points:
from skimage import io, util
image = util.img_as_float(io.imread("2-9.jpg"))
t = 0.001 # tolerance of deviation from exact color
blobs = ((image - [1, 0, 0])**2 < t) # distance from red less than t
| (image - [1, 1, 0])**2 < t)) # distance from yellow
blobs_float = blobs.astype(float) # convert from boolean to 1.0/0.0
Then, use blob_doh
on the blobs_float
image.
Hope this helps!
Upvotes: 1