def generate_report():
    report = MdUtils(file_name=f'./report.md')
    report.new_header(level=1, title='Текстурный анализ')
    report.new_line(text='Выполнил Ахманов Алексей Б18-514')

    for im in IMAGES:
        image_path = f'{helpers.folder_helper.IMAGES_FOLDER_PATH}/{im}'

        processed_image_folder_path = f'{image_path}_processed'
        os.makedirs(processed_image_folder_path, exist_ok=True)

        series_length_matrix_image_path = f'{processed_image_folder_path}/{im}_series_length_matrix.png'

        image = Image.open(image_path).convert(constants.constants.RGB_MODE)
        grayscaled = grayscale.grayscale.mean_grayscale(image)

        # Series length matrix
        draw.draw.draw_series_length_matrix(grayscale.grayscale.mean_grayscale(image)).save(series_length_matrix_image_path)

        # SRE
        sre = texturing.texturing.sre_coefficient(grayscaled)

        # Report
        report.new_header(level=2, title=f'{im} (SRE = {sre})')

        report.new_header(level=3, title='Исходная картинка')
        report.new_line(report.new_inline_image(text='Исходная картинка', path=image_path))

        report.new_header(level=3, title='Матрица длин серий')
        report.new_line(report.new_inline_image(text='Матрица длин серий', path=series_length_matrix_image_path))

    report.create_md_file()
Exemple #2
0
def generate_report():
    report = MdUtils(file_name=f'./report.md')
    report.new_header(level=1, title='Контрастирование')
    report.new_line(text='Выполнил Ахманов Алексей Б18-514')

    for im in IMAGES:
        image_path = f'{helpers.folder_helper.IMAGES_FOLDER_PATH}/{im}'

        processed_image_folder_path = f'{image_path}_processed'
        os.makedirs(processed_image_folder_path, exist_ok=True)

        grayscaled_image_path = f'{processed_image_folder_path}/{im}_grayscaled.png'
        linear_contrasted_image_path = f'{processed_image_folder_path}/{im}_linear_contrasted.png'
        power_transformed_image_path = f'{processed_image_folder_path}/{im}_power_transformed_gamma=#.png'

        image = Image.open(fp=image_path).convert(constants.RGB_MODE)
        grayscaled = grayscale.mean_grayscale(image)

        grayscaled.save(grayscaled_image_path)

        # Contrasting
        enhancement.contrasting.linear_contrasting(grayscaled).save(
            linear_contrasted_image_path)
        for gamma in numpy.arange(START_GAMMA, STOP_GAMMA, STEP_GAMMA):
            gamma = round(gamma, GAMMA_ROUND_SIGNS)
            enhancement.contrasting.power_transformation(grayscaled, gamma=gamma)\
                .save(power_transformed_image_path.replace('#', str(gamma)))

        # Report
        report.new_header(level=2, title=f'{im}')

        report.new_header(level=3, title='Исходная картинка')
        report.new_line(
            report.new_inline_image(text='Исходная картинка', path=image_path))

        report.new_header(level=3, title='Оттенки серого')
        report.new_line(
            report.new_inline_image(text='Оттенки серого',
                                    path=grayscaled_image_path))

        report.new_header(level=3, title='Линейное контрастирование')
        report.new_line(
            report.new_inline_image(text='Линейное контрастирование',
                                    path=linear_contrasted_image_path))

        report.new_header(level=3, title='Степенное преобразование')
        for gamma in numpy.arange(START_GAMMA, STOP_GAMMA, STEP_GAMMA):
            gamma = round(gamma, GAMMA_ROUND_SIGNS)
            report.new_header(level=4, title=f'Gamma = {gamma}')
            report.new_line(
                report.new_inline_image(
                    text='Степенное преобразование',
                    path=power_transformed_image_path.replace('#',
                                                              str(gamma))))

    report.create_md_file()
