To develop a quantitative analysis method for right diaphragm deformation. This method is based on optical flow and applied to diaphragm ultrasound imaging. This study enrolls six healthy subjects and eight patients under mechanical ventilation. Dynamic images with 3–5 breathing cycles were acquired from three directions of right diaphragm by a portable ultrasound system. Filtering and density clustering algorithms are used for denoising Digital Imaging and Communications in Medicine (DICOM) data. An optical flow based method is applied to track movements of the right diaphragm. An improved drift correction algorithm is used to optimize the results. The method can automatically analyze the respiratory cycle, inter-frame/cumulative vertical and horizontal displacements, and strain of the input right diaphragm ultrasound image. The optical-flow-based diaphragm ultrasound image motion tracking algorithm can accurately track the right diaphragm during respiratory motion. There are significant differences in horizontal and vertical displacements in each section (p-values<0.05 for all). Significant differences are found between healthy subjects and mechanical ventilation patients for both horizontal and vertical displacements in Section III (p-values<0.05 for both). There is no significant difference in global strain in each section between healthy subjects and mechanical ventilation patients (p-values>0.05 for all). The developed method can quantitatively evaluate the inter-frame/cumulative displacement of the diaphragm in both horizontal and vertical directions, as well as the global strain in three different imaging planes. The above indicators can be used to evaluate diaphragmatic dynamics.