示例#1
0
def ht_road():
    list_of_images = [
        os.path.join(image_folder, i) for i in os.listdir(image_folder)
    ]
    for i in list_of_images:
        print(i)
        img = cv2.imread(i)
        print(img)
        img = np.array(img, dtype=np.uint8)
        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        edges = cv2.Canny(gray, 50, 150, apertureSize=3)
        new_img = hough.hough_transform(img, edges)
        new_path = os.path.join(hough_folder, 'h' + os.path.basename(i))
        cv2.imwrite(new_path, new_img)
示例#2
0
# print d.shape
I = d['I'].reshape(1024, 1024)
I = I.T[:, ::-1]  # first time, then freq, both ascending
print I.shape

t = 2.219968e3 / 1024 * np.arange(1024)  # ms
f = np.genfromtxt(indir + 'freq.txt', dtype='f4', delimiter=',')
print f.shape, f[0], f[-1]
f = f[::-1]  # make ascending
f *= 1.0e-3  # GHz

A, dl, dh, t0l, t0h = hough.hough_transform(I,
                                            t,
                                            f,
                                            dl,
                                            dh,
                                            nd=ND,
                                            nt0=NC,
                                            threshold=threshold,
                                            comm=mpiutil._comm)
# A, dl, dh, t0l, t0h = hough.hough_transform(I, t, f, dl, dh, threshold=3.0, comm=mpiutil._comm)

if mpiutil.rank0:
    print A.shape
    # save data
    if not os.path.exists(outdir):
        os.makedirs(outdir)

    with h5py.File(outdir + 'A.hdf5', 'w') as f:
        f.create_dataset('A', data=A)
        f.attrs['axes'] = '(offset, DM)'
示例#3
0
        I[ti, fi] += np.random.normal(loc=mu_s, scale=sigma_s)

    # # plot I
    # plt.figure()
    # plt.imshow(I.T, origin='lower', aspect='auto', extent=(tl, th, f[0], f[-1]), cmap='gray')
    # plt.xlabel('Time [ms]')
    # plt.ylabel('Frequency [GHz]')
    # # plt.colorbar()
    # plt.savefig(outdir+'I_%.1f.png' % sigma_n)
    # plt.close()

    A, dl, dh, Cl, Ch = hough.hough_transform(I,
                                              time,
                                              freq,
                                              dl,
                                              dh,
                                              nd=ND,
                                              nt0=NC,
                                              threshold=threshold,
                                              comm=mpiutil._comm)

    dD = (Dh - Dl) / ND
    dC = (Ch - Cl) / NC

    # peak finding
    p = np.argmax(A)
    Cp = p / ND
    Dp = p % ND
    print 'peak at: (DM, offset) = (%g, %g), with value %g' % (
        Dl + Dp * dD, Cl + Cp * dC, A.flatten()[p])
    # compute peak-to-median ratio (PMR)
示例#4
0
from simulator.evaluator import Evaluator

""" setup evaluator """
evaluator = Evaluator("hough", detected_walls="N/A")

""" generate points """
points = generate_points(evaluator.sigma)

""" non-generated points """
# sys.path.append('../..')
# from simulator.points_dataset_real2 import points
# from outlierfilter import outlierfilterlib
# points = outlierfilterlib.filter_outliers(points)

""" hough transform """
rhos, thetas, hgrid = hough.hough_transform(points, n_theta=460, n_rho=360)
# print "  hough transform complete"

""" get lines from hough transform (matlab) """
MATLAB_HOUGH_FILE = "matlab_io/input_hough.mat"
MATLAB_PEAKS_FILE = "matlab_io/output_peaks.mat"
# check if matlab can be skipped
skip_matlab = False
if os.path.isfile(MATLAB_HOUGH_FILE):
    data = loadmat(MATLAB_HOUGH_FILE)
    if data["H"].shape == hgrid.T.shape and (data["H"] == hgrid.T).all():
        skip_matlab = True
# if not skip_matlab:
if True:
    # create input file
    savemat(MATLAB_HOUGH_FILE, {"H": hgrid.T})
示例#5
0
sys.path.append('..')
from simulator.plotter import *
from simulator.points_generator import *
import hough
from simulator.evaluator import Evaluator
""" setup evaluator """
evaluator = Evaluator("hough", detected_walls="N/A")
""" generate points """
points = generate_points(evaluator.sigma)
""" non-generated points """
#sys.path.append('../..')
#from simulator.points_dataset_real2 import points
#from outlierfilter import outlierfilterlib
#points = outlierfilterlib.filter_outliers(points)
""" hough transform """
rhos, thetas, hgrid = hough.hough_transform(points, n_theta=460, n_rho=360)
#print "  hough transform complete"
""" get lines from hough transform (matlab) """
MATLAB_HOUGH_FILE = 'matlab_io/input_hough.mat'
MATLAB_PEAKS_FILE = 'matlab_io/output_peaks.mat'
# check if matlab can be skipped
skip_matlab = False
if os.path.isfile(MATLAB_HOUGH_FILE):
    data = loadmat(MATLAB_HOUGH_FILE)
    if data['H'].shape == hgrid.T.shape and (data['H'] == hgrid.T).all():
        skip_matlab = True
#if not skip_matlab:
if True:
    # create input file
    savemat(MATLAB_HOUGH_FILE, {'H': hgrid.T})
    # run script