1 Introduction

Studying the shockwave phenomena is of a great importance in many different areas of physics and applied sciences and finds its use in a wide spectrum of medical applications [1]. Multiple numerical and experimental studies on shockwaves, their induction mechanisms, and their propagation under various circumstances have been recently demonstrated. Among those, the study of optodynamic energy-conversion efficiency [2], derivation of equations of state [3, 4], and validation of analytical and numerical models proposed by various research groups [5] are of importance for deeper understanding of shockwave physics and material science.

Over the past few years, various different systems for shockwave inspection, involving Schlieren imaging technique [6, 7] and shadowgraphy [8], have been developed and used. In both techniques, the observation of transient phenomena is possible due to the variations of refractive index of the medium [9]. High-contrast shadowgraphs can be obtained with set-ups where large variations in refractive index occur. This makes Schlieren and shadowgraphic techniques suitable mainly for observations of shockwaves in solids and liquids. On the other hand, extremely low contrast of shadowgraphs is encountered in experiments with gases, where the refractive-index variations are significantly smaller than in solids or liquids [10, 11]. Additionally, the pressure of the shockwave front is fading away by propagation, which also results in lower contrast of the acquired images. This makes the observation of shockwaves in gases a challenging problem. In order to overcome these problems, improvements of existing Schlieren visualization techniques has been proposed by Vogel et al. [10] to increase the sensitivity of the imaging technique and assure images having a higher contrast. However, there is still a lack of experimental studies encountering challenging visualization and data analysis in low-contrast shadowgraphs.

Autonomous computer-controlled systems for studying laser-induced plasma and shockwave phenomena have recently been reported [8], which allow the creation of large shockwave image dataset necessary for validation of analytical and numerical models. The current data processing involves time-consuming complex manual shockwave segmentation technique [12], and automating these tasks would facilitate the dataset creation. Up to now no thorough study on image processing on laser-induced shockwave shadowgraph can be found in the open literature. Nevertheless, for high-contrast images, many standard image processing techniques may yield good results [13, 14]. However, these techniques are insufficient for the processing of low-contrast shadowgraphs, where high-level algorithm for image segmentation is required. The main aim of this paper was to present a novel two-stage segmentation method based on active contours that allows automated shock wave segmentation in low-contrast shadowgraphs.

2 A background of laser shadowgraphy

In shadowgraphy, white light seems to be a preferable choice for illumination of wide variety of applications due to its flexibility, low-cost, and low-coherence yielding good image quality, i.e., high signal-to-noise ratio [9]. Here, typical pulse durations of spark gap light sources are in the range between 1 and 10 ns. However, very high-speed phenomena, such as plasma ignition and shockwave generation, propagate with velocities up to 600 and 100 km/s, respectively [8, 11]. Therefore, in these cases a very short illumination of less than 100 ps is required to achieve a spatial resolution of about 10 \(\upmu \)m. Consequently, a short laser pulse is the only option for illumination ensuring a high spatial resolution.

A coherent-laser illumination introduces many drawbacks regarding image quality, such as the presence of noise that is caused by laser speckles and diffraction pattern, clearly visible in Fig. 4a as a regular pattern of fringes. Here, Fig. 4a is acquired 132 ns after the laser breakdown in air and a 30-ps, green-laser pulse was used as an illumination source (see experimental setup in Refs. [8, 11]). Interference phenomena that appear due to the coherent illumination are undesirable and strongly impede the subsequent image processing. From Fig. 4a it is visible that the shockwave boundary is rather indistinctive on the low-contrast shadowgraph image hindering robustness of shockwave detection. It is, therefore, important to incorporate other image cues for successful detection. To do this, the understanding of image formation is crucial.

Figure 1 depicts a typical situation where coherent light is passed through a shockwave and collected by an image detector. Black dots on the left-hand side of Fig. 1 represent the unique and static speckle pattern in the illumination which can be priory acquired as a background image. Once the light passes through the shock wave, the speckle pattern gets distorted and displaced behind the object due to the shockwave refractive-index gradient, as schematically presented on the right-hand side of Fig. 1. Shortly before the shockwave is generated (e.g., typically 3 ms before the measurement) we acquire and store the background image. Subtracting the background from the shockwave image improves the overall SNR and yields the important change in the texture within the observed object. This way, we turn the laser speckles, often considered as undesired, into an advantage in the context of image processing.

