rhsimplex / image-match

🎇 Quickly search over billions of images
2.94k stars 405 forks source link

Requirement of ImageSignature() with img=bytes & bytestream=False #106

Open excerebrose opened 5 years ago

excerebrose commented 5 years ago

The function preprocess_image in goldberg.py has a use case when bytestream=False, img_or_path=<bytes> -> from line 226:

 if bytestream:
            try:
                img = Image.open(BytesIO(image_or_path))
            except IOError:
                # could be an svg, attempt to convert
.
.
.
.
elif type(image_or_path) is bytes:
            try:
                img = Image.open(image_or_path)
                arr = np.array(img.convert('RGB'))
            except IOError:
                # try again due to PIL weirdness
                return imread(image_or_path, as_grey=True)

I have tried to understand where this could be applicable as an edge case and fail to do so? In the scenario where I think it might be relevant is if someone does something like:

with open("file.jpg","rb") as f:
    sig = ImageSignature().generate_signature(f.read(), bytestream=False)

But that would just lead to an error.

rhsimplex commented 5 years ago

I believe it was related to: https://github.com/dsys/match/pull/2