Groupwise registration has received more and more attention in the area of medical image analysis, due to its importance in analysis of population data. One popular way for groupwise registration is to alternatively estimate the group mean image and register all subject images to the estimated group mean. However, for achieving better registration performance, it is important to always keep the sharpness of the group mean image during the registration, which has not been well investigated yet in the literature. To achieve this, we propose to treat each aligned subject, as well as its anatomical regions, differently when constructing the group mean image. Specifically, we propose a new objective function to generalize the conventional groupwise registration method by using a dynamic weighting strategy to weight adaptively across subjects and spatial regions, to construct a sharp group mean image in each stage of registration. By integrating this strategy into diffeomorphic demons algorithm, the performance of our groupwise registration can be significantly improved, compared to the conventional groupwise registration method that starts with a fuzzy group mean image.