I want to create a set of "distorted" images using python. The images should show possible misplacements of objects. The part of my script for translation and rotation seems to work well, but the scaling part doesn't work as expected. I want to randomly choose scaling parameters (random.gauss(1, 0.33)
) to scale in the different axes - so I put the following in a while loop:
# 3 random variables for scaling in x, y and z directions
num1 = math.fabs(random.gauss(1,0.33))
num2 = math.fabs(random.gauss(1,0.33))
num3 = math.fabs(random.gauss(1,0.33))
# scaling with random variables
bpy.ops.transform.resize(value=(num1, 1, 1), constraint_axis=(True, False, False))
bpy.ops.transform.resize(value=(1, num2, 1), constraint_axis=(False, True, False))
bpy.ops.transform.resize(value=(1, 1, num3), constraint_axis=(False, False, True))
Then I save the image and want to get back to the "undistorted" image. So I tried:
# scale back to original image
bpy.ops.transform.resize(value=(1/num1, 1, 1), constraint_axis=(True, False, False))
bpy.ops.transform.resize(value=(1, 1/num2, 1), constraint_axis=(False, True, False))
bpy.ops.transform.resize(value=(1, 1, 1/num3), constraint_axis=(False, False, True))
But this doesn't bring me back to the start. So I tried this in the console window of blenders UI. I have the simple startscreen featuring a camera, a cube and a lamp. For now resize and re-resize works. But if I turn the Cube by 45° round the z-axis it doesn't work any more. Scaling by (2,1,1) gives me a scale of (1.581,1.581,1) which suggests the scaling works in global coordinates. But why doesn't scaling with (0.5,1,1) give me the original cube. It gives me a scale of (1.25,1.25,1) instead.
So the question is, how do I get this to give me the original object back?