Example #1
0
 def test_select_dots_based_ratio(self):
     mat = np.zeros((64, 64), dtype=np.float32)
     mat[7:64:10, 7:64:10] = np.float32(1.0)
     mat[7, 7 + 1:64:10] = np.float32(1.0)
     mat[7, 7 + 2:64:10] = np.float32(1.0)
     mat[7, 7 - 1:64:10] = np.float32(1.0)
     mat[7, 7 - 2:64:10] = np.float32(1.0)
     mat = ndi.binary_dilation(mat, iterations=2)
     mat1 = prep.select_dots_based_ratio(mat, 0.05)
     num_dots2 = ndi.label(mat1)[-1]
     self.assertTrue(num_dots2 == (self.num_dots - self.rem_dot))
Example #2
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
Example #3
0
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
list_hor_lines = prep.remove_residual_dots_hor(list_hor_lines, hor_slope)
# Optional: remove vertical outliners
list_ver_lines = prep.remove_residual_dots_ver(list_ver_lines, ver_slope)
# Save output for checking
Example #4
0
# 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 +
# dot_size*ratio]
mat1 = prep.select_dots_based_size(mat1, dot_size, ratio=0.3)
io.save_image(output_base + "/cleaned_1_image.tif", mat1)

# Select dots with the ratio between the major axis and the minor axis (of a
# fitted ellipse) in the range of (1; 1 + ratio).
mat1 = prep.select_dots_based_ratio(mat1, ratio=0.5)
io.save_image(output_base + "/cleaned_2_image.tif", mat1)

# Calculate the horizontal slope and the vertical slope of the grid using the
# middle part of the image (30%).
hor_slope = prep.calc_hor_slope(mat1, ratio=0.3)
ver_slope = prep.calc_ver_slope(mat1, ratio=0.3)
print("Horizontal slope: {0}\nVertical slope: {1}".format(
    hor_slope, ver_slope))

# Group dots into lines. The method searches nearby dots and decide if they
# belong to the same line or not. The search-range in x-direction is
# defined by num_dot_miss and the search-range in y-direction is defined
# by the slope and the acceptable variation. Only lines with the number of
# dots >= 70% of the maximum number of dots on a line are kept.