Use GREYCstoration in an Applescript to denoise images

The open source program GREYCstoration can be used to denoise images taken in low light conditions or with poor-quality digital cameras like webcams. It looks to be fairly new and nobody’s really made a Mac standalone version-- just a GIMP plugin which I haven’t tried out. If you’re planning on using it in an Applescript there are a couple things to look out for. The following example works:


on run
	display dialog "drag! drag! ok!" buttons "oh. right." with icon caution
end run
on open filelist
	repeat with i in filelist
		set Ppath to POSIX path of i
		set bsuf to ".png"
		do shell script "/sw/bin/convert -normalize -resize 750x750 " & Ppath & " " & Ppath & bsuf
		do shell script "/usr/bin/GREYCstoration_darwin -restore " & Ppath & bsuf & " -p 0.7 -a 0.73 -dt 10 -iter 10 -sigma 0.5 -alpha 0.3 -o " & Ppath & ".x" & bsuf & " -visu 0"
		do shell script "rm " & Ppath & bsuf
	end repeat
end open

Take note of the “-visu” and “-o” switches. They tell greycstoration not to display an X11 window with interactive denoising (which didn’t really work for me anyway) and to save the result out as a file respectively. The other switches are taken from one of the example settings. It’ll take some tweaking to get the result you want but when it works it’s astonishing.

The other thing(s) to look out for is where the binaries are located, and the $PATHs that greycstoration uses. There doesn’t seem to be a way to tell grey’n where your imagemagick installation is manually although it’d probably be easy enough if you were to compile it yourself. I didn’t feel like doing a bunch of compiling, so I took the easy way out and simply cp’d the “convert” binary into a path I was fairly certain grey’n would use-- in this case /usr/bin. I had installed imagemagick with fink and grey’n wasn’t finding it in /sw/bin.

And that’s about it. Happy denoising. I’m using an upgraded G4 Sawtooth 1.6GHz / 1.5GB RAM / MacOSX 10.4.6