def test_wrong_mode(): lut = ImageMorph.LutBuilder(op_name="corner").build_lut() imrgb = Image.new("RGB", (10, 10)) iml = Image.new("L", (10, 10)) with pytest.raises(RuntimeError): _imagingmorph.apply(bytes(lut), imrgb.im.id, iml.im.id) with pytest.raises(RuntimeError): _imagingmorph.apply(bytes(lut), iml.im.id, imrgb.im.id) with pytest.raises(RuntimeError): _imagingmorph.match(bytes(lut), imrgb.im.id) # Should not raise _imagingmorph.match(bytes(lut), iml.im.id)
def test_wrong_mode(self): lut = ImageMorph.LutBuilder(op_name='corner').build_lut() imrgb = Image.new('RGB', (10, 10)) iml = Image.new('L', (10, 10)) with self.assertRaises(RuntimeError): _imagingmorph.apply(bytes(lut), imrgb.im.id, iml.im.id) with self.assertRaises(RuntimeError): _imagingmorph.apply(bytes(lut), iml.im.id, imrgb.im.id) with self.assertRaises(RuntimeError): _imagingmorph.match(bytes(lut), imrgb.im.id) # Should not raise _imagingmorph.match(bytes(lut), iml.im.id)
def apply(self, image): """Run a single morphological operation on an image Returns a tuple of the number of changed pixels and the morphed image""" if self.lut is None: raise Exception("No operator loaded") outimage = Image.new(image.mode, image.size, None) count = _imagingmorph.apply(bytes(self.lut), image.im.id, outimage.im.id) return count, outimage
def apply(self, image): """Run a single morphological operation on an image Returns a tuple of the number of changed pixels and the morphed image""" if self.lut is None: raise Exception('No operator loaded') outimage = Image.new(image.mode, image.size, None) count = _imagingmorph.apply( bytes(self.lut), image.im.id, outimage.im.id) return count, outimage
def verify(jd, func, args_tuple): jd_cmp = apply(func, args_tuple) if jd != jd_cmp: print ("ERROR: %s(%s) = %s did not match jd (%s)" % (func, str(args). str(jd_cmp), str(jd))) return 0 else: return 1
print ("-------------------------------------") print ("gregorian date:", gregorian) jd = gregorian_to_jd(gregorian[0], gregorian[1], gregorian[2]) print ("julian day:", jd) cals = ('hebrew', 'islamic', 'persian', 'indian_civil', 'iso', 'iso_day', 'julian', 'mayan_count', 'mayan_haab', 'mayan_tzolkin', 'bahai', 'french_revolutionary') errors = 0 for cal in cals: func = eval("jd_to_%s" % cal) val = apply(func, (jd,)) print ("%s: %s" % (cal, str(val))) try: func = eval("%s_to_jd" % cal) if not verify(jd, func, val): errors += 1 except NameError: #print str(func), "does not exist" pass if errors: print ("\nEncountered", errors, "errors in converting to and from jd")