def generate_report():
    report = MdUtils(file_name=f'./report.md')
    report.new_header(level=1, title='Сегментация текста')
    report.new_line(text='Выполнил Ахманов Алексей Б18-514')
    report.new_line(text=f'Алфавит - {ALPHABET}')
    report.new_line(text=f'Исходная фраза - {PHRASE}')

    # Phrase
    phrase_image_path = f'{folder_helper.IMAGES_FOLDER_PATH}/phrase.png'
    phrase_projections_image_path = f'{folder_helper.IMAGES_FOLDER_PATH}/phrase_projections.png'
    phrase_segments_image_path = f'{folder_helper.IMAGES_FOLDER_PATH}/phrase_segments.png'
    phrase_result_image_path = f'{folder_helper.IMAGES_FOLDER_PATH}/phrase_result.png'

    phrase_image = Image.new(mode=GRAYSCALE_MODE,
                             size=(1200, FONT_SIZE),
                             color=WHITE)
    result = ImageDraw.Draw(im=phrase_image, mode=GRAYSCALE_MODE)
    result.text(xy=(0, 0), text=PHRASE, font=FONT, fill=0, anchor='lt')
    phrase_image = cut_empty_rows_and_cols(phrase_image)
    phrase_image.save(phrase_image_path)

    phrase_projections_image = draw.draw_projections(phrase_image)
    phrase_projections_image.save(phrase_projections_image_path)

    phrase_segments_image = draw.draw_symbol_segments(phrase_image,
                                                      SYMBOLS_DIFF_THRESHOLD)
    phrase_segments_image.save(phrase_segments_image_path)

    phrase_result_image = phrase_projections_image.copy()
    phrase_result_image.paste(im=phrase_segments_image, box=(30, 0))
    phrase_result_image.save(phrase_result_image_path)

    # Report
    report.new_header(level=2, title='Картинка с фразой')
    report.new_line(
        report.new_inline_image(text='Картинка с фразой',
                                path=phrase_image_path))

    report.new_header(level=2, title='Картинка с профилями')
    report.new_line(
        report.new_inline_image(text='Картинка с профилями',
                                path=phrase_projections_image_path))

    report.new_header(level=2, title='Картинка с сегментами символов')
    report.new_line(
        report.new_inline_image(text='Картинка с сегментами символов',
                                path=phrase_segments_image_path))

    report.new_header(level=2, title='Картинка с результатом')
    report.new_line(
        report.new_inline_image(text='Картинка с результатом',
                                path=phrase_result_image_path))

    report.create_md_file()
def generate_report():
    report = MdUtils(file_name='./report.md')
    report.new_header(level=1, title='Фильтры и морфология')
    report.new_line(text='Выполнил Ахманов Алексей Б18-514')

    for im in IMAGES:
        image_path = f'{folder_helper.IMAGES_FOLDER_PATH}/{im}'

        processed_image_folder_path = f'{image_path}_processed'
        os.makedirs(processed_image_folder_path, exist_ok=True)

        image = Image.open(image_path).convert(constants.RGB_MODE)

        # Smoothing
        spatial_smoothed_image_path = f'{processed_image_folder_path}/{im}_spatial_smoothed.png'
        spatial_smoothed_difference_image_path = f'{processed_image_folder_path}/{im}_spatial_smoothed_difference.png'

        grayscaled = grayscale.mean_grayscale(image)
        filtration.spatial_smoothing(grayscaled).save(
            spatial_smoothed_image_path)
        filtration.spatial_smoothing_difference(grayscaled).save(
            spatial_smoothed_difference_image_path)

        # Report
        report.new_header(level=2, title=f'{im}')
        report.new_header(level=3, title='Исходная картинка')
        report.new_line(
            report.new_inline_image(text='Исходная картинка', path=image_path))

        report.new_header(level=3, title='Пространственное сглаживание')
        report.new_line(
            report.new_inline_image(text='Пространственное сглаживание',
                                    path=spatial_smoothed_image_path))

        report.new_header(level=3, title='Разница сглаженной и исходной')
        report.new_line(
            report.new_inline_image(
                text='Разница сглаженной и исходной',
                path=spatial_smoothed_difference_image_path))

    report.create_md_file()