Fig. 1
figure 1

Distortion of the static laser speckles pattern due to the light deviation

3 State of the art

We have acquired a dataset of 175 high-contrast images of shockwaves in water and 682 low-contrast shockwaves in air using the setup reported in Ref. [8]. From all images, acquired background is subtracted to improve SNR and to generate important image cues as described in Sect. 2. Three well-established state-of-the art methods have been employed to assess their potential for segmentation of shockwave images. The first method is simple image binarization employing Otsu’s automatic threshold [15] followed by morphological closing operation. the second method is hidden Markov Random Field segmentation followed by expectation maximization algorithm as proposed by Zhang et al. [16]. Markov random field is also basis for multiple state-of-the art segmentation algorithms such as GrowCut and GraphCut [17, 18]. The third algorithm is active contour introduced by Chan and Vese [19]. This is a reasonable choice for segmentation of low-contrast shockwave images since the edges are more likely to be less prominent there. The three algorithms have been implemented in Matlab and employed to segment both datasets. The obtained results (Fig. 2-upper row) show that the state-of-the art methods provide good segmentation results on majority (92 %) of high contrast images. The final contour of high-contrast shockwaves could be easily obtainable by an additional processing step such as morphological filtering and region boundary extraction. When applied to images with low-contrast shockwaves in gases, all 3 state-of-the-art methods failed to segment shockwaves in low-contrast images without any trace of success among 682 images (Fig. 2-lower row).

Fig. 2
figure 2

Comparison of state-of-the-art methods on typical high- and low-contrast shadowgraphs. Note the red outline showing the manual segmentation of trained human expert (color figure online)

Fig. 3
figure 3

Two-stage snake algorithm

Fig. 4
figure 4

a Original image; b image after background subtraction with arrows indicating the diffraction pattern; c texture image; d detected boundaries

As evident from extremely poor performance of the state-of-the-art methods, a domain specific approach is necessary to assure good shockwave segmentation in low-contrast images. Many new modifications of existing methods for low-contrast images were recently reported [2022], where none of them suit our need. In the following, we describe a domain-specific segmentation algorithm that incorporates the principles of image creation described in Sect. 2 to assure good segmentation performance.

4 Algorithm for automatic segmentation

To assure successful shockwave boundary detection, we choose a flexible framework for segmentation. Snakes and active contours have been already proved as prominent methods in a wide variety of applications and gain extreme attention due to their high flexibility and versatility [2325]. To facilitate understanding of the shock-segmentation method, we present here a brief overview of the active contours, i.e., snakes used hereafter. A detailed description and derivation of snakes can be found elsewhere [26, 27].

4.1 Active contours

Let \(s(p)=[x(p),y(p)]^T\) be the coordinates of a closed contour that encircles the object of interest. Here, \(p\) stands for the parameter running along the closed contour. As proposed by Kass et al. [26], the snake energy \(E\) consists of internal, \(E_{{int}}\), and external, \(E_{{ext}}\), energy as follows:

$$\begin{aligned} \alpha (p)s^{\prime \prime }(p)-\beta s^{(4)}(p)-\nabla E_{{ext}} (s(p))=0 \end{aligned}$$
(1)

Equation (1) is solved iteratively with gradient descent method as proposed by Kass et al. [26] using a finite difference approximation of the spatial derivatives.

Active contours offer a flexible framework in terms of energy definition. However, it is a great challenge to define a smooth and convex optimization function in a single step. To overcome non-convex optimization functions full of local minima, we try to mimic a human-hierarchical approach to boundary-segmentation problem. We propose a two-stage approach. Here, the first stage is inaccurate but globally robust. This stage is then followed by refining stage, which is globally not robust, but locally accurate. To achieve this, we propose the use of two different image cues in each stage. The first stage is regional-based segmentation, where texture cues are exploited to approximately segment the contour. The segmentation is then subsequently refined by second-stage, i.e., edge-based segmentation. Here, the contour is modified by employing the boundary information. Both stages incorporate active-contour algorithms, which are in detail presented in the following subsections. The entire algorithm is depicted in Fig. 3.

4.2 Coarse detection

