In RD1-RD8 in the most upstream lateral-end detecting process RB3, the pixel positions, which are apart from one another for the predetermined quantity of pixels in the range between the objective position TMDP, in which no edge was detected, and the foremost pixel position, are appointed intermittently upstream along the main-scanning direction MD as the objective positions TMDP. In RD2, RD3, and RD7, when the edge is detected in the objective position TMDP, the continuity count value CCT is incremented by 1; or when no edge is detected in the objective position TMDP, a value 0 is set in the continuity count value CCT. In RD4-RD5, when the continuity count value CCT indicates 3 or a larger value, the objective position TMDP, which caused the continuity count value CCT to be greater than or equal to 3, and the edge position EP in terms of the conveying direction FD associated with the objective position TMDP are saved as the most upstream lateral-end position USP. The most downstream lateral-end position DSP is detected in the similar manner as the most upstream lateral-end position detecting process RE3. Thus, the objective positions TMDP, which caused the continuity count value CCT to be greater than or equal to 3, are saved as the most upstream lateral-end position USP and the most downstream lateral-end position DSP respectively. Therefore, even if an edge is erroneously detected due to influence of a noise or an obstacle, the upstream lateral position USP and the most downstream lateral-end position DSP may be detected correctly.