fogbound.net




Thu, 13 Jun 2013

Failures in Image Processing

— SjG @ 10:00 am

I have a tendency to have ideas that seem simple until I attempt the implementation. Then, all of the complexities jump out at me, and I give up and move on to the next idea. Once in a while, however, I’ll go so far as to prototype something or play around before abandoning ship. This here’s an example of the latter.

The Big Idea hit when I looking up a recruiter who had emailed me out of the blue. He shared the name of someone I went to school with, and I wanted to see if it was, in fact, the same person. In this case, a quick Google Images search on the name and job title indicated that it was not the same person, so I didn’t have to fake remembered camaraderie.

While searching, though, I thought it interesting the variety of faces that showed up for that name. Hm. Wouldn’t it be cool, thought I, if I could enter a name into my simple little web service, and it would spit back the “average face” of the first ten or twenty matching images from Google? After writing a few pages of code, scrapping them, switching languages and libraries, writing a few pages of code, scrapping them, switching languages and libraries again, writing a few more pages of code, I then ditched the whole enterprise.

In the process, I did use some morphing software to test the underlying concept. Here is the average face for my picture mixed in with the first seven Samuel Goldstein images that were clear enough, angled correctly, and of sufficient size to work with:
s0123_4567

For what it’s worth, here are a few of the software challenges to automating something like this:

  • Extracting the portrait from the background. This isn’t critical, but will simplify subsequent tasks.
  • Scaling the heads to be the same size.
  • Aligning the images more or less. I was going to use the eyes as the critical alignment points; if they couldn’t be within a certain degree of accuracy, this would suggest incompatible images (e.g., one a 3/4 portrait, the other straight on).
  • Detail extraction. This is finding key points that match on each image. Experimentally, when combining images by hand, it may be sufficient to match:
    • 4 points for each eye, marking the boundaries
    • 3 points marking the extremities of the nostrils and bottom center of septum
    • 5 points marking ear boundaries: top point where they connect to the head, top of extension, center, bottom of lobe, point where lobe connects to head
    • 5 points marking top outer edges, outer angle, and center of mandible
    • 5 points mapping hairline
    • 5 points mapping top of hair
    • 7 points along the superciliary ridge
  • Interpolate these points on each pair of images, then on each interpolated pair, and so on until a single final interpolation is achieved
  • Render the image to a useful format
  • View image, and laugh (or cry)

A few other lessons learned:

The typical picture returned by Google images search for a name will be a thumbnail portrait. It’ll be small — maybe 150 by 300 pixels or so. While that’s enough data to recognize a face, it’s not a lot of data when you start manipulating it. Ideally, for nicer results, source images should be a minimum of two or three times that size.

Google gives back different results depending on whether you surround the name with quotes or not; it also makes a big difference if you pass size or color parameters. The “face” search is a good parameter to use, although when searching for “Samuel Goldstein” face search inexplicably had lots of Hitlers and Osama Bin Ladens. The “safe search” feature is also strongly recommended for this project — again, when searching for “Samuel Goldstein” without safe search yielded a variety of unexpected vaginas.

Bing image search gives different results (not too surprisingly), but they also have some anomalies. My search brought back many of the same pictures, along with an inexplicable collection of calabashes and LP labels.

If any ambitious programmers go ahead and implement this, please send me the link when you’re done!


Fri, 24 May 2013

Javascript approximation for Pi

— SjG @ 11:01 am

Based on this tweet, I now have the ultimate JavaScript approximation for Pi (Π), which I think we can all agree is preferable in every way to the outmoded Math.PI:

var pi=((++[+[]][+[]]+[]+ ++[+[]][+[]]+[])* ++[+[]][+[]])*(++[+[]][+[]]+ ++[+[]][+[]])/((+[+[]]+'x'+(![]+[])[[+!+[]+!+[]]*[+!+[]+!+[]]])/(++[+[]][+[]]+ ++[+[]][+[]]));


Thu, 11 Apr 2013

Uh-oh

— SjG @ 9:34 am

That was close.

scrabble_crop

