Commit 970d6577 authored by Tomaš Vank's avatar Tomaš Vank
Browse files

Update Task3.py

parent ca450b2d
......@@ -5,11 +5,11 @@ from skimage.color import rgb2gray
from skimage.draw import circle_perimeter
import scipy.ndimage as ndi
from skimage.measure import regionprops,label
from termcolor import colored
def maximum_Filter(img):
threshold = np.max(img) / 1.5
img_max = ndi.maximum_filter1d(img, size=2, axis=0,mode='nearest')
img_max = ndi.maximum_filter1d(img_max, size=2, axis=1,mode='nearest')
img_max = ndi.maximum_filter(img, size=3, mode='nearest')
img_t = img > threshold
return img_t,img_max,threshold
......@@ -27,33 +27,23 @@ def hough_Peaks(hspaces, radii, total_num_peaks):
radius, cx, cy, acc = [], [], [], []
for rad, hough_peaks in zip(radii, hspaces):
img = hough_peaks.copy()
img_t, img_max, threshold = maximum_Filter(img)
img_t, img_max, threshold = maximum_Filter(img)# threshold + max pretnutie
img_peaks, y_peaks, x_peaks = [], [], []
label_img = label(img_t)
pointsWithMaxValues = regionprops(label_img, img_max)
pointsWithMaxValues = np.flipud(sorted(pointsWithMaxValues, key=lambda x: x.max_intensity)) # s najdenych max hodnot zo sortujeme od zaciatku
coords = np.array([np.round(p.centroid) for p in pointsWithMaxValues], dtype=int) # zo sortovanych bodov najdeme centroidi
pointsWithMaxValues = regionprops(label_img, img_max)#kde sa najviac pretlo max
pointsWithMaxValues = np.flipud(sorted(pointsWithMaxValues, key=lambda x: x.max_intensity)) # s najdenych max hodnot zo sortujeme od konca sa da na zaciatok od najvacsieho
coords = np.array([np.round(p.centroid) for p in pointsWithMaxValues], dtype=int)# zo sortovanych bodov najdeme centroidi
for y_idx, x_idx in coords:
accum = img_max[y_idx, x_idx] # bod koordinatov s odfiltrovaneho obrazka
if accum > threshold:
accum = img_max[y_idx, x_idx] # bod koordinatov s odfiltrovaneho obrazka kde je max hodnota
if accum > threshold: # ak max value prejde cez threshuold
img_peaks.append(accum)
y_peaks.append(y_idx)
x_peaks.append(x_idx)
img_peaks = np.array(img_peaks)
y_peaks = np.array(y_peaks)
x_peaks = np.array(x_peaks)
img_peaks, y_peaks, x_peaks = np.array(img_peaks), np.array(y_peaks), np.array(x_peaks)
radius[len(radius):] = (rad,) * len(img_peaks)
cx[len(cx):] = x_peaks
cy[len(cy):] = y_peaks
acc[len(acc):] = img_peaks
radius = np.array(radius)
cx = np.array(cx)
cy = np.array(cy)
acc = np.array(acc)
s = [x for x, y in sorted(enumerate(acc), key=lambda x: x[1])]
cx[len(cx):], cy[len(cy):], acc[len(acc):] = x_peaks, y_peaks, img_peaks
radius, cx, cy, acc = np.array(radius), np.array(cx), np.array(cy), np.array(acc)
s = [x for x, y in sorted(enumerate(acc), key=lambda x: x[1])]#zoradi acc na osi 1 + enumerate pridava indexy
cx_sorted, cy_sorted, r_sorted = np.flipud(cx[s]), np.flipud(cy[s]), np.flipud(radius[s])
return (cx_sorted[:total_num_peaks],cy_sorted[:total_num_peaks],r_sorted[:total_num_peaks])
......@@ -163,7 +153,7 @@ for idx in range(len(middle_coor_Big)):
x = cxBig[idx] + 8200
y = cyBig[idx] + 15800
if [cxBig[idx],cyBig[idx]] not in labeled:
print(str(number) + " " + str(x) + " / " + str(y) + " polomer= " + str(BigRadii[0]))
print(colored(str(number) + " " + str(x) + " / " + str(y) + " polomer= " + str(BigRadii[0]),"white"))
plt.text(cxBig[idx], cyBig[idx], str(number))
number = 1 + number
labeled.append([cxBig[idx], cyBig[idx]])
......@@ -182,7 +172,7 @@ for center_y, center_x,radius in zip(cy, cx, radii):
if point[0] > 0 and already_there and [center_x,center_y] not in labeled:
x = center_x + 8200
y = center_y + 15800
print(str(number) + " " + str(x) + " / " + str(y) + " polomer= " + str(radius))
print(colored(str(number) + " " + str(x) + " / " + str(y) + " polomer= " + str(radius),"green"))
plt.text(center_x, center_y, str(number))
number = 1 + number
labeled.append([center_x, center_y])
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment