1. An image generation device comprising: a projection unit for projecting pattern light of a prescribed wavelength into an imaged space; an imaging unit for imaging the imaged space; a separation unit for separating a projected pattern image component from an imaging signal obtained by imaging by the imaging unit by taking a difference between the imaging signal obtained when the pattern light is projected and the imaging signal obtained when the pattern light is not projected; and a distance information generation unit for generating distance information on a basis of a projected image component separated by the separation unit; wherein the distance information generation unit determines projection angles of light spots in the imaged projected pattern from an arrangement of the light spots in the projected image represented by the projected image component and a prestored relationship between the projection angles and positions of the light spots in the projected pattern, and determines a distance to a surface of an imaged object onto which the light spots are projected on a basis of the projection angles thus determined; the pattern light projected from the projection unit includes a plurality of cells, each in an on state or an off state, forming an identification code accompanying each light spot; the distance information generation unit determines the positions of the light spots accompanied by the identification codes in the projected pattern on a basis of the identification codes; the identification code accompanying each light spot has a first part comprising a plurality of cells, aligned in a first direction in the projected pattern, and disposed on one side of the light spot in a second direction in the projected pattern, and a second part comprising a plurality of cells, aligned in the second direction, and disposed on one side of the light spot in the first direction; the identification codes accompanying the light spots that are adjacent in the first direction have at most one location at which the cells constituting the second parts of the identification codes change from the on state to the off state or from the off state to the on state; and the first parts of the identification codes accompanying the light spots that are adjacent in the second direction are mutually identical; wherein the imaging unit has an optical filter having transmission characteristics in a visible wavelength band and a wavelength of the pattern light, with transmittance in the visible wavelength band being lower than at the wavelength of the pattern light; the separation unit separates the projected image component from the imaging signal obtained by imaging by the imaging unit by taking a difference between the imaging signal obtained when the pattern light is projected and the imaging signal obtained when the pattern light is not projected; and the transmission characteristics of the optical filter are determined such that the difference has a value equal to or greater than a prescribed number of gradation levels of the imaging signal.