def generate_report():
    report = MdUtils(file_name='./report.md')
    report.new_header(level=1, title='Контуры')
    report.new_line(text='Выполнил Ахманов Алексей Б18-514')

    for im in IMAGES:
        image_path = f'{folder_helper.IMAGES_FOLDER_PATH}/{im}'

        processed_image_folder_path = f'{image_path}_processed'
        os.makedirs(processed_image_folder_path, exist_ok=True)

        image = Image.open(image_path).convert(constants.RGB_MODE)

        # Outline
        smoothed_image_path = f'{processed_image_folder_path}/{im}_grayscaled.png'
        roberts_cross_x_image_path = f'{processed_image_folder_path}/{im}_roberts_cross_x.png'
        roberts_cross_y_image_path = f'{processed_image_folder_path}/{im}_roberts_cross_y.png'
        roberts_cross_image_path = f'{processed_image_folder_path}/{im}_roberts_cross.png'
        roberts_cross_normalized_image_path = f'{processed_image_folder_path}/{im}_roberts_cross_normalized_#.png'

        grayscaled = grayscale.mean_grayscale(image)
        smoothed = filtration.spatial_smoothing(grayscaled)
        smoothed.save(smoothed_image_path)

        filtration.roberts_cross_x(smoothed).save(roberts_cross_x_image_path)
        filtration.roberts_cross_y(smoothed).save(roberts_cross_y_image_path)
        filtration.roberts_cross(smoothed).save(roberts_cross_image_path)

        for i in range(10, 31):
            filtration.roberts_cross_threshold(smoothed, i).save(
                roberts_cross_normalized_image_path.replace('#', f'{i}'))

        # Report
        report.new_header(level=2, title=f'{im}')
        report.new_header(level=3, title='Исходная картинка')
        report.new_line(
            report.new_inline_image(text='Исходная картинка', path=image_path))

        report.new_header(level=3, title='Сглаженные оттенки серого')
        report.new_line(
            report.new_inline_image(text='Сглаженные оттенки серого',
                                    path=smoothed_image_path))

        report.new_header(level=3, title='Оператор Робертса 2x2 (x)')
        report.new_line(
            report.new_inline_image(text='Оператор Робертса 2x2 (x)',
                                    path=roberts_cross_x_image_path))

        report.new_header(level=3, title='Оператор Робертса 2x2 (y)')
        report.new_line(
            report.new_inline_image(text='Оператор Робертса 2x2 (y)',
                                    path=roberts_cross_y_image_path))

        report.new_header(level=3, title='Оператор Робертса 2x2')
        report.new_line(
            report.new_inline_image(text='Оператор Робертса 2x2',
                                    path=roberts_cross_image_path))

        report.new_header(level=3,
                          title='Оператор Робертса 2x2 (нормализованная)')
        for i in range(10, 31):
            report.new_header(level=4, title=f'Порог {i}')
            report.new_line(
                report.new_inline_image(
                    text=f'Порог {i}',
                    path=roberts_cross_normalized_image_path.replace(
                        '#', f'{i}')))

    report.create_md_file()
