Esempio n. 1
0
 def testImageTransformBatch(self):
     file_path = "/Users/superCat/Desktop/PycharmProjectPortable/test/spam_test1.txt"
     read_file_path = "/Users/superCat/Desktop/PycharmProjectPortable/test/Image_Samples/"
     save_file_path = "/Users/superCat/Desktop/PycharmProjectPortable/test/Image_Filtered/"
     FileIO.FileHandler.create_file_if_not_exist(save_file_path)
     domain_list = FileIO.FileHandler.read_lines_from_file(file_path)
     for item in domain_list:
         print("doing: item:", item)
         peak_scale_factor = 0.9
         image_path = read_file_path + item + ".png"
         matrix, width, height = read_image(image_path)
         new_matrix, one_d_array, average = get_1d_array(
             matrix, 255, height, width, 0.5, 0.97)
         first_ref, second_ref, min_ref, min_v = find_peak(
             one_d_array,
             max_value=height,
             average_scale=peak_scale_factor,
             amplitude_scale=0.3,
             min_deviation=3)
         insert_line(new_matrix, first_ref, 50)
         insert_line(new_matrix, second_ref, 50)
         insert_line(new_matrix, min_ref, 50)
         insert_line(new_matrix,
                     int(average * peak_scale_factor),
                     200,
                     is_vertical=False)
         formated = png.from_array(new_matrix, mode='L')
         new_path = save_file_path + item + ".png"
         formated.save(new_path)
 def testImageTransform1(self):
     peak_scale_factor = 0.9
     image_path = "/Users/superCat/Desktop/PycharmProjectPortable/test/Image_Samples/3xstar.net.png"
     matrix, width, height = read_image(image_path)
     new_matrix, one_d_array, average = get_1d_array(matrix, 255, height, width, 0.5, 0.97)
     first_ref, second_ref, min_ref, min_v = find_peak(one_d_array,
                                                       max_value=height, average_scale=peak_scale_factor,
                                                       amplitude_scale=0.3, min_deviation=3)
     insert_line(new_matrix, first_ref, 50)
     insert_line(new_matrix, second_ref, 50)
     insert_line(new_matrix, min_ref, 50)
     insert_line(new_matrix, int(average*peak_scale_factor), 200, is_vertical=False)
     formated = png.from_array(new_matrix, mode='L')
     new_path = "/Users/superCat/Desktop/PycharmProjectPortable/test/test_filterd1.png"
     formated.save(new_path)
     im = Image.open(new_path)
     im.show()
