A non-transitory computer-readable medium storing computer-readable instructions that are executable by a processor coupled with an image scanner, the image scanner comprising:
- a document table configured to support a rectangular sheet placed thereon, the document table having a specific position thereon where one of four corners of the sheet is placed as a reference corner;
- an image sensor configured to repeatedly perform line scanning to scan the sheet placed on the document table in a main scanning direction while moving in a sub scanning direction perpendicular to the main scanning direction, thereby generating image data representing a scanned image of the sheet;
- and
- a binarizer configured to binarize the image data generated by the image sensor, the instructions being configured to, when executed by the processor, cause the processor to:
- receive first image data from the binarizer, the first image data being generated by binarizing image data generated by the image sensor repeatedly performing the line scanning a particular number of times while moving in the sub scanning direction from a scanning start position;
- detect a first position of a lateral side of the sheet within a first scanned image represented by the received first image data, the lateral side extending in the sub scanning direction from a non-reference corner of the sheet, the non-reference corner being opposed to the reference corner across an upper side of the sheet in the main scanning direction, the upper side extending in the main scanning direction from the reference corner;
- calculate an inner black pixel density and an outer black pixel density based on the first image data, the inner black pixel density being a density of black pixels in an inner particular area, the outer black pixel density being a density of black pixels in an outer particular area, the inner particular area and the outer particular area being defined with the detected first position of the lateral side as a boundary therebetween;
- set a plurality of thresholds based on the calculated inner black pixel density and the calculated outer black pixel density;
- each time the image sensor repeatedly performs the line scanning a predetermined number of times while moving in the sub scanning direction, perform an edge detecting process to detect a second position of the lateral side by detecting a document edge corresponding to the lateral side in the main scanning direction within a second scanned image represented by second image data received from the binarizer, the second image data being generated by binarizing image data generated by the line scanning repeated the predetermined number of times;
- in the edge detecting process performed for a first time, set a reference position based on the detected first position of the lateral side;
- in the edge detecting process performed for a second or later time, set the reference position based on the second position of the lateral side detected in a previous edge detecting process;
- and
- in each edge detecting process, perform:
- defining a detection range on the basis of the set reference position;
- selecting a target area from among a plurality of areas within the defined detection range, in ascending order of distance between an area to be selected as the target area and the reference position;
- determining whether the selected target area is a document outside area, a document inside area, or a document edge area, by comparing a black pixel density of the target area with the plurality of thresholds;
- in response to determining that the target area is the document outside area or the document inside area, selecting one or more new target areas from among the plurality of areas within the detection range;
- and
- in response to determining that the target area is the document edge area, detecting a specific position in the target area as the second position of the lateral side.