Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
Binary file added .gitignore
Binary file not shown.
Binary file added Ankit_Kumar_Dubey_230154.mp4
Binary file not shown.
Binary file added compressed_output.mp4
Binary file not shown.
185 changes: 185 additions & 0 deletions compression_report.html

Large diffs are not rendered by default.

3,047 changes: 3,047 additions & 0 deletions segments_kept.json

Large diffs are not rendered by default.

415 changes: 415 additions & 0 deletions solution.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions venv/Lib/site-packages/ImageHash-4.3.1.dist-info/INSTALLER
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pip
10 changes: 10 additions & 0 deletions venv/Lib/site-packages/ImageHash-4.3.1.dist-info/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Copyright (c) 2013-2022, Johannes Buchner
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

218 changes: 218 additions & 0 deletions venv/Lib/site-packages/ImageHash-4.3.1.dist-info/METADATA
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
Metadata-Version: 2.1
Name: ImageHash
Version: 4.3.1
Summary: Image Hashing library
Home-page: https://github.com/JohannesBuchner/imagehash
Author: Johannes Buchner
Author-email: buchner.johannes@gmx.at
License: 2-clause BSD License
Platform: UNKNOWN
Description-Content-Type: text/x-rst
License-File: LICENSE
Requires-Dist: PyWavelets
Requires-Dist: numpy
Requires-Dist: pillow
Requires-Dist: scipy

===========
ImageHash
===========

An image hashing library written in Python. ImageHash supports:

* Average hashing
* Perceptual hashing
* Difference hashing
* Wavelet hashing
* HSV color hashing (colorhash)
* Crop-resistant hashing

|CI|_ |Coveralls|_

Rationale
=========

Image hashes tell whether two images look nearly identical.
This is different from cryptographic hashing algorithms (like MD5, SHA-1)
where tiny changes in the image give completely different hashes.
In image fingerprinting, we actually want our similar inputs to have
similar output hashes as well.

The image hash algorithms (average, perceptual, difference, wavelet)
analyse the image structure on luminance (without color information).
The color hash algorithm analyses the color distribution and
black & gray fractions (without position information).

Installation
============

Based on PIL/Pillow Image, numpy and scipy.fftpack (for pHash)
Easy installation through `pypi`_::

pip install imagehash

Basic usage
===========
::

>>> from PIL import Image
>>> import imagehash
>>> hash = imagehash.average_hash(Image.open('tests/data/imagehash.png'))
>>> print(hash)
ffd7918181c9ffff
>>> otherhash = imagehash.average_hash(Image.open('tests/data/peppers.png'))
>>> print(otherhash)
9f172786e71f1e00
>>> print(hash == otherhash)
False
>>> print(hash - otherhash) # hamming distance
33

Each algorithm can also have its hash size adjusted (or in the case of
colorhash, its :code:`binbits`). Increasing the hash size allows an
algorithm to store more detail in its hash, increasing its sensitivity
to changes in detail.

The demo script **find_similar_images** illustrates how to find similar
images in a directory.

Source hosted at GitHub: https://github.com/JohannesBuchner/imagehash

References
-----------

* Average hashing (`aHashref`_)
* Perceptual hashing (`pHashref`_)
* Difference hashing (`dHashref`_)
* Wavelet hashing (`wHashref`_)
* Crop-resistant hashing (`crop_resistant_hashref`_)

.. _aHashref: http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html
.. _pHashref: http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html
.. _dHashref: http://www.hackerfactor.com/blog/index.php?/archives/529-Kind-of-Like-That.html
.. _wHashref: https://fullstackml.com/2016/07/02/wavelet-image-hash-in-python/
.. _pypi: https://pypi.python.org/pypi/ImageHash
.. _crop_resistant_hashref: https://ieeexplore.ieee.org/document/6980335

Examples
=========

To help evaluate how different hashing algorithms behave, below are a few hashes applied
to two datasets. This will let you know what images an algorithm thinks are basically identical.

Example 1: Icon dataset
-----------------------

Source: 7441 free icons on GitHub (see examples/github-urls.txt).

The following pages show groups of images with the same hash (the hashing method sees them as the same).

* `phash <https://johannesbuchner.github.io/imagehash/index3.html>`__ (or `with z-transform <https://johannesbuchner.github.io/imagehash/index9.html>`__)
* `dhash <https://johannesbuchner.github.io/imagehash/index4.html>`__ (or `with z-transform <https://johannesbuchner.github.io/imagehash/index10.html>`__)
* `colorhash <https://johannesbuchner.github.io/imagehash/index7.html>`__
* `average_hash <https://johannesbuchner.github.io/imagehash/index2.html>`__ (`with z-transform <https://johannesbuchner.github.io/imagehash/index8.html>`__)

The hashes use hashsize=8; colorhash uses binbits=3.
You may want to adjust the hashsize or require some manhattan distance (hash1 - hash2 < threshold).

Example 2: Art dataset
----------------------

