Even more improved line detection

This commit is contained in:
Caesar2011
2019-03-17 22:25:25 +01:00
parent 59e73827cf
commit e96d833fe9
4 changed files with 20 additions and 15 deletions

View File

@@ -2,15 +2,11 @@ import numpy as np
from scipy.ndimage import measurements
from src.processing.imageprocessing import rgb2gray
from src.processing.loader import load_numpy, save_numpy, save_image, load_image
from src.utils.cmap_generator import rand_cmap, list_cmap
from matplotlib import pyplot as plt
from src.processing.loader import load_numpy, save_numpy, save_image
def find_lines(image):
gray, binary, magnitude = preparation(image)
plt.imshow(binary, cmap="gray")
plt.show()
backtrack = load_numpy("result/backtrack.npz")
if backtrack is None:
energy, backtrack = minimum_seam(binary, magnitude)
@@ -18,7 +14,8 @@ def find_lines(image):
save_image("result/gray.png", gray)
seams = calculate_seams(backtrack)
labeled, ncomponents = group_empty_boxes(seams)
return generate_lines(labeled, ncomponents, gray)
lines = generate_lines(labeled, ncomponents, gray)
return filter_lines(lines)
def preparation(image):
@@ -160,4 +157,15 @@ def generate_lines(labeled, ncomponents, gray):
else:
pixelgroup = np.concatenate((pixelgroup, pixel))
submit_entry()
return entries
return entries
def filter_lines(lines):
filtered = []
for line in lines:
cnt, vals = np.histogram(line, 256)
threshold = get_threshold(cnt)/256*1.13#*0.96
binary = (line > threshold).astype(np.int_)
labeled, ncomponents = group_empty_boxes(binary)
if ncomponents > 2:
filtered.append(line)
return filtered

View File

@@ -2,7 +2,6 @@ from collections import defaultdict
from skimage.transform import resize
from scipy.ndimage import gaussian_filter
from matplotlib import pyplot as plt
from src.processing.imageprocessing import rgb2gray_value
from scipy import signal
@@ -162,8 +161,8 @@ def draw_hough_lines(image, scale, results, references, shape, theta_res=5, widt
y = int(n - x * m)
if 0 < y < image.shape[0]:
draw_image[max(0, y - GREEN_WIDTH):y + GREEN_WIDTH, max(0, x - GREEN_WIDTH):x + GREEN_WIDTH] = np.array([255, 0, 0])
plt.imshow(draw_image)
plt.show()
#plt.imshow(draw_image)
#plt.show()
def convert_to_lines(scale, results, references, shape, theta_res=5, width_res=5):
@@ -343,8 +342,8 @@ def draw_rectangle(image, corners):
x = int(a[1] + (b[1] - a[1]) * i / 5000)
y = int(a[0] + (b[0] - a[0]) * i / 5000)
draw_image[max(0, y - 15):y + 10, max(0, x - 10):x + 10] = np.array([255, 0, 0])
plt.imshow(draw_image)
plt.show()
#plt.imshow(draw_image)
#plt.show()
def crop_image(image, corners):

View File

@@ -2,7 +2,7 @@ from matplotlib.colors import LinearSegmentedColormap
import colorsys
import numpy as np
def rand_cmap(nlabels, type='bright', first_color_black=True, last_color_black=False, verbose=True):
def rand_cmap(nlabels, type='bright', first_color_black=True, last_color_black=False, verbose=False):
"""
Creates a random colormap to be used together with matplotlib. Useful for segmentation tasks
:param nlabels: Number of labels (size of colormap)