def process_import(fname, dct=image_import_dict): imglist = imageio.list_of_frames(fname) fsett = dct[str(len(imglist))] pwa, pwoa, df1, df2 = fsett.pwa, fsett.pwoa, fsett.df1, fsett.df2 # split the individual frames if kinetics mode is specified if fsett.kinetics: templist = [] for frame in imglist: for i in xrange(fsett.strips_per_frame): if fsett.startat == 'BR': if fsett.orientation == 'V': size = imglist[pwa].shape[0] else: size = imglist[pwa].shape[1] idx = slice(size - (i+1)*fsett.lineshift, size - i*fsett.lineshift) else: idx = slice(i*fsett.lineshift, (i+1)*fsett.lineshift) if fsett.orientation == 'V': templist.append(frame[idx, :]) else: templist.append(frame[:, idx]) imglist = templist rawframes = np.dstack(imglist) if not fsett.usetext: transimg, odimg = default_calc_transimg(imglist[pwa], imglist[pwoa], imglist[df1], imglist[df2]) else: funcstr = _construct_custom_func(fsett.text) exec(funcstr) # create the function transimg = imgfunc(imglist[pwa], imglist[pwoa], imglist[df1], imglist[df2], imglist) odimg = imageprocess.trans2od(transimg) return rawframes, transimg, odimg
def process_import(fname, dct=image_import_dict): imglist = imageio.list_of_frames(fname) fsett = dct[str(len(imglist))] pwa, pwoa, df1, df2 = fsett.pwa, fsett.pwoa, fsett.df1, fsett.df2 # split the individual frames if kinetics mode is specified if fsett.kinetics: templist = [] for frame in imglist: for i in xrange(fsett.strips_per_frame): if fsett.startat == 'BR': if fsett.orientation == 'V': size = imglist[pwa].shape[0] else: size = imglist[pwa].shape[1] idx = slice(size - (i + 1) * fsett.lineshift, size - i * fsett.lineshift) else: idx = slice(i * fsett.lineshift, (i + 1) * fsett.lineshift) if fsett.orientation == 'V': templist.append(frame[idx, :]) else: templist.append(frame[:, idx]) imglist = templist rawframes = np.dstack(imglist) if not fsett.usetext: transimg, odimg = default_calc_transimg(imglist[pwa], imglist[pwoa], imglist[df1], imglist[df2]) else: funcstr = _construct_custom_func(fsett.text) exec(funcstr) # create the function transimg = imgfunc(imglist[pwa], imglist[pwoa], imglist[df1], imglist[df2], imglist) odimg = imageprocess.trans2od(transimg) return rawframes, transimg, odimg
def add_noise(img, ampl=0.05, noisetype='random', fringeargs=None): """Noise is added to an image. **Inputs** * img: 2d array, containing image data * ampl: float, amplitude of the noise * noisetype: string, value can be one of * 'random', adds unbiased white noise * 'linear_x', adds a linear gradient along x from 0 to ampl * 'linear_y', adds a linear gradient along y from 0 to ampl * 'fringes', adds fringes with parameters fringeargs * fringeargs: sequence, containing four values * angle: float, angle of fringes in radians with respect to the x-axis * freq: float, frequency of the fringes in pixels^{-1} * pos: tuple, central position of the fringes with respect to the CoM * size: float, size of the Gaussian envelope of the fringes **Outputs** * img: 2d array, the input image with noise added to it """ noisetypes = ['random', 'linear_x', 'linear_y', 'fringes'] if not noisetype in noisetypes: raise ValueError, \ """noisetype is one of: %s"""%noisetypes if noisetype=='random': img = img + (np.random.random_sample(img.shape)-0.5)*ampl elif noisetype=='linear_x': noise = np.ones(img.shape).transpose()*np.arange(img.shape[0])\ /img.shape[0]*ampl img = img + noise.transpose() elif noisetype=='linear_y': noise = np.ones(img.shape)*np.arange(img.shape[1])/img.shape[1]*ampl img = img + noise elif noisetype=='fringes': if not len(fringeargs)==4: print "fringeargs needs to contain four values: angle, freq, pos, size" angle, freq, pos, size = fringeargs xx, yy = np.mgrid[0:img.shape[0], 0:img.shape[1]] # center of mass coordinates odimg = trans2od(img) com = center_of_mass(odimg) xx0 = xx - com[0] - pos[0] yy0 = yy - com[1] - pos[1] yy0 = np.where(yy0==0, 1e-6, yy0) rr = np.sqrt(xx0**2 + yy0**2) # coordinate projection along fringe axis rangle = np.arctan(xx0.astype(float)/yy0) rangle = np.where(yy0>0, rangle, rangle + np.pi) rfringe = rr*np.cos(angle - rangle) noise = fitfuncs.gaussian(rr, ampl, size) * np.sin(2*np.pi*rfringe*freq) img = img + noise return img
def add_noise(img, ampl=0.05, noisetype='random', fringeargs=None): """Noise is added to an image. **Inputs** * img: 2d array, containing image data * ampl: float, amplitude of the noise * noisetype: string, value can be one of * 'random', adds unbiased white noise * 'linear_x', adds a linear gradient along x from 0 to ampl * 'linear_y', adds a linear gradient along y from 0 to ampl * 'fringes', adds fringes with parameters fringeargs * fringeargs: sequence, containing four values * angle: float, angle of fringes in radians with respect to the x-axis * freq: float, frequency of the fringes in pixels^{-1} * pos: tuple, central position of the fringes with respect to the CoM * size: float, size of the Gaussian envelope of the fringes **Outputs** * img: 2d array, the input image with noise added to it """ noisetypes = ['random', 'linear_x', 'linear_y', 'fringes'] if not noisetype in noisetypes: raise ValueError, \ """noisetype is one of: %s"""%noisetypes if noisetype == 'random': img = img + (np.random.random_sample(img.shape) - 0.5) * ampl elif noisetype == 'linear_x': noise = np.ones(img.shape).transpose()*np.arange(img.shape[0])\ /img.shape[0]*ampl img = img + noise.transpose() elif noisetype == 'linear_y': noise = np.ones(img.shape) * np.arange( img.shape[1]) / img.shape[1] * ampl img = img + noise elif noisetype == 'fringes': if not len(fringeargs) == 4: print "fringeargs needs to contain four values: angle, freq, pos, size" angle, freq, pos, size = fringeargs xx, yy = np.mgrid[0:img.shape[0], 0:img.shape[1]] # center of mass coordinates odimg = trans2od(img) com = center_of_mass(odimg) xx0 = xx - com[0] - pos[0] yy0 = yy - com[1] - pos[1] yy0 = np.where(yy0 == 0, 1e-6, yy0) rr = np.sqrt(xx0**2 + yy0**2) # coordinate projection along fringe axis rangle = np.arctan(xx0.astype(float) / yy0) rangle = np.where(yy0 > 0, rangle, rangle + np.pi) rfringe = rr * np.cos(angle - rangle) noise = fitfuncs.gaussian(rr, ampl, size) * np.sin( 2 * np.pi * rfringe * freq) img = img + noise return img