Home » Php » php – Removing red eye from an Image on the client side using Jquery

php – Removing red eye from an Image on the client side using Jquery

Posted by: admin July 12, 2020 Leave a comment


I have the following html code rendered on my client’s browser:

<div id="Div">
  <img src="myImage.jpg" id="myImage"/>

This particular image is uploaded by the user and then displayed here.
I need to allow my user to remove any red-eye from this image. I would like to do it without any postback ( I’m using CodeIgniter at the back ). Are there any available libraries for this in JQuery (or plain Javascript) ? If not what could be a good approach ?

How to&Answers:

There is a lot of things that go on in red eye removal

A. Eye Detection

B. Red Eye Region Mapping

C. Fill Color

D. Fuzz

E. Opaque

My advice

If not a JOB for Jquery and even PHP would not remove red eye effectively

Likely Solution

  1. Get a Jquery area selection script where users can select their red eyes them self ( With this you would be able to get the region (X1 , Y1 , X2 , Y2 , Height , Width ) example http://odyniec.net/projects/imgareaselect/

  2. Have a simple Color Picker where they can select replacement color ??? Default can be black

  3. Send request to imagemagick using exec in PHP for the red eye removal

  4. You can not output your image …


I was able to help you get a ready command line tool for this JOB


Basic Concept

A. Create a desaturate copy of the input image

B. Perform a fuzzy floodfill to create a mask image

C. Composite the original with the desaturated image using the mask image

D. Apply a morphologic close operation to fill in the specular hole in the mask
and then create a difference operation to create a new mask of just the hole

E. Apply the new mask to composite the previous result with a full lightness,
zero saturation version of the original image

Sample Process

convert -quiet -regard-warnings "$infile" +repage "$tmpA1"
convert $tmpA1 -modulate $light,$sat,100 $tmpA2
for ((i=0; i<np; i++)); do
proc="$proc matte ${pairArray[i]} floodfill"
convert $tmpA5 -fuzz $fuzz% -fill none -draw "$proc" \
-fill "rgba(255,255,255,1)" +opaque "rgba(0,0,0,0)" \
-fill "rgba(0,0,0,1)" -opaque "rgba(0,0,0,0)" \
-alpha off -negate $tmpA3
if [ "$dilate" = 0 ]; then
dilation="-morphology dilate disk:$dilate"
convert $tmpA1 $tmpA2 $tmpA3 -compose over -composite $tmpA2
convert $tmpA3 \( +clone -morphology close disk:$rad $dilation \) \
-compose difference -composite -auto-level \
-negate -threshold 0 -negate $tmpA4
convert $tmpA2 \( $tmpA1 -modulate 100,0,100 \) $tmpA4 \
-compose over -composite $outfile

I hope this helps