def test_defgrad_rotate_square(self): """ Subtract an rotated and un-rotated square. Two cases: * Rotate 45deg and subtract, should give a non-zero diffence * Rotate 90 deg and subtract, should give a zero difference """ tol = 1e-4 square = np.zeros((200, 200), dtype=np.float) square[75:125, 75:125] = 1. theta = np.pi / 4. F_rot_45 = np.array([[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]], dtype=np.float64) image_deformer_45 = vlab.imageDeformer_from_defGrad(F_rot_45) image_rotated_45 = image_deformer_45(square, steps=2)[1] if np.abs(np.sum(np.abs(square - image_rotated_45))) < 1.: self.fail("The rotated image is the same as the un-rotated one") theta = np.pi / 2. F_rot_90 = np.array([[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]], dtype=np.float64) image_deformer_90 = vlab.imageDeformer_from_defGrad(F_rot_90) image_rotated_90 = image_deformer_90(square, steps=2)[1] if np.abs(np.sum(np.abs(square - image_rotated_90))) > tol: self.fail("The image rotated by 90deg should be identical to the un-rotated image")
def __run_DIC_defgrad__(self, F, element, x1=150, x2=350, y1=150, y2=350, n_elx=3, n_ely=3): """ Function that imposes a deformation gradient upon a reference image, runs a full DIC job and compares the resulting deformation gradient to the imposed gradient. This is done for all points within the elements. :param F: Deformation gradient :param element: Finite element definitions :return True if test is passed """ # Default settings n_frames = 10 rel_tol_F = 1e-2 downsampler = Downsampler(image_shape=self.img_shape, factor=1, fill=1.0, pixel_offset_stddev=0.0) image_deformer = vlab.imageDeformer_from_defGrad(F) noise_injector = lambda img: img image_reader = SyntheticImageGenerator(speckle_image=self.image, image_deformer=image_deformer, downsampler=downsampler, noise_injector=noise_injector, n=n_frames) images_stack = dic.IO.ImageStack(image_reader) # Initialize a mesh instance if isinstance(element, dic.elements.BSplineSurface): mesher_tool = dic.mesh.Mesher(element.degree_e, element.degree_n,type="spline") elif isinstance(element,dic.elements.Q4): mesher_tool = dic.mesh.Mesher(type="Q4") else: raise TypeError("Invalid element received") myMesh = mesher_tool.mesh(images_stack, x1, x2, y1, y2, n_elx, n_ely, GUI=False) # Generate mesh RefUpdate = [5] settings = muDIC.solver.correlate.DICInput(myMesh, images_stack, RefUpdate) settings.tol = 1e-6 # Run DIC analysis = dic.solver.DICAnalysis(settings) dic_results = analysis.run() n_nodes, n_frames_dic = np.shape(dic_results.xnodesT) if n_frames != n_frames_dic: return False results = dic.Fields(dic_results, seed=21) max_error, mean_error = self.__calculate_DIC_error__(F, results.F()) return max_error <= rel_tol_F
def test_defgrad_dilate_square_by_biaxial_tension(self): """ Deforms a image with a square by a given amount and checks the area of the square """ tol = 1e-4 square = np.zeros((200, 200), dtype=np.float) square[75:125, 75:125] = 1. undeformed_hole_area = np.sum(square) F = np.array([[2., .0], [0., 2.0]], dtype=np.float64) image_deformer = vlab.imageDeformer_from_defGrad(F) enlarged_hole = image_deformer(square, steps=2)[1] enlarged_hole_area = np.sum(enlarged_hole) area_increase = enlarged_hole_area / undeformed_hole_area if np.abs(area_increase - np.linalg.det(F)) > tol: self.fail("Deformed area should be %f but was %f" % (np.linalg.det(F), area_increase))
def test__pass_through_user_img(self): F = np.eye(2, dtype=np.float) image_deformer = vlab.imageDeformer_from_defGrad(F) downsampler = vlab.Downsampler(image_shape=self.img_shape, factor=1, fill=1., pixel_offset_stddev=0.0) noise_injector = lambda img: img virtualTest = vlab.SyntheticImageGenerator( speckle_image=self.image, image_deformer=image_deformer, downsampler=downsampler, noise_injector=noise_injector, n=10) deviation = np.abs(virtualTest(1) - self.image) if np.max(deviation) > self.tol: self.fail( "Image changed value or orientation. Largest error is%f" % np.max(deviation))
# Define the image you want to analyse n_imgs = 2 image_shape = (500, 500) downsample_factor = 4 super_image_shape = tuple(dim * downsample_factor for dim in image_shape) # Make a speckle image speckle_image = vlab.rosta_speckle(super_image_shape, dot_size=4, density=0.5, smoothness=2.0) # Make an image deformed F = np.array([[1.01, 0], [0.01, 1.0]]) image_deformer = vlab.imageDeformer_from_defGrad(F) # Make an image down-sampler including downscaling, fill-factor and sensor grid irregularities downsampler = vlab.Downsampler(image_shape=super_image_shape, factor=downsample_factor, fill=.95, pixel_offset_stddev=0.05) # Make a noise injector producing 2% gaussian additive noise noise_injector = vlab.noise_injector("gaussian", sigma=.02) # Make an synthetic image generation pipeline image_generator = vlab.SyntheticImageGenerator(speckle_image=speckle_image, image_deformer=image_deformer, downsampler=downsampler, noise_injector=noise_injector,