ageitgey / ageitgey/face_recognition

Face found in JPEG version of image, but not PNG or TIF version of same image

Open
#984 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
56.8k
Forks
13.7k
PR merge metrics
No merged PRs in 30d

Description

face-recognition==1.2.3
face-recognition-models==0.3.0
numpy==1.16.4
Pillow==6.1.0
Django==2.2.3
Python==3.6.6
Ubuntu 18.04

Description

I have a collection of tiff images for a web site. I need to convert them to png, find faces, and do other processing on the images. The pipeline is
upload image -> iff tif, convert to png with pillow -> find faces in png version of image or original version if not tif

Two images are attached - mom_aboard_ship.tif, and lunch.tif. Both scanned on the same HP scanner. The lunch.tif image has no issues with face recognition in my pipeline. The mom_aboard_ship.tif image has the following issues. In summary, the only way a face is found is if I first use imagemagic on the command line to convert mom_aboard_ship.tif to jpeg, and then use that image to find faces. The png version from the tif using pillow or the original tif image produce "no faces found" by the face recognition code. "no faces found" means the arrays returned by face_recognition.face_locations() and face_recognition.face_encodings() are both of zero length.

Sample tests:

  • The original image is tiff, and when uploaded to my app, it is converted to png using Pillow. The app then looks for faces, and zero faces are found. I get these messages from face_recognition -not sure where they are coming from (not my code)
    STREAM b'IHDR' 16 13
    STREAM b'IDAT' 41 65536
    STREAM b'IHDR' 16 13
    STREAM b'IDAT' 41 65536

  • I converted the tiff image to png using command line convert (Imagemagic), upload the image to my app, and look for faces. Zero faces are found. And more cryptic alien messages:
    STREAM b'IHDR' 16 13
    STREAM b'gAMA' 41 4
    STREAM b'bKGD' 57 2
    b'bKGD' 57 2 (unknown)
    STREAM b'pHYs' 71 9
    STREAM b'IDAT' 92 32768
    STREAM b'IHDR' 16 13
    STREAM b'gAMA' 41 4
    STREAM b'bKGD' 57 2
    b'bKGD' 57 2 (unknown)
    STREAM b'pHYs' 71 9
    STREAM b'IDAT' 92 32768
    STREAM b'tEXt' 7804821 37
    STREAM b'tEXt' 7804870 37
    STREAM b'tEXt' 7804919 42
    STREAM b'tEXt' 7804973 18
    STREAM b'tEXt' 7805003 22
    STREAM b'tEXt' 7805037 15
    STREAM b'tEXt' 7805064 15
    STREAM b'tEXt' 7805091 25
    STREAM b'tEXt' 7805128 29
    STREAM b'tEXt' 7805169 21
    STREAM b'tEXt' 7805202 36

  • I convert the tiff image to jpeg using the command line convert (Imagemagic), upload the image to my app and look for faces. 1 face is found. And no alien messages

  • I upload the original tiff image, try to convert to jpeg using Pillow, but it fails with the message "cannot write mode I;16 as JPEG". My app then tries to find the face in the original tif file, and it finds no faces. No cryptic alien messages.

I am not sure what I should do with these tiff images - some fail face recognition in the same way. The tiff images come from my HP scanner or Nikon DSLR. I am not an image expert, so perhaps you have a suggestion on how I can proceed with these tif images.

Thanks,

Mark
mom_aboard_ship.zip

PS
I did a little research on the I;16 mode for Pillow, and I added a step in the upload process to convert the I;16 mode images to mode L. Now the faces are found. I used the following for the conversion:

def convert_I_to_L(img):
array = numpy.uint8(numpy.array(img) / 256)
return PI.fromarray(array)

Does this seem a reasonable solution?

Mark

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the report with the attached mom_aboard_ship.tif and compare face_recognition.face_locations() and face_recognition.face_encodings() on the TIFF, Pillow-generated PNG, and ImageMagick-generated JPEG. Check how Pillow exposes the TIFF's I;16 mode and determine whether the project should handle this input or document a supported conversion path. Done means the behavior is reproducible and an agreed fix or documented recommendation is covered by a regression test or example.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
computer-vision, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.