Example #1
0
def task_sobel(original_path, result_path1, result_path2, result_path3):
    pix_array = utils.picture_to_array(IMAGES_RESOURCE + original_path)
    pix_result1 = sobel.sobelOperator(pix_array)[0]
    pix_result2 = sobel.sobelOperator(pix_array)[1]
    pix_result3 = sobel.sobelOperator(pix_array)[2]
    utils.array_to_picture(pix_result1, IMAGES_RESULT + result_path1)
    utils.array_to_picture(pix_result2, IMAGES_RESULT + result_path2)
    utils.array_to_picture(pix_result3, IMAGES_RESULT + result_path3)
Example #2
0
def texture(sample_path, result_path):
    pix = u.picture_to_array(IMAGES_RESOURCE + sample_path)
    pix_semitone = semitone.semitone(pix)
    u.array_to_picture(pix_semitone,
                       IMAGES_RESULT + result_path + "semitone.png")

    co_occurrence_matrix = t.get_co_occurrence_matrix(pix_semitone)
    spread_image = t.norm_matrix(co_occurrence_matrix)

    dis_i = t.dispersion(spread_image, 0)
    dis_j = t.dispersion(spread_image, 1)
    save_to_txt(dis_i, dis_j, IMAGES_RESULT + result_path + "features.txt")

    u.array_to_picture(spread_image,
                       IMAGES_RESULT + result_path + "visualized.png")
Example #3
0
def task_smoothing(original_path, result_path, xor_path):
    pix_array = utils.picture_to_array(IMAGES_RESOURCE + original_path)
    pix_smoothing = smoothing.conservative_smoothing_gray(pix_array, 2)
    utils.array_to_picture(pix_smoothing, IMAGES_RESULT + result_path)
    pix_xor = smoothing.xor(pix_array, pix_smoothing)
    utils.array_to_picture(pix_xor, IMAGES_RESULT + xor_path)
Example #4
0
SAMPLES_PATH = "media/samples/text/"
RESULTS_PATH = "media/results/task6"
SAMPLE_TEXT = "ШИРОКАЯ ЭЛЕКТРИФИКАЦИЯ ЮЖНЫХ ОБЛАСТЕЙ ДАСТ МОЩНЫЙ ТОЛЧОК ПОДЪЁМУ СЕЛЬСКОГО ХОЗЯЙСТВА"
SAMPLE_TEXT_NO_SPACE = "ШИРОКАЯЭЛЕКТРИФИКАЦИЯЮЖНЫХОБЛАСТЕЙДАСТМОЩНЫЙТОЛЧОКПОДЪЁМУСЕЛЬСКОГОХОЗЯЙСТВА"
SAMPLE_FONT = "fonts/arial_italic.ttf"

tg.create_image_sample_text(SAMPLE_TEXT, SAMPLE_FONT,
                            52).save(SAMPLES_PATH + "/sample_52.bmp")
tg.create_image_sample_text(SAMPLE_TEXT, SAMPLE_FONT,
                            40).save(SAMPLES_PATH + "/sample_40.bmp")
tg.create_image_sample_text(SAMPLE_TEXT, SAMPLE_FONT,
                            60).save(SAMPLES_PATH + "/sample_60.bmp")

img_52 = get_normalized_image(
    u.picture_to_array(SAMPLES_PATH + "sample_52.bmp"))
img_40 = get_normalized_image(
    u.picture_to_array(SAMPLES_PATH + "sample_40.bmp"))
img_70 = get_normalized_image(
    u.picture_to_array(SAMPLES_PATH + "sample_60.bmp"))

model_dict = load_model('dictionary/sign_table.csv')

hypothesis_52 = s.get_pix_hypothesis(img_52, model_dict)
hypothesis_40 = s.get_pix_hypothesis(img_40, model_dict)
hypothesis_70 = s.get_pix_hypothesis(img_70, model_dict)

