├── LICENSE
├── README.md
└── image_match
├── .idea
├── image_match.iml
├── inspectionProfiles
│ ├── Project_Default.xml
│ └── profiles_settings.xml
├── misc.xml
├── modules.xml
└── workspace.xml
└── image_match.py
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 KimJunho
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Image_match
2 | ## Find the original image of the converted image & Similarty between many images
3 | * Python implementation of [Libpuzzle algorithm papers](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.104.2585&rep=rep1&type=pdf)
4 | * Find similar images within 1 second (No matter how many images there are)
5 |
6 | ## Requirements
7 | * Python 3.5
8 | * [Elasticsearch 5.3.0](https://www.elastic.co/kr/downloads/elasticsearch)
9 | * image_match
10 | * numpy+mkl
11 | * scipy
12 |
13 | ## library download
14 | * [link](http://www.lfd.uci.edu/~gohlke/pythonlibs/)
15 |
16 | ## How to install the library
17 | Please follow the order
18 | ```bash
19 | use "pip install"
20 | 1. pip install elasticsearch
21 | 2. pip install scipy~.whl
22 | 3. pip install numpy+mkl~.whl
23 | 4. pip install image_match
24 | ```
25 |
26 | # Code (Similarity between 2 images)
27 | ```python
28 | from image_match.goldberg import ImageSignature
29 |
30 | gis = ImageSignature()
31 | a = gis.generate_signature(image_path_1)
32 | b = gis.generate_signature(image_path_2)
33 | print(gis.normalized_distance(a, b))
34 | ```
35 |
36 | If you want to get similarity between many images, See github code
37 |
38 | ## Reference
39 | * [image-match](http://image-match.readthedocs.io/en/latest/)
40 |
41 |
--------------------------------------------------------------------------------
/image_match/.idea/image_match.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/image_match/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
13 |
14 |
15 |
16 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/image_match/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
--------------------------------------------------------------------------------
/image_match/image_match.py:
--------------------------------------------------------------------------------
1 | from elasticsearch import Elasticsearch
2 | from image_match.elasticsearch_driver import SignatureES
3 | from PIL import Image
4 | from time import time
5 | import os
6 |
7 | def folder_make(folder) :
8 | if not os.path.isdir(folder) :
9 | os.mkdir(folder)
10 |
11 | es = Elasticsearch()
12 | ses = SignatureES(es)
13 | # Start Elastic search server
14 |
15 |
16 |
17 | extensions = (".png", ".jpg", ".jpeg", ".gif")
18 | original_image_folder = "C:/sample_image" # Folder where images are stored, that is, the original image is found here
19 | save_folder = "C:/test/save_folder" # Folder to save the original image of converted images
20 | folder_make(save_folder)
21 |
22 | converted_image = "C:/test/modified_image.jpg" # converted image
23 |
24 | '''
25 | # If you do not have a file stored on the elasticsearch server, you can run the following code.
26 |
27 | for(path, dir, files) in os.walk(original_image_folder) :
28 | for filename in files :
29 | path_file = os.path.join(path,filename)
30 | ext = os.path.splitext(filename)[1] # File extensions
31 | if ext in extensions :
32 | if(os.path.getsize(path_fil e) == 0) :
33 | pass
34 | else :
35 | ses.add_image(path_file) # save image to elastic search server
36 | # After saving, this part may not be executed.
37 | '''
38 |
39 | s = time()
40 | original_image = ses.search_image(converted_image)
41 | # Original images of the converted image are saved
42 | # If you want to search rotated photos, you can also change sess.search_image (crop_image, all_orientations = True)
43 | # If no options are added, only resize and cropped images are searched.
44 | # However, if you add an option, the search takes a little longer.
45 |
46 |
47 | elapsed = time() - s # Found in 0.3 ~ 0.7 seconds
48 | print(converted_image)
49 | print(elapsed)
50 | print(len(original_image))
51 | for i in range(len(original_image)) :
52 | image_path = original_image[i].get('path') # Path to the original image
53 | # At this time, the similarity value is extracted when "original_image[i].get('score')"
54 | image_path = image_path.replace('\\','/')
55 | img = Image.open(image_path).save(save_folder+"/"+image_path.split("/")[-1])
56 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------