示例#1
0
def calc_distor_coef(mat, num_coef, perspective=False):
    # Pre-processing
    mat1 = prep.binarization(mat)
    (dot_size, dot_dist) = prep.calc_size_distance(mat1)
    mat1 = prep.select_dots_based_size(mat1, dot_size)
    mat1 = prep.select_dots_based_ratio(mat1)
    hor_slope = prep.calc_hor_slope(mat1)
    ver_slope = prep.calc_ver_slope(mat1)
    list_hor_lines = prep.group_dots_hor_lines(mat1, hor_slope, dot_dist)
    list_ver_lines = prep.group_dots_ver_lines(mat1, ver_slope, dot_dist)
    list_hor_lines = prep.remove_residual_dots_hor(list_hor_lines, hor_slope)
    list_ver_lines = prep.remove_residual_dots_ver(list_ver_lines, ver_slope)
    if perspective is True:
        try:
            list_hor_lines, list_ver_lines = proc.regenerate_grid_points_parabola(
                list_hor_lines, list_ver_lines, perspective=perspective)
        except AttributeError:
            raise ValueError("Perspective correction only available "
                             "from Discorpy 1.4!!!")
    # Processing
    (xcenter, ycenter) = proc.find_cod_coarse(list_hor_lines, list_ver_lines)
    list_fact = proc.calc_coef_backward(list_hor_lines, list_ver_lines,
                                        xcenter, ycenter, num_coef)
    return xcenter, ycenter, list_fact
示例#2
0
文件: demo_01.py 项目: gbzan/vounwarp
import numpy as np
import discorpy.losa.loadersaver as io
import discorpy.prep.preprocessing as prep
import discorpy.proc.processing as proc
import discorpy.post.postprocessing as post

# Initial parameters
file_path = "C:/data/dot_pattern_01.jpg"
output_base = "./output_demo_01/"
num_coef = 5  # Number of polynomial coefficients
mat0 = io.load_image(file_path) # Load image
(height, width) = mat0.shape
# Segment dots
mat1 = prep.binarization(mat0)
# Calculate the median dot size and distance between them.
(dot_size, dot_dist) = prep.calc_size_distance(mat1)
# Remove non-dot objects
mat1 = prep.select_dots_based_size(mat1, dot_size)
# Remove non-elliptical objects
mat1 = prep.select_dots_based_ratio(mat1)
io.save_image(output_base + "/segmented_dots.jpg", mat1)
# Calculate the slopes of horizontal lines and vertical lines.
hor_slope = prep.calc_hor_slope(mat1)
ver_slope = prep.calc_ver_slope(mat1)
print("Horizontal slope: {0}. Vertical slope: {1}".format(hor_slope, ver_slope))

# Group points to horizontal lines
list_hor_lines = prep.group_dots_hor_lines(mat1, hor_slope, dot_dist)
# Group points to vertical lines
list_ver_lines = prep.group_dots_ver_lines(mat1, ver_slope, dot_dist)
# Optional: remove horizontal outliners
示例#3
0
mat0 = io.load_image(file_path)
(height, width) = mat0.shape

# Optional step: correct non-uniform background for global thresholding method.
# Background is generated by applying a strong low-pass filter to the image.
# Then, the image is normalized with the background.
if norm is True:
    mat1 = prep.normalization_fft(mat0, sigma=5, pad=30)
else:
    mat1 = np.copy(mat0)

# Binarization using Otsu's method if thres = None
# Cropped image (30% of the size around the middle) is used for calculating
# the threshold. This is to avoid a case which a dot-pattern doesn't
# cover the whole field of view of a camera.
mat1 = prep.binarization(mat1, ratio=0.3, thres=None)
check = prep.check_num_dots(mat1)
if check:
    raise ValueError(
        "Number of objects detected is not enough !!! Parameters of"
        " the binarization method need to be adjusted!!!")
io.save_image(output_base + "/binarized_image.tif", mat1)

