-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcircle_detection.py
46 lines (39 loc) · 1.58 KB
/
circle_detection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# !/usr/bin/env python
# -*- coding: utf-8
#########################################################################################
#
# Trouver le centre du capillaire grace a la transformee de hough circulaire
# https://scikit-image.org/docs/stable/auto_examples/edges/plot_circular_elliptical_hough_transform.html
#
# ---------------------------------------------------------------------------------------
# Authors: groupe oct
#
#########################################################################################
import numpy as np
import matplotlib.pyplot as plt
from skimage.transform import hough_circle, hough_circle_peaks
from skimage.feature import canny
import nibabel as nib
# load image and find center b_scan
filename = "data_test_oct_0degree.nii"
image = nib.load(filename)
data = image.get_fdata()
x_tube = 260
b_scan = data[x_tube, :, :]
print("la detection de la frontiere circulaire peu prendre du temps...")
# Load picture and detect edges
edges = canny(b_scan, sigma=2, low_threshold=50, high_threshold=100)
plt.imshow(edges, cmap="gray", origin="lower")
plt.show()
# Detect one radii
hough_radii = np.arange(100, 140, 1)
hough_res = hough_circle(edges, hough_radii)
# Select the most prominent circle and detect center
accums, cx, cy, radii = hough_circle_peaks(hough_res, hough_radii,
total_num_peaks=1)
print("Centre du cercle sur l'axe x: {} et sur l'axe y: {}".format(cx, cy))
# Draw circle
plt.imshow(b_scan, cmap="gray", origin="lower")
circle1 = plt.Circle((cx, cy), radii, color='b', fill=False)
plt.gca().add_patch(circle1)
plt.show()