We aimed to longitudinally examine the relationship between depression and cognitive function and investigate the mediating effects of imaging indicators in this relationship. 2,251 subjects with longitudinal assessment of geriatric depression scale, Mini-Mental State Examination, Montreal Cognitive Assessment, Clinical Dementia Rating-Sum of Boxes (CDRSB), Alzheimer's Disease Assessment Scale11, Alzheimer's Disease Assessment Scale13 and imaging of 3DT1, diffusion tensor imaging, fluid-attenuated inversion recovery, arterial spin labeling, fluorodeoxyglucose positron emission tomography, 18F-AV45-PET, and 18F-AV1451-PET were included from the Alzheimer's Disease Neuroimaging Initiative database. The multivariate mixed-effects models were employed to analyze the correlation between geriatric depression scale scores, cognitive function, and imaging indicators. The sgmediation software package was utilized to analyze the mediating effects of imaging indicators. The geriatric depression scale was negatively correlated with Mini-Mental State Examination and Montreal Cognitive Assessment, and positively correlated with CDRSB, Alzheimer's Disease Assessment Scale11, and Alzheimer's Disease Assessment Scale13 when the subjects were not grouped. The geriatric depression scale was negatively correlated with Montreal Cognitive Assessment and positively correlated with Alzheimer's Disease Assessment Scal13 in groups with baseline diagnosis of early mild cognitive impairment and late mild cognitive impairment. Furthermore, depression was associated with regional imaging indicators, while cognitive function was linked to broad imaging indicators. Some of these indicators were related to both depression and cognitive function, playing a mediating role in their relationship. Depression was related to cognitive function, especially in subjects with mild cognitive impairment. Some imaging indicators may represent the underlying basis for the association between depression and cognitive function.