Based on the non-equilibrium Green's function formalism and spin-polarized density functional theory calculations, we investigate the spin transport properties of HDI and terahydrotetraazahexacene diimide (4H-TAHDI) with two ferromagnetic zigzag-edge graphene nanoribbon electrodes. Compared with HDI, four carbon atoms in the hexacene part of 4H-TAHDI are substituted by nitrogen atoms. The results show that the nitrogen substitution can improve significantly the spin-filtering performance and 4H-TAHDI can be used as a perfect spin filter. Our study indicates that suitable chemical substitution is a possible way to realize high-efficiency spin filters.