Esempio n. 1
0
    def __init__(self, img_rgb, pattern_name, threshold, probe_func_list):
        img_tools = ImageTools()

        self.img_rgb = img_rgb
        self.threshold = threshold
        self.img_gray = img_tools.rgb2gray(self.img_rgb, self.threshold)
        self.pattern_name = pattern_name
        self.arr_image = img_tools.img2arr(self.img_gray)

        self.probe_func_list = probe_func_list

        self.lst_near_patterns = []  #...patterns of this class
        self.lst_L2 = []  #...distance L2 by each pattern of thi class
        self.ave_contrast = 0
        self.ave_correlation = 0
        self.ave_energy = 0
        self.ave_entropy = 0
        self.ave_homogeneity = 0
        self.l2 = 0
        self.class_name = ''
        self.class_index = 0

        if probe_func_list[0]:
            self.contrast = self.calculateContrast(self.arr_image)
        if probe_func_list[1]:
            self.correlation = self.calculateCorrelation(self.arr_image)
        if probe_func_list[2]:
            self.energy = self.calculateEnergy(self.arr_image)
        if probe_func_list[3]:
            self.entropy = self.calculateEntropy(self.arr_image)
        if probe_func_list[4]:
            self.homogeneity = self.calculateHomogeneity(self.arr_image)
    def test_equal_images_histogram_compare_returns_zero(self):
        im1 = Image.new('RGB', (256, 256), 'white')
        im2 = im1.copy()

        img_comp = ImageTools()
        img_diff = img_comp._compare_images_histogram(im1, im2)
        self.assertEqual(img_diff, 0)
    def test_empty_images_histogram_compare_returns_error(self):
        im1 = Image.new('RGB', (256, 256), 'white')
        im2 = None

        img_comp = ImageTools()
        img_diff = img_comp._compare_images_histogram(im1, im2)
        self.assertEqual(img_diff, 'One or more images are empty')
    def test_opposite_images_histogram_compare_returns_nonzero(self):
        im1 = Image.new('RGB', (256, 256), 'white')
        im2 = Image.new('RGB', (256, 256), 'black')

        img_comp = ImageTools()
        img_diff = img_comp._compare_images_histogram(im1, im2)
        print(img_diff)
        self.assertGreater(img_diff, 0)
    def test_opposite_images_pixel_compare_returns_one_hundred(self):
        im1 = Image.new('RGB', (256, 256), 'white')
        im2 = Image.new('RGB', (256, 256), 'black')

        img_comp = ImageTools()
        img_diff = img_comp._compare_images_pixel(im1, im2)
        print(img_diff)
        self.assertEqual(img_diff, 100.0)
    def test_nonexist_imagefiles_return_error(self):
        im1 = Image.new('RGB', (256, 256), 'white')

        im1.save(self.imfile1)

        img_comp = ImageTools()
        img_diff = img_comp.compare_image_files(self.imfile1, 'notreal.jpg')
        self.assertEqual(img_diff, 'Error reading one or more files')
    def test_imagefiles_calls_pixels_algo_by_default(self):
        im1 = Image.new('RGB', (256, 256), 'white')
        im2 = Image.new('RGB', (256, 256), 'black')

        im1.save(self.imfile1)
        im2.save(self.imfile2)

        img_comp = ImageTools()
        img_diff = img_comp.compare_image_files(self.imfile1, self.imfile2)
        self.assertEqual(img_diff, 100.0)
Esempio n. 8
0
 def __init__(self, img_rgb, solar_disk_name, threshold, size,
              probe_func_list):
     img_tools = ImageTools()
     self.size = size
     self.img_rgb = img_rgb
     self.threshold = threshold
     self.img_gray = img_tools.rgb2gray(self.img_rgb, self.threshold)
     self.pattern_name = solar_disk_name
     self.arr_image = img_tools.img2arr(self.img_gray)
     self.lst_windows = self.generateFixedWindows(self.arr_image, self.size,
                                                  probe_func_list)
    def test_imagefiles_calling_unknown_algo_returns_error(self):
        im1 = Image.new('RGB', (256, 256), 'white')
        im2 = Image.new('RGB', (256, 256), 'black')

        im1.save(self.imfile1)
        im2.save(self.imfile2)

        img_comp = ImageTools()
        img_diff = img_comp.compare_image_files(self.imfile1,
                                                self.imfile2,
                                                algorithm='unknown')
        self.assertEqual(img_diff, 'Unsupported algorithm')
    def test_imagefiles_calling_histogram_algo(self):
        im1 = Image.new('RGB', (256, 256), 'white')
        im2 = Image.new('RGB', (256, 256), 'black')

        im1.save(self.imfile1)
        im2.save(self.imfile2)

        img_comp = ImageTools()
        img_diff = img_comp.compare_image_files(self.imfile1,
                                                self.imfile2,
                                                algorithm='histogram')
        self.assertGreater(img_diff, 100.0)
Esempio n. 11
0
 def __init__(self, nro_line, nro_column, arr_window, probe_func_list):
     img_tools = ImageTools()
     self.nro_line = nro_line
     self.nro_column = nro_column
     self.arr_image = arr_window
     if probe_func_list[0]:
         self.contrast = self.calculateContrast(self.arr_image)
     if probe_func_list[1]:
         self.correlation = self.calculateCorrelation(self.arr_image)
     if probe_func_list[2]:
         self.energy = self.calculateEnergy(self.arr_image)
     if probe_func_list[3]:
         self.entropy = self.calculateEntropy(self.arr_image)
     if probe_func_list[4]:
         self.homogeneity = self.calculateHomogeneity(self.arr_image)
#probe_func_list = [True,False,True,Fale,False]        #..(Contrast,Energy)
#probe_func_list = [True,False,True,True,True]        #..(Contrast,Energy,Entropy,Homogeneity)
#probe_func_list = [True,False,False,True,False]        #..(Contrast,Entropy)
#probe_func_list = [True,False,False,False,True]        #..(Contrast,Homogeneity)
#probe_func_list = [False,False,True,False,False]        #..(Energy)
#probe_func_list = [False,False,True,True,False]        #..(Energy,Entropy)
#probe_func_list = [False,False,True,False,True]        #..(Energy,Homogeneity)
#probe_func_list = [False,False,False,True,False]        #..(Entropy)
#probe_func_list = [False,False,False,True,True]        #..(Entropy,Homogeneity)
#probe_func_list = [False,False,False,False,True]        #..(Homogeneity)

lst_patterns = []  #...patterns object list
lst_classes = []  #...solar flare classes
lst_solar_disk = []  #...solar disk images for test

image_tools = ImageTools()
db_images = dbImages()

if probe_func_list[0]:
    max_contrast = 0
if probe_func_list[1]:
    max_correlation = 0
if probe_func_list[2]:
    max_energy = 0
if probe_func_list[3]:
    min_entropy = 0
if probe_func_list[4]:
    max_homogeneity = 0

print ".|begin application..."