It almost made me think I’d need to take shelter under a refrigerator.

Filed in:

Tue, 19 Mar 2013

Godwin’s Law

— SjG @ 8:22 am

(Mary) Godwin’s Law: As a summer of incessant Swiss rain wears on, the probability of romantic poets turning into monsters approaches one.


Thu, 11 Oct 2012

Perplexing

— SjG @ 8:40 pm

I have to admit, this latest presidential election has me perplexed1. Why is there even a contest? The Democrats love Obama, and the Republicans should too. After all, the Obama administration is the apotheosis of traditional supply-side GOP ideals — a Republican wet dream. “Wait. What?” I hear you say. Turn off the partisan filters for a moment, and consider the following facts:

  • Corporate profits are at an all-time high.2
  • CEO salaries are the highest ever.3
  • Wall Street salaries are close to the highest they’ve ever been.4
  • The Stock Market is within a few percent of its all-time high.5
  • Interest rates are the lowest on record.6
  • Corporate Taxes are at the lowest effective rate ever (recording begun in 1947).7
  • Tax rate for highest earners is the lowest it’s been since 1931.8
  • The US Defense budget is at an all-time high.9
  • There are more deportations of illegal immigrants than ever.10
  • More terrorists / enemy militants killed per year than ever before11

So, given this list, why is the current administration so hated by the American Right and so loved by the American Left? We have, in essence, a pitched battle between two symbols, which we choose to take at face value. Never mind that the actuality is nothing like what it says on the label12.

1 OK, not really. But the phrase works better, rhetorically. This entire posting should be considered in that light.

2“Corporate Profits Just Hit An All-Time High, Wages Just Hit An All-Time Low”, Business Insider Magazine, 22 June 2012.
US Department of Commerce, Bureau of Economic Analysis.

3“Historical Trends in Executive Compensation” (PDF), 1936-2003, Carola Frydman and Raven E. Saks, November 15, 2005.
“C.E.O. Pay Is Rising Despite the Din,” NY Times, 16 June 2012.
United States Bureau of Labor Statistics, Occupational Employment Statistics survey for 2001-2010.

4“Wall Street Pay: A Record $144 Billion, Financial Overhaul Has Affected Structure but Not Level; Revenue-to-Compensation Ratio Stays Flat”, Wall Street Journal, October 11, 2010.
“The Giant Pay Gap Between Wall Street And Everyone Else Isn’t Going Anywhere”, Business Insider Magazine, October 10, 2012.

5The Dow Jones Industrial Average was 13,494.6 on 3 Oct 2012, the all time high was 14,164.53, so it’s only 4.8% down from the highest it’s ever been. The S&P 500 was 1,450.99 on 3 Oct 2012, the all time high was 1,576.09, so that’s a bigger gap, but it’s still only 8% down from the all-time high.

6“Mortgage rates now below even lows of early 1950s”, Associated Press, 30 Sept 2011.
National Bureau of Economic Research, Macrohistory: Interest Rates.

7St. Louis Federal Reserve Bank, FRED® Economic Data, “Graph: Federal Government: Tax Receipts on Corporate Income (FCTAX)/(Corporate Profits After Tax (CP)+Federal Government: Tax Receipts on Corporate Income (FCTAX))”

8Historical Top Tax Rate, Tax Policy Center of the Urban Institute and Brookings Institution.

9Government Printing Office, Budgets
US Census Bureau historical records

10“President’s Approval Rating Drops, but He Leads 2012 Rivals. As Deportations Rise to Record Levels, Most Latinos Oppose Obama’s Policy” PEW research, 28 Dec 2011.
Numbers may have been inflated by changes in how they’re counted; even so, deportations are still higher than Bush numbers. “Deportation statistics said to be inflated”, Washington Times, 23 August 2012

11“The Year of the Drone. An Analysis of U.S. Drone Strikes in Pakistan, 2004-2012” New America Foundation

12And just so you don’t think I’m picking on the Democrats alone, I only point out the one side as it’d take a whole additional posting to show that the Republicans are the “spend and borrow” party, etc.