A path detection-use graph structure is generated based on a plurality of nodes representing the plurality of linear structures, and a path that is included in the generated path detection-use graph structure and connects a plurality of root nodes representing points of origin of the plurality of linear structures to each other is detected. Then, based on a predetermined condition representing a feature of an erroneous connection edge erroneously connecting two nodes that are to belong to different graph structures to each other, a connection cost is set for each of edges forming the path so that the erroneous connection edge is hard to connect, and based on the set connection costs, the plurality of graph structures corresponding respectively to the plurality of linear structures are generated.