-
-
Save isagalaev/4554182 to your computer and use it in GitHub Desktop.
Revisions
-
isagalaev revised this gist
Jan 17, 2013 . 1 changed file with 3 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,6 @@ #!/usr/bin/env python # coding: utf-8 import os import random import glob @@ -39,7 +36,7 @@ def duplicates(dirname): """ files = glob.glob(os.path.join(dirname, '*.jpg')) images = [(f, image_data(f)) for f in files] random.shuffle(images) for filename, data in images: distances = [(distance(data, d), f) for f, d in images] @@ -60,7 +57,4 @@ def html(groups): if __name__ == '__main__': print(html(duplicates('/home/maniac/Desktop/4554182'))) -
isagalaev revised this gist
Jan 17, 2013 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,7 +23,7 @@ def image_data(filename): Get data from image ready for comparison """ img = Image.open(filename).resize((BLOCK_SIZE, BLOCK_SIZE), Image.BILINEAR) return numpy.array([sum(x) for x in img.getdata()]) def distance(data1, data2): """ @@ -38,7 +38,7 @@ def duplicates(dirname): Returns an iterator of image groups ([], [], ... []) """ files = glob.glob(os.path.join(dirname, '*.jpg')) images = [(f, image_data(f)) for f in files] # random.shuffle(images) for filename, data in images: -
isagalaev revised this gist
Jan 17, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -46,7 +46,7 @@ def duplicates(dirname): yield sorted([(dist, f) for dist, f in distances if dist < MAX_DISTANCE]) def html_group(group): return ''.join( '<img src="%s" width="%s"/>%s' % (os.path.basename(f), WIDTH, dist) for dist, f in group ) -
isagalaev revised this gist
Jan 17, 2013 . 1 changed file with 3 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -55,15 +55,12 @@ def html(groups): """ Generates HTML from groups of image duplicates """ body = '<hr/>'.join(html_group(g) for g in groups) return '<html><body>%s<hr/></body></html>' % body if __name__ == '__main__': reference = open('reference.html').read() result = html(duplicates('/home/maniac/Desktop/4554182')) + '\n' print(reference.replace('\n', '') == result.replace('\n', '')) # print(html(duplicates('/home/maniac/Desktop/4554182'))) -
isagalaev revised this gist
Jan 17, 2013 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -55,12 +55,12 @@ def html(groups): """ Generates HTML from groups of image duplicates """ body = '\n<hr/>\n'.join(html_group(g) for g in groups) return '''<html><body> %s <hr/> </body></html>''' % body if __name__ == '__main__': reference = open('reference.html').read() -
isagalaev revised this gist
Jan 17, 2013 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -56,9 +56,8 @@ def html(groups): Generates HTML from groups of image duplicates """ res = ['<html><body>'] res += ['\n<hr/>\n'.join(html_group(g) for g in groups)] res += ['<hr/>'] res += ['</body></html>'] return '\n'.join(res) -
isagalaev revised this gist
Jan 17, 2013 . 1 changed file with 8 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -45,15 +45,19 @@ def duplicates(dirname): distances = [(distance(data, d), f) for f, d in images] yield sorted([(dist, f) for dist, f in distances if dist < MAX_DISTANCE]) def html_group(group): return '\n'.join( '<img src="%s" width="%s"/>%s' % (os.path.basename(f), WIDTH, dist) for dist, f in group ) def html(groups): """ Generates HTML from groups of image duplicates """ res = ['<html><body>'] for group in groups: res += [html_group(group)] res += ['<hr/>'] res += ['</body></html>'] @@ -63,3 +67,4 @@ def html(groups): reference = open('reference.html').read() result = html(duplicates('/home/maniac/Desktop/4554182')) + '\n' print(reference == result) # print(html(duplicates('/home/maniac/Desktop/4554182'))) -
isagalaev revised this gist
Jan 17, 2013 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -42,8 +42,8 @@ def duplicates(dirname): # random.shuffle(images) for filename, data in images: distances = [(distance(data, d), f) for f, d in images] yield sorted([(dist, f) for dist, f in distances if dist < MAX_DISTANCE]) def html(groups): """ @@ -53,7 +53,7 @@ def html(groups): for group in groups: res += [ '<img src="%s" width="%s"/>%s' % (os.path.basename(f), WIDTH, dist) for dist, f in group] res += ['<hr/>'] res += ['</body></html>'] -
isagalaev revised this gist
Jan 17, 2013 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -42,7 +42,8 @@ def duplicates(dirname): # random.shuffle(images) for filename, data in images: distances = [(distance(data, d), f, d) for f, d in images] yield sorted([(dist, f, d) for dist, f, d in distances if dist < MAX_DISTANCE]) def html(groups): """ @@ -52,7 +53,7 @@ def html(groups): for group in groups: res += [ '<img src="%s" width="%s"/>%s' % (os.path.basename(f), WIDTH, dist) for dist, f, d in group] res += ['<hr/>'] res += ['</body></html>'] -
isagalaev revised this gist
Jan 17, 2013 . 1 changed file with 13 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -31,27 +31,34 @@ def distance(data1, data2): """ return sum(1 for x in data1 - data2 if abs(x) > THRESHOLD) def duplicates(dirname): """ Finds duplicate images in a directory. All files must be *.jpg. Returns an iterator of image groups ([], [], ... []) """ files = glob.glob(os.path.join(dirname, '*.jpg')) images = [image_data(f) for f in files] # random.shuffle(images) for filename, data in images: yield sorted([(distance(data, d), f, d) for f, d in images]) def html(groups): """ Generates HTML from groups of image duplicates """ res = ['<html><body>'] for group in groups: res += [ '<img src="%s" width="%s"/>%s' % (os.path.basename(f), WIDTH, dist) for dist, f, d in group if dist < MAX_DISTANCE] res += ['<hr/>'] res += ['</body></html>'] return '\n'.join(res) if __name__ == '__main__': reference = open('reference.html').read() result = html(duplicates('/home/maniac/Desktop/4554182')) + '\n' print(reference == result) -
isagalaev revised this gist
Jan 17, 2013 . 1 changed file with 9 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,13 +6,16 @@ # import os import random import glob from PIL import Image import numpy BLOCK_SIZE = 20 THRESHOLD = 60 WIDTH = 200 MAX_DISTANCE = 220 def image_data(filename): @@ -33,18 +36,16 @@ def html(dirname): Generates HTML from a set of images in a directory. All files must be *.jpg. """ files = glob.glob(os.path.join(dirname, '*.jpg')) images = [image_data(f) for f in files] # random.shuffle(images) res = ['<html><body>'] for filename, data in images: distances = sorted([ (distance(data, d), f, d) for f, d in images ]) res += [ '<img src="%s" width="%s"/>%s' % (os.path.basename(f), WIDTH, dist) for dist, f, d in distances if dist < MAX_DISTANCE] res += ['<hr/>'] res += ['</body></html>'] -
isagalaev revised this gist
Jan 17, 2013 . 1 changed file with 3 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import os import random from PIL import Image import numpy @@ -19,15 +19,8 @@ def image_data(filename): """ Get data from image ready for comparison """ img = Image.open(filename).resize((BLOCK_SIZE, BLOCK_SIZE), Image.BILINEAR) return filename, numpy.array([sum(x) for x in img.getdata()]) def distance(data1, data2): """ -
isagalaev revised this gist
Jan 17, 2013 . 1 changed file with 22 additions and 31 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -35,38 +35,29 @@ def distance(data1, data2): """ return sum(1 for x in data1 - data2 if abs(x) > THRESHOLD) def html(dirname): """ Generates HTML from a set of images in a directory. All files must be *.jpg. """ images = \ [image_data(os.path.join(dirname, filename)) \ for filename in os.listdir(dirname) if filename.endswith('.jpg')] # random.shuffle(images) res = ['<html><body>'] for img in images: distances = sorted([ (distance(img[1], x[1]), x) for x in images ]) res += [ '<img src="' + os.path.basename(x[0]) + '" width="200"/>' + str(dist) for dist, x in distances if dist < 220] res += ['<hr/>'] res += ['</body></html>'] return '\n'.join(res) if __name__ == '__main__': reference = open('reference.html').read() result = html('/home/maniac/Desktop/4554182') + '\n' print(reference == result) -
isagalaev revised this gist
Jan 17, 2013 . 1 changed file with 18 additions and 16 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,23 +15,25 @@ THRESHOLD = 60 def image_data(filename): """ Get data from image ready for comparison """ filename = filename img = pImage.open(filename) small = img.resize( (BLOCK_SIZE, BLOCK_SIZE), pImage.BILINEAR ) t_data = numpy.array( [sum(list(x)) for x in small.getdata()] ) del img, small return filename, t_data def distance(data1, data2): """ Logical distance between two images on a scale 0..400 """ return sum(1 for x in data1 - data2 if abs(x) > THRESHOLD) class ImageList: """List of images information, built from directory. @@ -42,7 +44,7 @@ def __init__(self, dirname): def load(self): self.images = \ [image_data(os.path.join(self.dirname, filename)) \ for filename in os.listdir(self.dirname) if filename.endswith('.jpg')] # random.shuffle(self.images) @@ -54,9 +56,9 @@ def __repr__(self): def html(self): res = ['<html><body>'] for img in self.images: distances = sorted([ (distance(img[1], x[1]), x) for x in self.images ]) res += [ '<img src="' + os.path.basename(x[0]) + '" width="200"/>' + str(dist) for dist, x in distances if dist < 220] res += ['<hr/>'] res += ['</body></html>'] -
isagalaev revised this gist
Jan 17, 2013 . 1 changed file with 16 additions and 19 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,40 +1,37 @@ #!/usr/bin/env python # coding: utf-8 # # Video of this screencast: https://vimeo.com/57296525 # # import os import random from PIL import Image as pImage import numpy BLOCK_SIZE = 20 THRESHOLD = 60 class Image: """Take an information from image file""" def __init__(self, filename): self.filename = filename img = pImage.open(self.filename) small = img.resize( (BLOCK_SIZE, BLOCK_SIZE), pImage.BILINEAR ) self.t_data = numpy.array( [sum(list(x)) for x in small.getdata()] ) del img, small def distance(self, other): """ Logical distance between two images on a scale 0..400 """ return sum(1 for x in self.t_data - other.t_data if abs(x) > THRESHOLD) class ImageList: """List of images information, built from directory. @@ -45,7 +42,7 @@ def __init__(self, dirname): def load(self): self.images = \ [Image(os.path.join(self.dirname, filename)) \ for filename in os.listdir(self.dirname) if filename.endswith('.jpg')] # random.shuffle(self.images) @@ -57,7 +54,7 @@ def __repr__(self): def html(self): res = ['<html><body>'] for img in self.images: distances = sorted([ (distance(img, x), x) for x in self.images ]) res += [ '<img src="' + os.path.basename(x.filename) + '" width="200"/>' + str(dist) for dist, x in distances if dist < 220] -
isagalaev revised this gist
Jan 17, 2013 . 1 changed file with 8 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,9 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # # Video of this screencast: https://vimeo.com/57296525 # # from __future__ import print_function, division, absolute_import from PIL import Image as pImage import numpy @@ -48,7 +48,7 @@ def load(self): [Image(os.path.join(self.dirname, filename)).load() \ for filename in os.listdir(self.dirname) if filename.endswith('.jpg')] # random.shuffle(self.images) return self def __repr__(self): @@ -67,5 +67,7 @@ def html(self): return '\n'.join(res) if __name__ == '__main__': reference = open('reference.html').read() il = ImageList('/home/maniac/Desktop/4554182') result = il.html() + '\n' print(reference == result) -
Grigory Bakunov revised this gist
Jan 13, 2013 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,9 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # # Video of this screencast: https://vimeo.com/57296525 # # from __future__ import print_function, division, absolute_import from PIL import Image as pImage import numpy -
Grigory Bakunov revised this gist
Jan 13, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -34,7 +34,7 @@ def __mul__(self, other): return sum(1 for x in self.t_data - other.t_data if abs(x) > Image.TRESHOLD) class ImageList: """List of images information, built from directory. All files must be *.jpg""" def __init__(self, dirname): self.dirname = dirname -
Grigory Bakunov created this gist
Jan 13, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,68 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import print_function, division, absolute_import from PIL import Image as pImage import numpy import os import random class Image: """Take an information from image file""" BLOCK_SIZE = 20 TRESHOLD = 60 def __init__(self, filename): self.filename = filename def load(self): img = pImage.open(self.filename) small = img.resize( (Image.BLOCK_SIZE, Image.BLOCK_SIZE), pImage.BILINEAR ) self.t_data = numpy.array( [sum(list(x)) for x in small.getdata()] ) del img, small return self def __repr__(self): return self.filename def __mul__(self, other): return sum(1 for x in self.t_data - other.t_data if abs(x) > Image.TRESHOLD) class ImageList: """List of images information, build from directory. All files must be *.jpg""" def __init__(self, dirname): self.dirname = dirname self.load() def load(self): self.images = \ [Image(os.path.join(self.dirname, filename)).load() \ for filename in os.listdir(self.dirname) if filename.endswith('.jpg')] random.shuffle(self.images) return self def __repr__(self): return '\n'.join( ( x.filename for x in self.images ) ) def html(self): res = ['<html><body>'] for img in self.images: distances = sorted([ (img * x, x) for x in self.images ]) res += [ '<img src="' + os.path.basename(x.filename) + '" width="200"/>' + str(dist) for dist, x in distances if dist < 220] res += ['<hr/>'] res += ['</body></html>'] return '\n'.join(res) if __name__ == '__main__': il = ImageList('/Users/bobuk/,misc/wm') print(il.html())