The invention provides an image processing apparatus capable of reliably
and quickly retrieving, from an image, a pattern ("a layout pattern")
including a plurality of elements and being specified based on the
relative layout information among the elements. To retrieve the pattern
from the image, the apparatus first detects two elements of the specific
pattern giving a maximum distance therebetween, specifies positions where
the other elements composing the layout pattern together with the two
elements should be present based on the positional relationship between
the two elements, and recognizes the layout pattern in the image when the
other elements are accurately detected in the specified positions.