Find Circular circles in an image -
i have image.i want detect 4 holes have marked red line.
i have images in link below. https://www.dropbox.com/sh/mlrm51qx8s1mcw0/aabu_dlm8rbvpo60h4cj7i3ka?dl=0
inputimage(input_image.bmp)
preprocessed image(preprocessedimage.bmp)
working image(holes detected) (detectedholes.bmp)
nonworking image(only 3 holes detected)(nonworking.bmp)
initially, preprocessing on input image input image :input_image.bmp
hcontadj=vision.contrastadjuster; extracted_rim_contrast_adj=step(hcontadj,extracted_rim); j = adapthisteq(extracted_rim); sharp_img=imsharpen(j); se=strel('disk',300); imtop_op=imtophat(sharp_img,se); hgamma = ... vision.gammacorrector(90.0,'correction','de-gamma'); % hgamma = ... % vision.gammacorrector(12.0,'correction','gamma'); y = step(hgamma, imtop_op); h1 = imfilter(y,fspecial('gaussian',60,5)); h2=h1.*6.0; se = strel('disk',14); % perform morphological close operation on image. closebw = imclose(h2,se); figure, imshow(closebw);
the output image obtained after above processing preprocessedimage.bmp
imfindcircles() , viscircles() used find [centre,raddi] , mark circles blue color respectively.
[centers, radii] = imfindcircles(new_open_img,[32 100],'sensitivity',0.81,'objectpolarity','dark'); [h,x,y]=viscircles(centers, radii,'edgecolor','b');
the output image obtained after above 2 functions imfindcircles() , viscircles() detectedholes.bmp
the non working image in 3 holes detected nonworking.bmp.in case 4 circles not detected properly.
i fine tuned sensitivity , radius in imfindcircles()
,but still not able detect circles.
it grateful if give me idea tackle issue.
thanks
i assume using matlab, unfortunately not have matlab installed here, can give answer in python should translate straight matlab.
i think going in direction using hough transform circles (imfindcircles
). crucial set radius range correct. if expect images process similar. if images uploaded representative, radius should between 10 , 15 (maybe generous, circles want detect around 25px wide).
also rather preprocessing image morphological operations, use edge detector. tried canny edge detector bw1 = edge(i,'canny');
. if this, detect circle in middle well, can remove in post processing step. have check circle neither furthest or down, nor furthest left or right.
the python/skimage based code (slightly changed example code: http://scikit-image.org/docs/dev/auto_examples/plot_circular_elliptical_hough_transform.html ):
import numpy np import matplotlib.pyplot plt skimage import data, color skimage.transform import hough_circle skimage.feature import peak_local_max, canny skimage.draw import circle_perimeter skimage.util import img_as_ubyte skimage.io import imread # load picture , detect edges image = imread('test.jpeg')[..., 0] edges = canny(image, sigma=3, low_threshold=10, high_threshold=50) fig, ax = plt.subplots(ncols=1, nrows=1, figsize=(20, 10)) # detect 2 radii hough_radii = np.arange(13, 15, 2) hough_res = hough_circle(edges, hough_radii) centers = [] accums = [] radii = [] radius, h in zip(hough_radii, hough_res): # each radius, extract 5 circles num_peaks = 5 peaks = peak_local_max(h, num_peaks=num_peaks) centers.extend(peaks) accums.extend(h[peaks[:, 0], peaks[:, 1]]) radii.extend([radius] * num_peaks) # draw prominent 5 circles image = color.gray2rgb(image) idx in np.argsort(accums)[::-1][:]: center_x, center_y = centers[idx] radius = radii[idx] cx, cy = circle_perimeter(center_y, center_x, radius) image[cy, cx] = (220, 20, 20) ax.imshow(image, cmap=plt.cm.gray)
notebook (with result) here: https://gist.github.com/groakat/0e04d10a08fc05bff7e1
in matlab should like
i = imread('test.jpeg'); bw1 = edge(i,'canny'); [centers, radii, metric] = imfindcircles(bw1,[10 15]); centersstrong5 = centers(1:5,:); radiistrong5 = radii(1:5); metricstrong5 = metric(1:5); imshow(i) viscircles(centersstrong5, radiistrong5,'edgecolor','b');
Comments
Post a Comment