save_hypothesis(hypothesis_52, RESULTS_PATH + '/size_52/hypothesis.csv')
save_hypothesis(hypothesis_40, RESULTS_PATH + '/size_40/hypothesis.csv')
save_hypothesis(hypothesis_70, RESULTS_PATH + '/size_60/hypothesis.csv')
Example #5
0
  #      subpix = _img[y0:y1, x0:x1]
   #     name = "[%.0f, %.0f, %.0f, %.0f]" % (x0, y0, x1, y1)
    #    _prof_x = fa.calc_image_profile(subpix, 1, 0)[::-1]
     #   _prof_y = fa.calc_image_profile(subpix, 0, 1)
      #  fa.visualize_profile(_prof_x, "horizontal", RESULTS_PATH + path + "/char_profiles/horizontal/" + name + ".png")
       # fa.visualize_profile(_prof_y, "vertical", RESULTS_PATH + path + "/char_profiles/vertical/" + name + ".png")


def get_normalized_image(pix):
    img_grayscale = binary.apply_threshold(semitone.semitone(pix), 128, 1)
    return utils.pix_invert(img_grayscale, 0)


# 1. Подготовить текст из одной строки, пользуясь выбранным алфавитом и теми же параметрами шрифта
tg.generate_img_from_text("ШИРОКАЯ ЭЛЕКТРИФИКАЦИЯ ЮЖНЫХ ГУБЕРНИЙ ДАСТ МОЩНЫЙ ТОЛЧОК ПОДЪЁМУ СЕЛЬСКОГО ХОЗЯЙСТВА", "fonts/arial_italic.ttf", 52)
img_1 = get_normalized_image(utils.picture_to_array(SAMPLES_PATH + "text3.png"))

# 2. Реализовать алгоритм расчёта горизонтального и вертикального профиля изображения
# Профили X и Y
prof_x = s.calc_image_profile(img_1, 1, 0)[::-1]
prof_y = s.calc_image_profile(img_1, 0, 1)
# сохраняем графики профилей в картинках
s.horizontal_profile(prof_x, RESULTS_PATH + "1/line_profiles/horizontal.png")
s.vertical_profile(prof_y, RESULTS_PATH + "1/line_profiles/vertical.png", (25, 5))

# 3. Реализовать алгоритм сегментации символов в строке на основе профилей с прореживанием
#rects_img_1 = s.get_polygon(img_1)
#s.draw_polygons(SAMPLES_PATH + "text3.png", RESULTS_PATH + "/1/bounds.png", rects_img_1)

#for i in range(0, len(poly_img_1)):
   # norm = s.polygon_to_matrix(poly_img_1[i], img_1) * 255
Example #6
0
def task_threshold(sample_path, result_path):
    pix_array = utils.picture_to_array(IMAGES_RESOURCE + sample_path)
    semitone_arr = semitone.semitone(pix_array)
    threshold = binarization.bernsen_threshold(semitone_arr)
    pix_threshold = binarization.apply_threshold(semitone_arr, threshold)
    utils.array_to_picture(pix_threshold, IMAGES_RESULT + result_path)
Example #7
0
def task_semitone(original_path, result_path):
    pix_array = utils.picture_to_array(IMAGES_RESOURCE + original_path)
    pix_semitone = semitone.semitone(pix_array)
    utils.array_to_picture(pix_semitone, IMAGES_RESULT + result_path)
Example #8
0
def task_oversample_once(original_path, result_path, ratio):
    pix_array = utils.picture_to_array(IMAGES_RESOURCE + original_path)
    pix_once = oversampling.once(pix_array, ratio)
    utils.array_to_picture(pix_once, IMAGES_RESULT + result_path)
Example #9
0
def task_decimation(original_path, result_path, m):
    pix_array = utils.picture_to_array(IMAGES_RESOURCE + original_path)
    pix_decimated = oversampling.decimation(pix_array, m)
    utils.array_to_picture(pix_decimated, IMAGES_RESULT + result_path)
Example #10
0
def task_interpolation(original_path, result_path, n):
    pix_array = utils.picture_to_array(IMAGES_RESOURCE + original_path)
    pix_interpolated = oversampling.interpolation(pix_array, n)
    utils.array_to_picture(pix_interpolated, IMAGES_RESULT + result_path)