Source: 109259 art pieces from http://parismuseescollections.paris.fr/en/recherche/image-libre/.

The following pages show groups of images with the same hash (the hashing method sees them as the same).

* `phash <https://johannesbuchner.github.io/imagehash/art3.html>`__ (or `with z-transform <https://johannesbuchner.github.io/imagehash/art9.html>`__)
* `dhash <https://johannesbuchner.github.io/imagehash/art4.html>`__ (or `with z-transform <https://johannesbuchner.github.io/imagehash/art10.html>`__)
* `colorhash <https://johannesbuchner.github.io/imagehash/art7.html>`__
* `average_hash <https://johannesbuchner.github.io/imagehash/art2.html>`__ (`with z-transform <https://johannesbuchner.github.io/imagehash/art8.html>`__)

For understanding hash distances, check out these excellent blog posts:
* https://tech.okcupid.com/evaluating-perceptual-image-hashes-at-okcupid-e98a3e74aa3a
* https://content-blockchain.org/research/testing-different-image-hash-functions/

Storing hashes
==============

As illustrated above, hashes can be turned into strings.
The strings can be turned back into a ImageHash object as follows.

For single perceptual hashes::

>>> original_hash = imagehash.phash(Image.open('tests/data/imagehash.png'))
>>> hash_as_str = str(original_hash)
>>> print(hash_as_str)
ffd7918181c9ffff
>>> restored_hash = imagehash.hex_to_hash(hash_as_str)
>>> print(restored_hash)
ffd7918181c9ffff
>>> assert restored_hash == original_hash
>>> assert str(restored_hash) == hash_as_str

For crop_resistant_hash::

>>> original_hash = imagehash.crop_resistant_hash(Image.open('tests/data/imagehash.png'), min_segment_size=500, segmentation_image_size=1000)
>>> hash_as_str = str(original_hash)
>>> restored_hash = imagehash.hex_to_multihash(hash_as_str)
>>> assert restored_hash == original_hash
>>> assert str(restored_hash) == hash_as_str

For colorhash::

>>> original_hash = imagehash.colorhash(Image.open('tests/data/imagehash.png'), binbits=3)
>>> hash_as_str = str(original_hash)
>>> restored_hash = imagehash.hex_to_flathash(hash_as_str, hashsize=3)

For storing the hashes in a database and using fast hamming distance
searches, see pointers at https://github.com/JohannesBuchner/imagehash/issues/127
(a blog post on how to do this would be a great contribution!)



Changelog
----------

* 4.3: typing annotations by @Avasam @SpangleLabs and @nh2

* 4.2: Cropping-Resistant image hashing added by @joshcoales

* 4.1: Add examples and colorhash

* 4.0: Changed binary to hex implementation, because the previous one was broken for various hash sizes. This change breaks compatibility to previously stored hashes; to convert them from the old encoding, use the "old_hex_to_hash" function.

* 3.5: Image data handling speed-up

* 3.2: whash now also handles smaller-than-hash images

* 3.0: dhash had a bug: It computed pixel differences vertically, not horizontally.
I modified it to follow `dHashref`_. The old function is available as dhash_vertical.

* 2.0: Added whash

* 1.0: Initial ahash, dhash, phash implementations.

Contributing
=============

Pull requests and new features are warmly welcome.

If you encounter a bug or have a question, please open a GitHub issue. You can also try Stack Overflow.

Other projects
==============

* http://blockhash.io/
* https://github.com/acoomans/instagram-filters
* https://pippy360.github.io/transformationInvariantImageSearch/
* https://www.phash.org/
* https://pypi.org/project/dhash/
* https://github.com/thorn-oss/perception (based on imagehash code, depends on opencv)
* https://docs.opencv.org/3.4/d4/d93/group__img__hash.html

.. |CI| image:: https://github.com/JohannesBuchner/imagehash/actions/workflows/testing.yml/badge.svg
.. _CI: https://github.com/JohannesBuchner/imagehash/actions/workflows/testing.yml

.. |Coveralls| image:: https://coveralls.io/repos/github/JohannesBuchner/imagehash/badge.svg
.. _Coveralls: https://coveralls.io/github/JohannesBuchner/imagehash


