Saturday 11 July 2015

What do you do when...

Today's blog is about image processing.  In some down time, I've been trying to figure out what to do to manage my photo library that has grown over 25G.  This makes it hard to just upload to the cloud (free services anyway).  My first intention was to remove duplicates.  But of course, its more fun to tackle the bigger issue.  How can I index my library so I can actually query against it?

My first thoughts were; there needs to be a simple way to do some basic image comparisons, so what are they?
1) produce a grayscale histogram
2) produce a color histogram
3) create a CRC
4) gather meta data

If an image is exactly the same, regardless of file name and whatnot that can change if the image is copied, then the CRC (ie Adler) will be the same.  The trick is, don't calculate the CRC on the file, but rather the contained image, because if the image is edited or saved (i.e. a copy paste), then the EXIF metadata will get lost.  So, trick one, calculate the CRC on the pixel map and at the same time rip out the EXIF metadata to stuff into an XML metadata file.  (Cool right?  Too bad java libraries do not include mechanisms to extract EXIF from JPEG!  But easy enough to borrow some libraries from open source projects.)

While calculating the CRC, that will tell you if the image is exactly the same, you still have the issue of "What if I rotated the image 90 or 180 degrees?"  You will have a different CRC, so that mechanism won't help.  But you can create a histogram on the image.  Then you can compare histograms, and if the image is rotated so it is edge aligned (270,180,90) or bit flipped, if those histograms are equal, the image is the same with high probability.  Also, images of the same subject in the same context (background) will also be similar.

So, if you have free rotate or scaled (or otherwise changed the image quality or cropped), the histogram might be a good starting guess.  There will be false positives, but from a numerical standpoint, you can then move on to more intensive methods.  How to compare?  Cosine similarity works.  The vector is the histogram, and you can fix the scaling issue by changing the frequency (count) of the color to the percentage (so count over total size).  I have a sneaky suspicion this is how the brain does it.  When our eyes scan an image, we look for discontinuity in the image (and tend to ignore anything with continuity.  That's why "if it were any closer it would bite me.")

I am still thinking about false positives, or how to identify subjects in an image.  For subjects, the cosine similarity will also work, but figuring out the threshold of what to suggest to a human could be fun.  I need to play with that, but I figure a that with a divide and conquer based on histogram might work. Then also working in some extrapolation methods.  I could divide and conquer to generate average colors in a section of an image, and/or use that to generate a polynomial for horizontal and vertical slices.  If the coefficients are close, then there is a good bet the images are similar.


Thursday 25 June 2015

Sleepy in Seattle

Well, Seattle is nice. My room here is about 30C (86F) in the "nice" apartment. I'm not too happy, but too overwhelmed to do anything about it. One of my original criteria for short stay was a gym. This building doesn't have a gym, but they do have a game room with nice pinball, pool table, and Foosball. Tonight I ventured out to the game room that was doubling as a kids rumpus. I sat beside a six year old beating the heck out of a pinball machine making farting noises after which I was grateful for my kids whom I miss dearly. On Tuesday I took out the Pi and the junk I brought to try and fiddle with it. The power adapter, 7.5V 800amp, seemed to get the hub powered without exploding (I blew up some speakers before I left home by mistaking a 9V adapter for a 6V device. Smoke and pop.) I read that Windows 7 has DHCP built in via "Share Internet Connection." My portable was connected via wifi to a router. So I plugged the hard line into the hub (and to the Pi.) First thing I needed to do was assign a static IP to the portable on the lan interface. Then I was able to turn on connection sharing (you need two active networks before you can play router.) But Windows 7 did not act as a DHCP server... guidance said install nmap and do a subnet scan. The Pi was never issued an IP, and I suspect DHCP was not part of the setup so not running. So I installed openDHCP. And the first thing I saw, running it as standalone, was that it was getting a broadcast request from Spock (my Pi), but giving the error "No matching DHCP range" - that is somewhat cryptic! The problem, after fiddling, was the the default IP of the DHCP server in the configuration file was 192.168.0.1. I thought you weren't supposed to use 0... and most of us use 192.168.1.1. So of course changing the ini file solved the problem but not after some head scratching. So after a few hours and getting as far as PuTTY to the Pi (not using nmap because in DHCP stand alone you know what the first IP leased is, and it tells you if you can't guess) I gave up for the night. I don't think I care about turning the portable into a router yet.

Sunday 14 June 2015

Java Pi

Some useful links; not sure if these are installed yet but I will install them if not.  (I was worried I'd need to write my own.)


  • Article on Pi and Java
  • WiringPi is a library needed by pi4j (for JNI low level GPIO access)
  • pi4j is a java library giving you GPIO access and some other OSI layer functions

Minecraft Pi


Wanted to see how the composite output looked and attach old USB keyboard and mouse. Composite is not great and would need some alignment fiddling. But the input devices work fine. My next little task is to try attach an old joystick or paddle to the GPIO pins.





Patrick tries out Minecraft Pi, looks creative only:  Minecraft Pi website (though it looks like it hasn't been updated in three years.)  But it was pretty responsive (even under X.)

 I saw a dude make a box out of lego to protect his Pi - seems like a great idea.





Saturday 13 June 2015

who knew EMP

I discovered today while taking a picture of my son on the Raspberry Pi2, that the camera and flash generates enough of an EMP to derange the Pi2 electronics!  Subsequently I learned you can turn an old camera into a pretty strong EMP device capable of knocking out the average cell phone!  Wow.

Next, Raspberry Pi boots into tty.  You need to "startx" to get the raspian desktop up (default xwindows manager.)  It is not great on a composite TV (and you need to figure out which composite out is the video line as the iPad cable I had required me to swap red for yellow.)  Sound also is not configured on by default it seems.


Friday 12 June 2015

Could Not Wait


Well, I plugged in an ethernet cable into the hub and the Pi, and USB mini power from my desktop to the Pi... just to see if I could log in.  Turned it on, installed putty on my Windows 7 machine, checked my router just in case it gave itself an IP via DHCP (that it did), and...


There ya go!  Like magic it worked.  It helps to read - I should have run raspi-config first because I looked up on the web how to resize the micro-SD card up to 32G and did it manually via fdisk (and of course raspi-config does this for you.)  Note, there is no swap partition on the raspian image I downloaded from raspberrypi - so no need to delete it!

Next thing after browsing /var/syslog to see what I missed during boot.  Then off to see if I could install Java.  Typed 'arch' and saw the arm chip.  Saw a note about hard float being used in the forums.  And guess what - Oracle Java arm with hard float is pre-installed!  (Not sure about full JDK, but javac is in /usr/bin.)

Next I thought I wanted to "see" the desktop.  So I installed MobaXterm.  It doesn't work out the box (as in I got the window with the background up, a few error messages, but no actually desktop.)  Not sure why yet; I might not care because I saw a few folks say "just install xrdp via sudo apt-get xrdp" and more magic.



Minecraft and Mathematica are also installed!  Life is good.

Monday 1 June 2015

Looky looky!

The computer "brain" has arrived.



Step 1... install rasbpian onto SD card.
Step 2... find MAME for linux and try get it building
Step 3... find an old arcade chasis
...


Thursday 28 May 2015

Regression

OMDI is now officially unofficially OMD.

Ah, change and transition are good things.  I am un-incorporating to be free of paperwork.

Wednesday 20 May 2015

Things are in transition.  I'm finally moving all my stuff into "the cloud."

It is logical.