Esempio n. 3
0
    def testRead(self):
        image_path = "/Users/superCat/Desktop/PycharmProjectPortable/test/BacklinkHistoryChart.png"
        new_image_path = "/Users/superCat/Desktop/PycharmProjectPortable/test/Image/{0:d}.png"
        matrix = []
        reader = png.Reader(filename=image_path)
        pixel_dict = {}
        w, h, pixels, metadata = reader.asRGBA()
        for row in pixels:
            matrix.append(row)
            for pixcel in row:
                if pixcel in pixel_dict.keys():
                    v = pixel_dict[pixcel]
                    pixel_dict.update({pixcel: v + 1})
                else:
                    pixel_dict.update({pixcel: 1})
        height = len(matrix)
        width = len(matrix[0])
        print("height:", height, "width:", width)
        print("variations:")

        sort = [
            x for x in sorted(pixel_dict.items(),
                              key=lambda pixel_count: pixel_count[1],
                              reverse=True) if 20000 > x[1] > 50
        ]
        count = 0
        for item in sort:
            new_matrix = []
            for row in matrix:
                new_row = []
                for pixel in row:
                    if pixel == item[0]:
                        new_row.append(255)
                    else:
                        new_row.append(0)
                new_matrix.append(new_row)
            formated = png.from_array(new_matrix, mode='L')
            new_path = new_image_path.format(item[0], )
            FileIO.FileHandler.create_file_if_not_exist(new_path)
            formated.save(new_path)
            count += 1
            if count == 10:
                break
    def testRead(self):
        image_path = "/Users/superCat/Desktop/PycharmProjectPortable/test/BacklinkHistoryChart.png"
        new_image_path = "/Users/superCat/Desktop/PycharmProjectPortable/test/Image/{0:d}.png"
        matrix = []
        reader = png.Reader(filename=image_path)
        pixel_dict = {}
        w, h, pixels, metadata = reader.asRGBA()
        for row in pixels:
            matrix.append(row)
            for pixcel in row:
                if pixcel in pixel_dict.keys():
                    v = pixel_dict[pixcel]
                    pixel_dict.update({pixcel: v+1})
                else:
                    pixel_dict.update({pixcel: 1})
        height = len(matrix)
        width = len(matrix[0])
        print("height:", height, "width:", width)
        print("variations:")

        sort = [x for x in sorted(pixel_dict.items(), key=lambda pixel_count: pixel_count[1], reverse=True) if 20000> x[1] > 50]
        count = 0
        for item in sort:
            new_matrix= []
            for row in matrix:
                new_row = []
                for pixel in row:
                    if pixel == item[0]:
                        new_row.append(255)
                    else:
                        new_row.append(0)
                new_matrix.append(new_row)
            formated = png.from_array(new_matrix, mode='L')
            new_path = new_image_path.format(item[0],)
            FileIO.FileHandler.create_file_if_not_exist(new_path)
            formated.save(new_path)
            count += 1
            if count == 10:
                break
 def testImageTransformBatch(self):
     file_path = "/Users/superCat/Desktop/PycharmProjectPortable/test/spam_test1.txt"
     read_file_path = "/Users/superCat/Desktop/PycharmProjectPortable/test/Image_Samples/"
     save_file_path = "/Users/superCat/Desktop/PycharmProjectPortable/test/Image_Filtered/"
     FileIO.FileHandler.create_file_if_not_exist(save_file_path)
     domain_list = FileIO.FileHandler.read_lines_from_file(file_path)
     for item in domain_list:
         print("doing: item:", item)
         peak_scale_factor = 0.9
         image_path = read_file_path + item + ".png"
         matrix, width, height = read_image(image_path)
         new_matrix, one_d_array, average = get_1d_array(matrix, 255, height, width, 0.5, 0.97)
         first_ref, second_ref, min_ref, min_v = find_peak(one_d_array,
                                                           max_value=height, average_scale=peak_scale_factor,
                                                           amplitude_scale=0.3, min_deviation=3)
         insert_line(new_matrix, first_ref, 50)
         insert_line(new_matrix, second_ref, 50)
         insert_line(new_matrix, min_ref, 50)
         insert_line(new_matrix, int(average*peak_scale_factor), 200, is_vertical=False)
         formated = png.from_array(new_matrix, mode='L')
         new_path = save_file_path + item + ".png"
         formated.save(new_path)
Esempio n. 6
0
 def testImageTransform1(self):
     peak_scale_factor = 0.9
     image_path = "/Users/superCat/Desktop/PycharmProjectPortable/test/Image_Samples/3xstar.net.png"
     matrix, width, height = read_image(image_path)
     new_matrix, one_d_array, average = get_1d_array(
         matrix, 255, height, width, 0.5, 0.97)
     first_ref, second_ref, min_ref, min_v = find_peak(
         one_d_array,
         max_value=height,
         average_scale=peak_scale_factor,
         amplitude_scale=0.3,
         min_deviation=3)
     insert_line(new_matrix, first_ref, 50)
     insert_line(new_matrix, second_ref, 50)
     insert_line(new_matrix, min_ref, 50)
     insert_line(new_matrix,
                 int(average * peak_scale_factor),
                 200,
                 is_vertical=False)
     formated = png.from_array(new_matrix, mode='L')
     new_path = "/Users/superCat/Desktop/PycharmProjectPortable/test/test_filterd1.png"
     formated.save(new_path)
     im = Image.open(new_path)
     im.show()