#!/usr/bin/python

import os,sys,Image,ImageFilter,math,ImageChops

#the aim of this programm is to remove the vignetting of a photo by dividing by a filter


if len(sys.argv)==3:
	filt=sys.argv[2]
	filename=sys.argv[1]
elif len(sys.argv)==2:
	filename=sys.argv[1]
	filt="filter.png"
else:
	raise "Please enter the name of the photo (and the filter)"

try:
	I=Image.open(filename).convert("RGB")
	F=Image.open(filt).convert("RGB")
except:
	raise "either the file %s or the filter %s is not readable !!!"%(filename,filt)

#G=F.convert("RGB")
#H=ImageChops.invert(I.convert("RGB"))
#J=ImageChops.invert(ImageChops.multiply(H,G))

J=ImageChops.invert(ImageChops.multiply(F,ImageChops.invert(I))) 

J.save(os.path.splitext(filename)[0]+"-dv"+os.path.splitext(filename)[1])