Exemple #6
0
def generate_report():
    report = MdUtils(file_name='./report.md')
    report.new_header(level=1, title='Бинаризация')
    report.new_line(text='Выполнил Ахманов Алексей Б18-514')

    for im in IMAGES:
        image_path = f'{folder_helper.IMAGES_FOLDER_PATH}/{im}'

        processed_image_folder_path = f'{image_path}_processed'
        os.makedirs(processed_image_folder_path, exist_ok=True)

        image = Image.open(image_path).convert(constants.RGB_MODE)

        # Sampling
        upsampled_integer_number_of_times_image_path = f'{processed_image_folder_path}/{im}_upsampled_m.png'
        downsampled_integer_number_of_times_image_path = f'{processed_image_folder_path}/{im}_downsampled_n.png'
        oversampled_two_pass_image_path = f'{processed_image_folder_path}/{im}_oversampled_two_pass.png'
        oversampled_one_pass_image_path = f'{processed_image_folder_path}/{im}_oversampled_one_pass.png'

        sampling.bilinear_interpolation_upsampling(
            image,
            UPSAMPLE_FACTOR).save(upsampled_integer_number_of_times_image_path)
        sampling.decimation_downsampling(image, DOWNSAMPLE_FACTOR).save(
            downsampled_integer_number_of_times_image_path)
        sampling.decimation_downsampling(
            sampling.bilinear_interpolation_upsampling(image, UPSAMPLE_FACTOR),
            DOWNSAMPLE_FACTOR).save(oversampled_two_pass_image_path)
        sampling.one_pass_resampling(
            image, UPSAMPLE_FACTOR,
            DOWNSAMPLE_FACTOR).save(oversampled_one_pass_image_path)

        # Grayscale
        mean_grayscaled_image_path = f'{processed_image_folder_path}/{im}_mean_grayscaled.png'
        photoshop_grayscaled_image_path = f'{processed_image_folder_path}/{im}_photoshop_grayscaled.png'

        grayscale.mean_grayscale(image).save(mean_grayscaled_image_path)
        grayscale.photoshop_grayscale(image).save(
            photoshop_grayscaled_image_path)

        # Threshold
        balansed_hist_thresholded_image_path = f'{processed_image_folder_path}/{im}_balansed_hist_thresholded.png'

        thresholding.balansed_histogram_method(grayscale.mean_grayscale(
            image)).save(balansed_hist_thresholded_image_path)

        # Report
        report.new_header(level=2, title=f'{im}')
        report.new_header(level=3, title='Исходная картинка')
        report.new_line(
            report.new_inline_image(text='Исходная картинка', path=image_path))

        report.new_header(
            level=3, title=f'Интерполяция с коэффициентом {UPSAMPLE_FACTOR}')
        report.new_line(
            report.new_inline_image(
                text=f'Интерполяция с коэффициентом {UPSAMPLE_FACTOR}',
                path=upsampled_integer_number_of_times_image_path))

        report.new_header(
            level=3, title=f'Децимация с коэффициентом {DOWNSAMPLE_FACTOR}')
        report.new_line(
            report.new_inline_image(
                text=f'Децимация с коэффициентом {DOWNSAMPLE_FACTOR}',
                path=downsampled_integer_number_of_times_image_path))

        report.new_header(
            level=3,
            title=
            f'Двухпроходная передескритизация с коэффициентом {UPSAMPLE_FACTOR}/{DOWNSAMPLE_FACTOR}'
        )
        report.new_line(
            report.new_inline_image(
                text=
                f'Двухпроходная передескритизация с коэффициентом {UPSAMPLE_FACTOR}/{DOWNSAMPLE_FACTOR}',
                path=oversampled_two_pass_image_path))

        report.new_header(
            level=3,
            title=
            f'Однопроходная передескритизация с коэффициентом {UPSAMPLE_FACTOR}/{DOWNSAMPLE_FACTOR}'
        )
        report.new_line(
            report.new_inline_image(
                text=
                f'Однопроходная передескритизация с коэффициентом {UPSAMPLE_FACTOR}/{DOWNSAMPLE_FACTOR}',
                path=oversampled_two_pass_image_path))

        report.new_header(level=3, title=f'Оттенки серого')
        report.new_line(
            report.new_inline_image(text=f'Оттенки серого',
                                    path=mean_grayscaled_image_path))

        report.new_header(level=3, title=f'Оттенки серого (как в Photoshop)')
        report.new_line(
            report.new_inline_image(text=f'Оттенки серого (как в Photoshop)',
                                    path=photoshop_grayscaled_image_path))

        report.new_header(level=3,
                          title=f'Бинаризация (балансировка гистограммы)')
        report.new_line(
            report.new_inline_image(
                text=f'Бинаризация (балансировка гистограммы)',
                path=balansed_hist_thresholded_image_path))

    report.create_md_file()