This paper introduces the autofocus problem for non-destructive testing and evaluation of specimens with complicated geometries using ultrasonic arrays. We present an algorithm for autofocusing imagery of point-like defects obtained from a flexible array with an unknown profile. The relative positions of the array elements are parameterised using a cubic spline function and the spline control points are estimated by iterative maximisation of an image contrast metric via simulated annealing. The resultant spline gives an estimate of the array profile and the profile of the surface that it has conformed to, allowing the generation of a well-focused image. The algorithm is demonstrated on experimental data obtained using a flexible array prototype.