# Calculate the median dot size and the median distance of two nearest dots
# using the middle part of the image (30%). This is based on an assumption
# that there's no distortion around the middle part of the image.
(dot_size, dot_dist) = prep.calc_size_distance(mat1, ratio=0.3)
print("Median size of dots: {0}\nMedian distance between two dots: {1}".format(
    dot_size, dot_dist))

# Select dots with size in the range of [dot_size - dot_size*ratio; dot_size +
示例#4
0
 def test_check_num_dots(self):
     bck = 0.5 * np.random.rand(self.hei, self.wid)
     mat_bin = prep.binarization(self.mat_dots + bck, denoise=False)
     check = prep.check_num_dots(mat_bin)
     self.assertTrue(not check)
示例#5
0
 def test_binarization(self):
     bck = 0.5 * np.random.rand(self.hei, self.wid)
     mat_bin = prep.binarization(self.mat_dots + bck, denoise=False)
     num_dots2 = ndi.label(mat_bin)[-1]
     self.assertTrue(self.num_dots == num_dots2)
示例#6
0
文件: demo_05.py 项目: gbzan/vounwarp
import discorpy.prep.preprocessing as prep
import discorpy.proc.processing as proc
import discorpy.post.postprocessing as post

# Initial parameters
file_path = "C:/data/dot_pattern_06.jpg"
output_base = "./for_demo_05/"
num_coef = 4  # Number of polynomial coefficients
mat0 = io.load_image(file_path)  # Load image
(height, width) = mat0.shape

# Normalize background
mat1 = prep.normalization_fft(mat0, sigma=20)
# Segment dots
threshold = prep.calculate_threshold(mat1, bgr="bright", snr=1.5)
mat1 = prep.binarization(mat1, thres=threshold)
io.save_image(output_base + "/segmented_dots.jpg", mat1)

# Calculate the median dot size and distance between them.
(dot_size, dot_dist) = prep.calc_size_distance(mat1)
# Calculate the slopes of horizontal lines and vertical lines.
hor_slope = prep.calc_hor_slope(mat1)
ver_slope = prep.calc_ver_slope(mat1)
print("Horizontal slope: {0}. Vertical slope: {1}".format(
    hor_slope, ver_slope))

# Group dots into lines.
list_hor_lines0 = prep.group_dots_hor_lines(mat1,
                                            hor_slope,
                                            dot_dist,
                                            ratio=0.3,
示例#7
0
文件: demo_03.py 项目: gbzan/vounwarp
import discorpy.post.postprocessing as post

# Initial parameters
file_path = "C:/data/dot_pattern_04.jpg"
output_base = "./output_demo_03/"
num_coef = 5  # Number of polynomial coefficients
mat0 = io.load_image(file_path)  # Load image
(height, width) = mat0.shape

# Correct non-uniform background.
mat1 = prep.normalization_fft(mat0, sigma=20)
io.save_image(output_base + "/image_normed.tif", mat1)

# Segment dots.
threshold = prep.calculate_threshold(mat1, bgr="bright", snr=3.0)
mat1 = prep.binarization(mat1, ratio=0.5, thres=threshold)
io.save_image(output_base + "/image_binarized.tif", mat1)

# Calculate the median dot size and distance between them.
(dot_size, dot_dist) = prep.calc_size_distance(mat1)
# Remove non-dot objects
mat1 = prep.select_dots_based_size(mat1, dot_size, ratio=0.8)
# Remove non-elliptical objects
mat1 = prep.select_dots_based_ratio(mat1, ratio=0.8)
io.save_image(output_base + "/image_cleaned.tif", mat1)

# Calculate the slopes of horizontal lines and vertical lines.
hor_slope = prep.calc_hor_slope(mat1)
ver_slope = prep.calc_ver_slope(mat1)
print("Horizontal slope: {0}. Vertical slope: {1}".format(hor_slope, ver_slope))