def test_load(self): t1 = KerrArray([1, 2, 3], metadata={'a': 5}) self.assertTrue(np.array_equal(t1, np.array([1, 2, 3])), 'Initialising from list failed') self.assertTrue(t1.metadata['a'] == 5, 'Initialising metadata from data failed') t1 = KerrArray([1, 2, 3]) self.assertTrue(np.array_equal(t1, np.array([1, 2, 3])))
def correct_drift(im, ref, threshold=0.005, upsample_factor=50): """Align images to correct for image drift. Detects common features on the images and tracks them moving. Adds 'drift_shift' to the metadata as the (x,y) vector that translated the image back to it's origin. Parameters ---------- ref: KerrArray or ndarray reference image with zero drift threshold: float threshold for detecting imperfections in images (see skimage.feature.corner_fast for details) upsample_factor: the resolution for the shift 1/upsample_factor pixels registered. see skimage.feature.register_translation for more details Returns ------- shift: array shift vector relative to ref (x drift, y drift) transim: KerrArray copy of im translated to account for drift""" refed=KerrArray(ref,get_metadata=False) refed=refed.filter_image(sigma=1) refed=refed.corner_fast(threshold=threshold) imed=im.clone imed=imed.filter_image(sigma=1) imed=imed.corner_fast(threshold=threshold) shift,err,phase=feature.register_translation(refed,imed,upsample_factor=upsample_factor) im=im.translate(translation=(-shift[1],-shift[0])) #x,y im.metadata['correct_drift']=(-shift[1],-shift[0]) return im
# -*- coding: utf-8 -*- """ Created on Mon Jun 20 19:21:48 2016 @author: phyrct """ from kermit import KerrArray import numpy as np a=KerrArray('coretestdata/im2_noannotations.png') a1=KerrArray('coretestdata/im1_annotated.png') b=a.translate((2.5,3)) c=b.correct_drift(ref=a) print a.metadata print a1.metadata print all([k in a.metadata.keys() for k in a1.metadata.keys()])
# -*- coding: utf-8 -*- """ Created on Mon Jun 20 19:21:48 2016 @author: phyrct """ from kermit import KerrArray import numpy as np a = KerrArray([[.1, .2, .3], [.2, .3, .4], [.3, .4, .5]], dtype=np.float64) b = a.level_image() c = a.level_image(poly_vert=0) assert np.allclose( b, np.array([[.3, .3, .3], [.3, .3, .3], [.3, .3, .3]], dtype=np.float64)) c = a.level_image(poly_vert=0) assert np.allclose( c, np.array([[.2, .2, .2], [.3, .3, .3], [.4, .4, .4]], dtype=np.float64)) d = b.level_image(poly=-np.array(b.metadata['poly_sub'])) assert np.allclose(d, a) #should get it back to original
def _load_KerrArray(f,img_num=0, **kwargs): return KerrArray(f, **kwargs)
@author: phyrct """ from kermit import KerrArray,KerrList import numpy as np import matplotlib.pyplot as plt a=KerrList('coretestdata/*.png') #check loaded ok print a[1].metadata assert all([k in ['floatdata','filename'] for k in a[1].metadata.keys()]) #check set item a[0]=KerrArray([1,2,3],dtype=np.float64,metadata={'abc':3}) assert 'abc' in a[0].metadata.keys() print a[0].metadata a.files #check reload doesn't destroy setitems a.reload() print a[0].metadata assert 'abc' in a[0].metadata.keys() #check loading from arrays print 'load array test' b=KerrList([KerrArray('coretestdata\\im1_annotated.png'), KerrArray('coretestdata\\im2_noannotations.png')]) print b[1].metadata
def setUp(self): self.td1 = KerrArray(td1) self.td2 = KerrArray(td2) self.anim = KerrArray('coretestdata/im1_annotated.png') self.unanim = KerrArray('coretestdata/im2_noannotations.png') self.testdata = (self.td1, self.td2, self.anim, self.unanim)
Created on Wed Jun 29 11:45:26 2016 @author: phyrct """ import os import numpy as np from kermit import KerrArray, KerrList from skimage.viewer import CollectionViewer, ImageViewer import matplotlib.pyplot as plt folder = r'..\tests\coretestdata\hysteresis_test' editfolder = r'..\tests\coretestdata\hysteresis_test\edited_ims' os.chdir(folder) background = KerrArray('image0000_background.png') background = background.convert_float() print 'loading images...' kl = KerrList('image000*unproccessed.png', conserve_memory=False, get_metadata=False) list(kl) #make sure all images loaded print 'images loaded' #%% print 'convert float' kl.apply_all('convert_float') #convert pixels to decimal values print 'correct_drift' kl.apply_all('correct_drift', ref=background, upsample_factor=200) print 'subtract'