The pre-acquired background image is first subtracted from every upcoming image (i) to increase the contrast between the object of interest, and (ii) to generate the texture differences, as described in Sect. 2. The diffraction pattern around shockwave remains visible after background subtraction (e.g., as evident in Fig. 4b), which obstruct the segmentation process. In order to avoid the diffraction effect, we exploit the texture cues that arise due to speckle displacement phenomena as mentioned in Sect. 2. This texture, although not obvious to human eye, is revealed by calculation of the image variance in regions of \(5 \times 5\) pixels. On the other hand, variance filtering also eliminates the diffraction pattern, as the diffraction lobes are homogenous features and region size is set small enough. As a result, the variance filtering yields a high-intensity region corresponding mainly to the shockwave (e.g., see Fig. 4c). Region-based segmentation, e.g., described by Ivins and Porrill [27], is usually applied for the segmentation task. We simplify their approach by crude direct definition of the external-energy gradient that is required for active contour formulation. Since we know that the object appears approximately in the center of the image \([x_c, y_c]\), we define the external-energy gradient at each pixel \([x,y]\) that points either towards or outwards the center and has a magnitude proportional to the image intensity drawn from the variance image \(I_{var}\):

$$\begin{aligned} {\nabla }E_{{ext}} (x,y)= \left\{ {\begin{array}{l@{\quad }l} -I_{{var}} \frac{{\mathop {v}\limits ^{\rightharpoonup }}}{\left\| {{\mathop {v}\limits ^{\rightharpoonup }}}\right\| };&{} I_{{var}} \ge I_{{thresh}} \\ (1-I_{{var}} )\frac{{\mathop {v}\limits ^{\rightharpoonup }}}{\left\| {{\mathop {v}\limits ^{\rightharpoonup }}} \right\| };&{} I_{{var}}<I_{{thresh}} . \\ \end{array}} \right. \end{aligned}$$
(2)

In Eq. (2), \({\mathop {v}\limits ^{\rightharpoonup }}=[x,x_c, y,y_c]\) stands for the orientation vector, and \(I_{\textit{thresh}}\) defines a threshold value, which decides whether the vector at some location pushes the snake towards the center or repels it away from the center. A very basic version of the snake algorithm is then launched using this external-energy gradient. The snake is initialized by an elliptic region, which is placed at the center of the image. By setting \(I_{\textit{thresh}}\) to be the Otsu’s threshold level [15], the snake is converging fast and yields good approximations to the shockwave contour. While the snake is evolving in the presence of weak external energies, the contour points may concentrate at certain location due to relatively high snake shrinkage (alpha). This is a common problem of snakes. In order to avoid these effects, we release the internal energies before entering the refinement stage. To achieve this, the snake is resampled equidistantly along the contour.

4.3 Fine segmentation

The extracted contour, obtained with the coarse detection stage, is close to desired shock contour. However, the local refinements are still necessary. For this purpose we use the Greedy-snake approach [28], where the contour is locally optimized to the shockwave boundary. Since the contrast at the edges of the shockwave is low and the edge is thin, classic gradient-based-edge detection yields poor results. In the literature, Hessian ridge detector is often applied for this task [29]. We use steerable filters [30] to detect ridges and extract their orientation. Here, we employ the Laplacian of Gaussian filters at three different scales with \((\sigma _u, \sigma _v )=\{ {(1,3),(2,6),(4,12)}\}\) At each scale, the filters are oriented at six different orientations. \(\theta =\{ {0,\pi /6,\pi /3,\pi , 2\pi /3,5\pi /6} \}\) By deriving the anisotropic Laplacian of Gaussian and introducing the coordinate rotation by an angle \(\theta \), we end up with

$$\begin{aligned} G(\sigma _u, \sigma _v, \theta )&=-\frac{1}{2\pi \sigma _u \sigma _v }\nonumber \\&\quad \times \bigg (-\frac{1}{\sigma _u^2 }-\frac{1}{\sigma _v^2 }-\frac{(x \cos \theta +y \sin \theta )^2}{\sigma _u^4 }\nonumber \\&\quad -\frac{(-x \sin \theta +y \cos \theta )^2}{\sigma _v^4}\bigg )\nonumber \\&\quad \times \exp \bigg \{ -\frac{1}{2}\bigg (\frac{(x \cos \theta +y \sin \theta )^2}{\sigma _u^2 }\nonumber \\&\quad +\frac{(-x\sin \theta +y \cos \theta )^2}{\sigma _v^2}\bigg ) \bigg \} \end{aligned}$$
(3)

Figure 5 shows the filter bank that was calculated from Eq. (3) using the parameters described above and constant filter window size of \(51 \times 51\) pixels.

Fig. 5
figure 5

Steerable filters calculated by Eq. (3)

Convolving the input image with steerable filters yields high responses at the thin black outline of the shock wave as shown in Fig. 4d. For efficient implementation to avoid the high computation costs, all convolutions were implemented by the use of Fourier transform. The filtered \(I(\sigma _u, \sigma _v, \theta )\) is then given as

$$\begin{aligned} I(\sigma _u, \sigma _v, \theta )=\mathcal {F}^{-1}\left\{ {\mathcal {F}\{I\}\mathcal {F}\{G(\sigma _x, \sigma _y, \theta )\}}, \right\} \end{aligned}$$
(4)

where \(\mathcal {F}\{\}\) and \(\mathcal {F}^{-1}\{\}\) denote the Fourier transform and its inverse, respectively. The image of detected boundaries (Fig. 4d) is determined by taking the maximum filter response at each pixel location. The orientation of this edge is drawn from the filter orientation \(\theta \) that yields that response:

$$\begin{aligned} \begin{array}{l} I_{\textit{edge}} =\max (I(\sigma _u, \sigma _v, \theta )) \\ \theta _{\textit{edge}} =\mathop {\arg \max }\limits _\theta (I(\sigma _u, \sigma _v, \theta ))\\ \end{array} \end{aligned}$$
(5)

Following the idea of Radeva and Serrat [31] that the snake should be attracted only to high-level edges with similar orientation to the snake tangent, we introduce the Bayesian formalism in order to combine boundary and orientation cues to a robust high-level detection. Boundary likelihood \(p(y_{\textit{bound}} \vert {\mathbf {X}})\) for a given position of the image \({\mathbf {X}}=[x,y]\) is constructed by simple normalization of \(I_{\textit{edge}}\). In order to construct the orientation likelihood \(p(y_{\textit{orient}} \vert {\mathbf {X}})\), the orientation \(\theta _{{edge}}\) is compared to the tangent orientation of the snake at every iteration. Orientation similarity measure is introduced for this task. Given the snake contour, the tangent angle at every node of contour is calculated by

$$\begin{aligned} \psi&=\mathrm{atan2}(\dot{y},\dot{x})\end{aligned}$$
(6)
$$\begin{aligned} \psi _{{ref}}&= {\left\{ \begin{array}{ll} \psi ; &{} \psi \le 0 \\ \psi +\pi ;&{} \psi >0 \\ \end{array}\right. }, \end{aligned}$$
(7)

where atan2() is the arctangens function defined on all four quadrants.

For similarity measure, a cosine function is introduced to weight edges with similar orientation to the starting curve and suppress edges with perpendicular orientation. The orientation likelihood is thus formulated as

$$\begin{aligned} p(y_{{orient}} \vert \mathbf {x})=\frac{1}{2}\vert \cos (\theta _{\textit{edge}} -\psi _{{ref}})\vert +\frac{1}{2}. \end{aligned}$$
(8)

Search of local optimum is accomplished by the Bayesian formalism. We want to combine the orientation likelihood \(p(y_{\textit{orient}} \vert {\mathbf {x}})\) with boundary likelihood \(p(y_{\textit{bound}} \vert {\mathbf {x}})\) to improve the detection. Assuming both likelihoods are independent, their joint likelihood can be formulated as

$$\begin{aligned} \begin{array}{l} p(y_{\textit{joint}} \vert {{\mathbf x}})=p(y_{{orient}}, y_{{bound}} \vert {{\mathbf x}}) \\ p(y_{\textit{orient}}, y_{{bound}} \vert {{\mathbf x}})=p(y_{\textit{orient}} \vert {{\mathbf x}})p(y_{{bound}} \vert {{\mathbf x}}).\\ \end{array} \end{aligned}$$
(9)

To make overall tracking with combined probability density functions less prone to failure, the Gaussian kernel with variance of 30 pixels is superimposed over the joint likelihood. This gives more weight to locations near current snake position and less to more distant one. The variance of the Gaussian kernel was optimized empirically and corresponds to the expected positional errors of coarse detection stage. Increasing or decreasing the variance of the kernel does, however, not affect the segmentation significantly.

The final joint likelihood can be then seen in Fig. 6c. Local maxima of the joint probability, the so-called Maximum A Posteriori (MAP), depicted with red cross in the Fig. 6c, is then used as the next most possible location \(x_{{map}}\)

$$\begin{aligned} x_{{map}} =\mathop {\max }\limits _x (p(y_{\textit{orient}}, y_{{bound}} \vert {{\mathbf x}})) \end{aligned}$$
(10)

Once the local optimum for each snake’s node \(s(p)\) has been determined, the snake is attracted to them. This procedure is iterated few times to obtain the global optimum of the snake’s energy. Performance of the proposed scheme has been found sufficient for the cases where shockwave boundaries are continuous, smooth, and visible. However, this is not the case in some parts of our shadowgraphic results. As is clearly visible from Fig. 4a, in our case the edge responses at upper and lower caps of the shockwave are weak with undeterminable orientation. This results in weak or erroneous external energies (e.g., the red springs in close-up window of Fig. 7). In such situations internal energies undertake the control of the snake’s shape which often yields unsatisfactory results as depicted with dotted line in close up window of Fig. 7. To alleviate this problem, we introduce additional external forces at both upper and lower parts of the curve (e.g., see the blue springs in Fig. 7).

Fig. 6
figure 6

Greedy search algorithm: a boundary likelihood with initial contour; b orientation similarity coded with color temperature; c joint likelihood with red cross representing the detected local optimum (color figure online)

Fig. 7
figure 7

Extension springs compensate external energies of Greedy snake. Left the red springs span between evolving snake and corresponding local maximum, while the blue springs span back to the texture based snake. Right the amplitude of the blue springs according to the angular position (color figure online)

The forces act as extension springs pulling the evolving snake towards to the initial texture snake. The stiffness of the springs \(k(\varphi )\) is given with superimposing two normalized Gaussian functions that have their centers at \(\pi /2\) and \(3\pi /2\), respectively (e.g., see Fig. 7). Thus, the external force of the \(p\)th node can be defined as

$$\begin{aligned} F_{\textit{MAP}}&=\max (p(y_{\textit{orient}}, y_{{bound}} \vert x))\vert \vert s_{\textit{evolv}}(p)-x_{{map}}(p)\vert \vert \end{aligned}$$
(11)
$$\begin{aligned} F_{\textit{prior}}&=\kappa (\varphi )\vert \vert s_{{init}} (p)-s_{{evolv}} (p)\vert \vert . \end{aligned}$$
(12)

The external energy is then formulated as a sum of the force towards local maxima \(F_{\textit{MAP}}\) and prior force \(F_{\textit{prior}}\) in no-contrast region. This way, the driving of the snake by sole internal energies or erroneous external energies is prevented.

5 Results and discussion

Our dataset consists of 682 images of low-contrast shockwaves acquired between 500 and 1500 \(\upmu \)s after laser-induced breakdown in air. Image size is \(1392\times 1040\) pixels. All images are first manually segmented by a trained expert, which last approximately 20 h. The manual segmentation involves manual selection of node points with subsequent B-spline interpolation, as described in [12]. It should be highlighted that low contrast and the presence of diffraction lobes seriously hinder the human perception. Manual segmentation is, therefore, not an easy task and may in many cases depend on operator interpretation. After segmentation all contours are equiangularly sampled to 80 contour points and transformed to polar coordinates [\(r, \varphi \)] with origin placed at the center of the image (as visible in the left-hand side of Fig. 9). The manually segmented curves serve as reference ground-truth and are used to evaluate the performance of the proposed automatic method. Once segmented, the dataset is divided into training and validation set. Since the optimization of algorithm involves tuning of several parameters simultaneously and whole algorithm takes 30 s to segment the image, the training set has been lowered to 50 images to avoid prolonged optimization. It turned out that 50 images were sufficiently representative dataset to optimize the algorithm. The validation set thus includes the remaining 632 image.

The algorithm of automatic segmentation has been implemented in Mathworks Matlab. The snake is initialized with the elliptical region with horizontal and vertical semi-axis being 450 and 650 pix, respectively. The snake comprises 80 equidistant points along the curve. The algorithm has been empirically optimized, such that \(\alpha \) and \(\beta \) and the number of iterations were manually varied until satisfactory performance on a training-set consisting of 50 images was obtained. Simple scalar metric derived from radial errors (e.g. RMS) is used to help us empirically determine the appropriate parameters. Good performance has been generally achieved with stiffer snake in the coarse step, while in refinement stage the internal energy is then somewhat lowered to achieve a more detailed contour (lower \(\beta \)). Final settings of the snake are represented in Table 1. The behavior of the algorithm is then fully determined by the obtained parameters (number of iterations, \(\alpha \) and \(\beta \)) which are kept constant in segmentation process.

Table 1 Snake settings

Figure 8 shows the iteration steps in both coarse (first row) and fine stages of detection (second row). As evident, the snake converges fast and outlines the contour approximately within the coarse stage of detection. In the refinement stage, its shape is altered to better match the shockwave boundaries.

Fig. 8
figure 8

Coarse (1–25) and fine stage (30–50) of shockwave segmentation. The number of iteration is shown in top left-hand side of each image

Fig. 9
figure 9

End results for typical successful (left) and failed segmentation (right) of the proposed method

The method has been verified on a validation set consisting of 632 images by comparing the automatically detected outlines with reference ones. This way, the discrepancy between the snake and the corresponding reference contour is estimated by observing the radius error \(r(\varphi )\) after both coarse and fine stages of segmentation. The obtained results are represented in Table 2. The final RMS evaluated on validation set obtained is 1.84 pix and standard deviation of radius error 2.5 pix.

Table 2 Results of complete detection

Figure 9 demonstrates a typical successful and failed segmentation from the validation set. As obvious from the right-hand side of Fig. 9, the highest errors occur at lower cap of the shockwave (i.e. subregion D), where the shockwaves pressure gradient and correlated texture contrast is significantly lower than elsewhere. This corresponds to the direction of the laser pulse as depicted in Fig. 1 and already pointed out by Gregorčič et al. [12]. Another region where high errors occur is the region of interference fringe (i.e. subregion C). Here, the error occurs especially due to poor coarse detection and since high responses of steerable filters may sometimes be present due to interference. Despite that, the segmentation algorithm maintains error to be less than 30 pix in problematic regions in worst case, while for the rest of the curve the error remains lower than 5 pix as visible from the right-hand side of Fig. 9.

The left-hand side of Fig. 10 present the histogram of radius errors of all nodes of all curves in validation set. It shows that the cases where segmentation may be considered less successful (e.g. as in the right-hand side of as in Fig. 9) are extremely rare. In addition to that, an angular dependency of errors has been studied. RMS of radial error as well as minimal and maximal errors has been determined for each angular position using the whole validation set. The results are presented in the right-hand side of Fig. 10. Regions C and D form Fig. 9 that are marked by red and green box in the right-hand side of Fig. 10, respectively, coincide well with the angular positions of extreme error values.

Fig. 10
figure 10

Left Histogram of radius error evaluated on validation set. Right Angular radius error evaluated on validation set

All in all, the segmentation was successful on all images, with good performance in comparison to manual segmentation technique reported in Ref. [12]. Taking this fact into account, we find the automatic segmentation method accurate, very robust, and also objective.

6 Conclusions

With the presented two-stage, active-contour-segmentation method we demonstrate a practicable and efficient solution for three common problems that occur in evaluation of laser shadowgraphs of weak shock phenomena in gases: (i) diffraction patterns, (ii) general lack of image contrast, and (iii) laser speckles. By exploiting different image cues, textures, and boundaries, the method enables fast, robust, accurate, and objective detection of the shockwave boundary. The performance of the algorithms has been trained on training set consisting of 50 shockwaves and tested on validation set of 632 manually segmented reference images. Good segmentation performance with RMS lower than 2 pix has been obtained. The method opens the way to the analysis of large datasets and thus opens new prospects for the examination of laser-induced shockwaves. Large datasets will enable additional improvements regarding the image processing by incorporation of higher level statistics, such as active shape models.