(IJACSA) International Journal of Advanced Computer Science and Applications, Vol. 6, No. 3, 2015 77 | Page www.ijacsa.thesai.org Jigsopu: Square Jigsaw Puzzle Solver with Pieces of Unknown Orientation Abdullah M. Moussa Electrical Engineering Department Faculty of Engineering Port-Said University, Port-Said, Egypt Abstract—In this paper, we consider the square jigsaw puzzle problem in which one is required to reassemble the complete image from a number of unordered square puzzle pieces. Here we focus on the special case where both location and orientation of each piece are unknown. We propose a new automatic solver for such problem without assuming prior knowledge about the original image or its dimensions. We use an accelerated edge matching based greedy method with combined compatibility measures to provide fast performance while maintaining robust results. Complexity analysis and experimental results reveal that the new solver is fast and efficient. Keywords—jigsaw puzzle; image merging; edge matching; jigsaw puzzle assembly; automatic solver I. INTRODUCTION It is generally accepted that the first modern jigsaw puzzle was built in 1760 by London map maker John Spilsbury for educational purposes [1]. Since then, several different manufacturers around the world are manufacturing jigsaw puzzles in many shapes, sizes and piece types. The jigsaw puzzle is provably technically challenging. It has been shown by Demaine et al. [2] that the jigsaw puzzle problem is NP- complete in the general case when the pairwise affinity of jigsaw pieces is unreliable. The computational problem of jigsaw puzzle assembly was first introduced nearly fifty years ago in a fundamental work by Freeman and Gardner [3]. In addition to being an interesting problem in its own right, the computational jigsaw assembly has many applications in recovering shredded documents or photographs [4, 5, 6, 7], reassembling archaeological artifacts [8], DNA/RNA modeling [9] and speech descrambling [10]. Many attempts have been made to handle the problem. Several papers [11, 12] assume using classic jigsaw pieces with distinct shapes, and focus on matching the shape of the pieces to solve the puzzle. Some others use both of image contents and boundary shape [13, 14, 15]. In this paper, we follow the lead of recent work [16, 17, 18] and consider jigsaw puzzles with square pieces. We believe that assuming prior knowledge about the dimensions of the complete image of the puzzle pieces, as what the majority of the existing algorithms do, can reduce the applicability of the algorithm used. So, we relax the condition that the dimensions of the complete image should be previously known. We focus on the special case where both location and orientation of each piece are unknown. We present a new fast algorithm to tackle such problem. Our algorithm, named JigSoPU (Jigsaw Solver with Pieces of Unknown orientation), uses an edge matching based greedy technique along with a combined compatibility score functions to provide an accelerated performance while maintaining robust results. Complexity analysis and experimental results show that the new algorithm is fast and efficient. The rest of the paper is organized as follows: Section II introduces the new jigsaw assembly algorithm. Section III presents the complexity analysis of the proposed algorithm. In Section IV the experimental results are presented. Finally, conclusions are summarized in Section V. II. ALGORITHM DESCRIPTION To solve the square jigsaw puzzle problem, we need to consider two aspects, a criterion of compatibility between jigsaw pair of pieces, and a specific strategy to assemble the pieces. In section II-A, we will present the compatibility measure used, and in section II-B the new edge matching based assembly strategy will be proposed. A. Pairwise Compatibility Criterion When the jigsaw puzzle is correctly assembled, it can be observed that the adjoining pieces have often adjacent edges with pixels of similar intensity values. Such feature is the base of jigsaw edge matching based solvers. Common dissimilarity measures can be used to calculate the minimum difference between the pixels of pieces' edges in search of the best match between two candidate pieces. However, depending on a single dissimilarity measure may make the algorithm getting trapped in an incorrect assembly. So, we propose to use a combined measure that jointly minimizes the mean value of SAD (sum of absolute difference) of candidate adjacent edges along with the amount of pixel pairs that have a SAD value above a predefined threshold. We found experimentally that using the proposed combined compatibility functions is efficient enough to even handle color images after converting them to grayscale versions without a need to deal with each color channel alone. B. Assembly Strategy In this section, we introduce the new edge matching based greedy assembly algorithm. The algorithm is inspired by the FRoTeMa algorithm [19, 20] for template matching. Exhaustive matching of edges in search of the complete image should be robust, but it is not efficient in time because such procedure will have a complexity of where is the number of edges. This costly complexity makes the exhaustive matching procedure difficult to be applied to large jigsaw