An image forming apparatus including an optical writer in which positions of a plurality of light emitting element array units (2, 3) are different in a sub scanning direction, ends of the light emitting element array units overlap each other in a main scanning direction and the light emitting elements in the ends are used as joints, the image forming apparatus comprising: a print head control unit configured to sequentially form latent images of a plurality of test patterns on a photosensitive element by sequentially writing a plurality of test pattern data onto at least the light emitting elements in the ends of the two light emitting element array units adjacent to each other in the main scanning direction; a test pattern image forming unit configured to sequentially form a plurality of test pattern images on the photosensitive element by operating a developing device to develop the latent images of the plurality of test patterns; and a density detection unit configured to operate a density sensor so as to detect density of the plurality of test pattern images; characterized by a storage unit configured to store outputs of the density detection unit for the plurality of test pattern images; a number-of-overlap-pixels determination unit configured to determine number of the light emitting elements overlapping at the ends based on a pattern of change in the outputs stored in the storage unit; and a joint pixel determination unit configured to determine joint pixels of the two light emitting element array units depending on a result of determination of the number-of-overlap-pixels determination unit, wherein the plurality of test pattern data are configured to cause the light emitting elements of one of the two light emitting element array units to operate such that a predetermined number of turned on light emitting elements and a predetermined number of turned off light emitting elements are alternately and repeatedly arranged, and cause the light emitting elements of another of the two light emitting element array units to operate such that the predetermined number of the turned on light emitting elements and the predetermined number of the turned off light emitting elements are alternately and repeatedly arranged, and positions of the turned on light emitting elements and the turned off light emitting elements of the other of the two light emitting element array units are sequentially shifted for each of the plurality of test patterns. a print head control unit configured to sequentially form latent images of a plurality of test patterns on a photosensitive element by sequentially writing a plurality of test pattern data onto at least the light emitting elements in the ends of the two light emitting element array units adjacent to each other in the main scanning direction; a test pattern image forming unit configured to sequentially form a plurality of test pattern images on the photosensitive element by operating a developing device to develop the latent images of the plurality of test patterns; and a density detection unit configured to operate a density sensor so as to detect density of the plurality of test pattern images; characterized by a storage unit configured to store outputs of the density detection unit for the plurality of test pattern images; a number-of-overlap-pixels determination unit configured to determine number of the light emitting elements overlapping at the ends based on a pattern of change in the outputs stored in the storage unit; and a joint pixel determination unit configured to determine joint pixels of the two light emitting element array units depending on a result of determination of the number-of-overlap-pixels determination unit, wherein the plurality of test pattern data are configured to cause the light emitting elements of one of the two light emitting element array units to operate such that a predetermined number of turned on light emitting elements and a predetermined number of turned off light emitting elements are alternately and repeatedly arranged, and cause the light emitting elements of another of the two light emitting element array units to operate such that the predetermined number of the turned on light emitting elements and the predetermined number of the turned off light emitting elements are alternately and repeatedly arranged, and positions of the turned on light emitting elements and the turned off light emitting elements of the other of the two light emitting element array units are sequentially shifted for each of the plurality of test patterns.