Thomas Robinson was experimenting with a way to recover censored text from documents that use the Photoshop “mosaic” filter to redact text. One way to brute force a solution to a redacted message is to run the mosaic filter with a number of input letters, looking for visual matches that progressively uncover the censored text.

Manually performing this trial and error approach would take quite a bit of time, but Thomas was able to automate this by writing a Javascript program that interfaces directly with Photoshop CS3 and performs the necessary filters and test operations to uncover the secret message. This is cool on a number of levels, not only for the particulars of the example, but also for the fact that you can now script Photoshop in plain old Javascript.

There are so many cool things you could do with an easy scripting interface to Photoshop. Check the video above to see this particular application in action, or follow the links below for the full discussion and example code for writing the Javascript code to make something like this work.

## 4 thoughts on “Scripting Photoshop with Javascript – anti-redaction example”

1. Anonymous says:

that is some cool math there

2. Jim Shima says:

This trick has been used in the signal processing community for some time. In fact, the inverse square root via Newton’s method is an opcode on the ADI Sharc processors (to do fast sqrt operations). Newton’s method for any function x^n requires a division per iteration, and for x^(-n) requires only multiplications. Since DSPs can do multiplications very fast, computing x^(-1/2) is much faster than computed x^(1/2). And to compute a fast sqrt, you can take the output of the inverse sqrt and multiply by the original x to get sqrt(x).

Also as stated, for the initial guess in floating pt when you shift the IEEE float number to the right by one that gives you a very accurate starting guess (you must remove the exp bias first). This effectively divides the exp by two as well as the mantissa. If you go through the entire analysis, you will find that the starting guess is, at worst, only 6% in error to the true sqrt. Not bad for just one shift! That is why doing only one Newton iteration is good enough for most applications.

3. DJSolin says:

And I had always asked my calc profs what in the hell did we do math anyway, “It’s not like I am going to use it in programming!!” I used to say!! ;) I guess the joke is on me… I LOVE MATH!!