Since real-time 4D dynamic magnetic resonance imaging (dMRI) methods with adequate spatial and temporal resolution for imaging the pediatric thorax are currently not available, free-breathing slice acquisitions followed by appropriate 4D construction methods are currently employed. Self-gating methods, which extract breathing signals only from image information without any external gating technology, have much potential for this purpose, such as for use in studying pediatric thoracic insufficiency syndrome (TIS). Patients with TIS frequently suffer from extreme malformations of the chest wall, diaphragm, and spine, leading to breathing that is very complex, including deep or shallow respiratory cycles. Existing 4D construction methods cannot perform satisfactorily in this scenario, and most are not fully automatic, requiring manual interactive operations. In this paper, we propose a novel fully automatic 4D image construction method based on an image-derived concept called flux to address these challenges. We utilized 25 dMRI data sets from 25 pediatric subjects with no known thoracic anomalies and 58 dMRI data sets from 29 patients with TIS where each patient had a dMRI scan before and after surgery. A time sequence of 80 slices are acquired at each sagittal location continuously at a rate of ~480ms per slice under free-breathing conditions, with 30-40 sagittal locations across the chest for each subject depending on the thoracic size. In our approach, we first extract the breathing signal for each sagittal location based on the flux of the optical flow vector field of the body region from the image time series. Here, for each time point of respiratory phase, the net flux of the body region can be regarded as the flux going into or out of the body region, which we term Optical Flux (OFx). OFx provides a very robust representation of the real breathing motion of the thorax. OFx allows us to perform a full analysis of all respiratory cycles, extract only normal cycles in a robust manner, and map all extracted normal cycles on to one cosine respiration model for each sagittal location. Subsequently, we re-sample one normal cycle from the respiration model for each location independently. The normal cycle models associated with the different sagittal locations are finally composited to form the final constructed 4D image. We employ several metrics to evaluate the quality of the 4D construction results: Eie - error in locating time instants corresponding to end inspiration and end expiration; Eto - deviation from correct temporal order in each detected normal cycle; Ess - deviation in spatial smoothness; and Esc - deviation from spatial continuity as scored by a reader. The means and standard deviations of these metrics for normal subjects and TIS patients are found to be, respectively: Eie: 0.25±0.05 and 0.38±0.16 in units of time instance (ideal value=0); Eto: 2.7% ± 2.3% and 1.8%±2% (ideal value=0%); Ess: 0.5±0.17 and 0.54±0.25 in pixel units (ideal value=0); Esc: 4.6±0.48 and 4.56±0.98 (score range: best=5, worst=1). The results show that the OFx method achieves excellent spatial and temporal continuity and its yield was 100% meaning that it successfully performed 4D construction on every data set tested. Compared to a recently published method, OFx is fully automatic requiring about 5min of computational time per study starting from acquired dMRI scans. The method achieves high temporal and spatial continuity even on complex TIS data sets that include many abnormal respiratory cycles. A new 4D dMRI construction method based on the concept of optical flux is presented which is fully automatic and very robust in deriving respiratory signals purely from dynamic image sequences even when presented with complex breathing patterns due to severe disease conditions like TIS. Evaluations show that its accuracy is comparable to the variations found in manual annotations. An important characteristic of the method is that it is independent of the number of sagittal locations used in the construction process, which suggests that it is applicable to imaging techniques where data are acquired at only a few sagittal locations instead of the full width of the thorax. The method is not tied to any specific imaging modality, as demonstrated in this paper on not just dMRI but dynamic computed tomography (CT) as well.