13 changes: 13 additions & 0 deletions venv/Lib/site-packages/ImageHash-4.3.1.dist-info/RECORD
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
../../Scripts/__pycache__/find_similar_images.cpython-310.pyc,,
../../Scripts/find_similar_images.py,sha256=d4_RAVgjsMceoBrEMZx-TjoeI__rdWeNXj9OFk4gdHw,2230
../../images/imagehash.png,sha256=NRNPYFhZRvuj5wXbVtSUEkG7F0IHqS4s1GSY76BVqTY,292247
ImageHash-4.3.1.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
ImageHash-4.3.1.dist-info/LICENSE,sha256=nQsDeFPa57z2sZtyhVmoM5k82HEPwYomHmAm5Wv3BL4,1302
ImageHash-4.3.1.dist-info/METADATA,sha256=bDVP5rYjqfmFmsFjw0aSQTpMHVzxijz09lhtUr7VftM,8022
ImageHash-4.3.1.dist-info/RECORD,,
ImageHash-4.3.1.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
ImageHash-4.3.1.dist-info/WHEEL,sha256=z9j0xAa_JmUKMpmz72K0ZGALSM_n-wQVmGbleXx2VHg,110
ImageHash-4.3.1.dist-info/top_level.txt,sha256=50BXQ_hiKLUM8Nh9bREcTIsLBl9-TggxRdi7bv2LYZg,10
imagehash/__init__.py,sha256=z9xjrGgYUXxpwpj2BKV90J8CfMeiLBYCfLfxT7JrqJ8,25367
imagehash/__pycache__/__init__.cpython-310.pyc,,
imagehash/py.typed,sha256=sNJcSCznk4EDK7g4Y8Bdo8eFC1UeFKrL9sFIBvoFsOk,69
Empty file.
6 changes: 6 additions & 0 deletions venv/Lib/site-packages/ImageHash-4.3.1.dist-info/WHEEL
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Wheel-Version: 1.0
Generator: bdist_wheel (0.37.1)
Root-Is-Purelib: true
Tag: py2-none-any
Tag: py3-none-any

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
imagehash
133 changes: 133 additions & 0 deletions venv/Lib/site-packages/PIL/BdfFontFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#
# The Python Imaging Library
# $Id$
#
# bitmap distribution font (bdf) file parser
#
# history:
# 1996-05-16 fl created (as bdf2pil)
# 1997-08-25 fl converted to FontFile driver
# 2001-05-25 fl removed bogus __init__ call
# 2002-11-20 fl robustification (from Kevin Cazabon, Dmitry Vasiliev)
# 2003-04-22 fl more robustification (from Graham Dumpleton)
#
# Copyright (c) 1997-2003 by Secret Labs AB.
# Copyright (c) 1997-2003 by Fredrik Lundh.
#
# See the README file for information on usage and redistribution.
#

"""
Parse X Bitmap Distribution Format (BDF)
"""
from __future__ import annotations

from typing import BinaryIO

from . import FontFile, Image

bdf_slant = {
"R": "Roman",
"I": "Italic",
"O": "Oblique",
"RI": "Reverse Italic",
"RO": "Reverse Oblique",
"OT": "Other",
}

bdf_spacing = {"P": "Proportional", "M": "Monospaced", "C": "Cell"}


def bdf_char(
f: BinaryIO,
) -> (
tuple[
str,
int,
tuple[tuple[int, int], tuple[int, int, int, int], tuple[int, int, int, int]],
Image.Image,
]
| None
):
# skip to STARTCHAR
while True:
s = f.readline()
if not s:
return None
if s[:9] == b"STARTCHAR":
break
id = s[9:].strip().decode("ascii")

# load symbol properties
props = {}
while True:
s = f.readline()
if not s or s[:6] == b"BITMAP":
break
i = s.find(b" ")
props[s[:i].decode("ascii")] = s[i + 1 : -1].decode("ascii")

# load bitmap
bitmap = bytearray()
while True:
s = f.readline()
if not s or s[:7] == b"ENDCHAR":
break
bitmap += s[:-1]

# The word BBX
# followed by the width in x (BBw), height in y (BBh),
# and x and y displacement (BBxoff0, BByoff0)
# of the lower left corner from the origin of the character.
width, height, x_disp, y_disp = (int(p) for p in props["BBX"].split())

# The word DWIDTH
# followed by the width in x and y of the character in device pixels.
dwx, dwy = (int(p) for p in props["DWIDTH"].split())

bbox = (
(dwx, dwy),
(x_disp, -y_disp - height, width + x_disp, -y_disp),
(0, 0, width, height),
)

try:
im = Image.frombytes("1", (width, height), bitmap, "hex", "1")
except ValueError:
# deal with zero-width characters
im = Image.new("1", (width, height))

return id, int(props["ENCODING"]), bbox, im


class BdfFontFile(FontFile.FontFile):
"""Font file plugin for the X11 BDF format."""

def __init__(self, fp: BinaryIO):
super().__init__()

s = fp.readline()
if s[:13] != b"STARTFONT 2.1":
msg = "not a valid BDF file"
raise SyntaxError(msg)

props = {}
comments = []

while True:
s = fp.readline()
if not s or s[:13] == b"ENDPROPERTIES":
break
i = s.find(b" ")
props[s[:i].decode("ascii")] = s[i + 1 : -1].decode("ascii")
if s[:i] in [b"COMMENT", b"COPYRIGHT"]:
if s.find(b"LogicalFontDescription") < 0:
comments.append(s[i + 1 : -1].decode("ascii"))

while True:
c = bdf_char(fp)
if not c:
break
id, ch, (xy, dst, src), im = c
if 0 <= ch < len(self.glyph):
self.glyph[ch] = xy, dst, src, im
Loading