Numerical simulations were performed to study the effect of composition gradient and obstacle arrangement on detonation initiation in fuel-rich hydrogen-air mixtures. A third-order WENO method with adaptive mesh refinement (AMR) was used to solve the unsteady, fully-compressible, reactive Navier-Stokes equations coupled to a calibrated chemical-diffusive model (CDM). An obstructed channel at a blockage ratio of 0.3 filled with non-uniform hydrogen-air mixtures of an average H2 concentration 50 vol% was considered. The results show that unilateral obstacle arrangement is more conducive to flame acceleration (FA) and DDT than bilateral obstacle arrangement for both homogeneous and inhomogeneous mixtures. For inhomogeneous mixtures, the flame accelerates faster, and the detonation onset time is shorter when obstacles are placed on the sidewall with a hydrogen concentration closer to the stoichiometric ratio than the those when obstacles are placed on the other sidewall. However, the placement of unilateral obstacles on either the upper or lower sidewall does not significantly affect the DDT run-up distance. Besides, for fuel-rich inhomogeneous hydrogen-air mixtures, detonation tends to be initiated in the regions of high H2 concentration. Idealized models were introduced to simplify the intricate interactions of the reaction waves and flow fields to better understand the connection between H2 concentration distribution and detonation initiation. The analysis suggests that the minimum shock strength required for detonation initiation decreases with increasing equivalence ratio. This is supported by a kinetics analysis with detailed reaction model, which shows that ignition delay increases with decreasing equivalence ratio when detonation is about to be initiated.