Before And After II

Continuing in the before and after series (previous post), here is a Caribbean Reef Shark which I photographed in the Turks and Caicos.

We had put out an ‘attractor’ for the sharks (namely a small piece of fish in a metal box) and we had five to six circling around and swimming amongst the divers. In those sorts of situations I tend to look at the patterns the sharks follow, place myself in their path and wait. They are quite inquisitive and will come by quite close to check out the divers (insert your own jokes about tasty morsels here) at which point you can get some really nice shots as they stream by. I had positioned myself on the seabed very close to the attractor and was watching sharks come by and it stuck me that I could get better shots by lying with my back on the seabed. Indeed I had been noticing that the sharks would just swim over me. So I turned over and started taking shots.

This is the initial shot of a shark as it swam over me. The shot is tinged with red because I had calibrated the white balance on the camera my shooting down at the calibration slate and now I was taking shots upwards so getting more sunlight from the surface (we were at about 50 feet). You will also notice some ‘snow’ in the picture and a diver’s fin. Unfortunately the camera I was using is pretty slow focusing so I lost the nose of the shark.
Caribbean Reef Shark (Master)

So cleaning up the picture, I adjusted down the red, brought out the blues a little, better contrast, then removed the ‘snow’ and the errant fin. The result is a fairly decent blue for the water, though I could have done a better job on the texture on the left of the shark, there is some blotching going on. One thing that was really brought out are the sharks “Ampullae of Lorenzini” all across the shark’s snout. Basically they are a network of electroreceptors, which you can read up on on Wikipedia.
Caribbean Reef Shark

There are some divers who will massage shark’s Ampullae of Lorenzini which makes them very docile, but I was not about to attempt that.


Ruby Threads vs. Perl Threads

Over the weekend I was playing around with a text processing script I wrote in Perl (and then ported to Ruby). This script is CPU bound and runs as a single thread. Interestingly the Ruby version is quite a bit faster than the Perl version, and I suspect that the speed difference is due to the differences in string handling (utf8 vs. non-utf8) and libraries dependencies.

So I decided that it would be interesting to add thread support to the scripts to compare how the two languages handled threading. I used the native threading support that is provided with each language, no external support or libraries were used.

Along the way I discovered some interesting things on how Ruby and Perl handle threads.

The Perl thread scheduler is pretty basic and it is easy for a busy thread to completely crowd out other threads effectively stopping them in some cases. So it is a good idea to have threads yield to each other (which is expensive), or use sleep() statements (which turns out to be cheaper). I did not check this on Ruby.

Most interesting is that Perl is able to take advantage of multiple CPUs/cores when threading while Ruby limits itself on one CPU/core. The script I am playing around with lends itself nicely to threading so I was able to get a nice performance improvement using Perl (more or less linearly with the number of threads I ran plus some overhead), while I go no performance improvement on Ruby.

It would be interesting to see how this script fares in Python, next weekend perhaps.

Coral Reefs Rebound from Damage if Protected

This encouraging report about coral reefs was talked about on ArsTechnica.

Basically reefs bounce back if they are protected:

The study examined ten different reef sites in and around the Bahamas over the course of two and a half years. The reefs had seen damage both from bleaching and from hurricane Frances in the summer of 2004. At the beginning of the observation period, the reefs had, on average, seven percent coral coverage. At the end, two and a half years later, the reefs in marine reserve had coral coverage increase by 19 percent, when initial distribution was taken into account. The areas not protected as part of a reserve showed no statistically significant recovery.

The key is reducing the amount of fishing that goes on because the fish actually help keep down the algae population which, if left unchecked, will quickly overwhelm a reef:

Their work shows, for the first time, that reducing the amount of human interference, mainly fishing, can help nature regain lost ground. By limiting the amount of parrotfish taken, the reserves gave these natural herbivores the chance to keep the local seaweed population under check, which gave the reefs the breathing room they needed to bounce back.

It is true that Parrotfish eat coral but they also graze on the algae that grows on the the reef (as opposed to the algae that grows in the reef which has a symbiotic relationship with the coral). The coral that the Parrotfish eat gets excreted as part of their normal digestive process as sand which eventually makes it to a beach somewhere. So next time you are walking across a beautiful white beach spare a moment to remember where the sand came from.

Before And After

I thought I would do something new for this scuba picture posting. The truth is that most (all!) scuba pictures need some post-processing to look good and the amount of time I spend on picture depends not only on how much work it needs but also on how good the picture is. Typically I will take up to 1,400 pictures on a dive trip, I come back with about 800 (600 get ditched while on the trip), I pick around 100-125 which are worth post-processing and three or four come out really well.

This is the initial picture of a Sea Turtle taken on a night dive in the Cocos Island. It was moving close to the surface and I had to shoot from the hip to get this picture, in fact I was swimming alongside it, holding out the camera, aiming as best I could taking shots. I got three shots, one was of a flipper only and the other had someone else’s flash in it. I was very lucky to get this shot. As you can see there is a lot of ‘snow’, reflections from particles and creatures floating in the water due to the flash. In the bottom of the picture you can see a couple of shark eye reflections.
Sea Turtle Master Image

So cleaning all those up and adjusting the color a little yielded this which I think is a lot better.
Sea Turtle Image

All the snow is gone, the color of the Sea Turtle is a little more saturated and the black of the water is deep.

I will post some more before and after pictures in the next few weeks so you can see what one has to content with.

Number Encoding III

I decided to make the code for the number encoding benchmark available for download (see my earlier posts “Number Encoding” and “Number Encoding II”).

The code is basic C code and contains three tests:

  • A basic bitshift based encoding which is reasonably fast and where the data is portable across big-endian and little-endian machines.
  • A varint based encoding programmed to the spec issued by Google.
  • A compressed varint based encoding which is a variation on the varint based encoding. The difference is that I chose to represent zeros as a 0 bit byte, as opposed to an 8 bit byte which saves a byte when zero needs to be stored. When I checked some of the test collection indices, it turns out that about 10% of the data is zero, so this saved me some amount of space (less data means less I/O.)

You can download the code here.

You can compile the code in debug mode as follows:

gcc -g -o perf_test2 perf_test2.c

Or compile it in optimized mode as follows (-O3 provided the best optimizations):

gcc -O3 -o perf_test2 perf_test2.c

and run it thus:


Let me know how it works for you, if you see any further optimizations, etc…

Apple Tablet

Ok, so I am going to throw my hat into the ring here with Apple Tablet predictions, what I have seen and heard so far range from the boring to the ludicrous. I have also heard a few things from the mother ship which seemed to make sense, at how I perceive reality.

So here goes:

  • 10″ tablet-like device, much like an oversized iPod touch, smaller would not make sense, bigger would be too big.
  • WiFi is a no-brainer, 3G for data connectivity, and bluetooth for audio connectivity as well as keyboard and mouse. This last part is key is any amount of data entry needs to be done on the device (such as email, IM, etc…)
  • There will be a front-facing camera on the device.
  • The operating system will be iPhone-like but with new interface elements to fit the larger screen size. Some have speculated that there will be a new major iPhone OS version released at the same time but this is doubtful, typically these have come with new iPhones to support new hardware features and to serve as an incentive to upgrade.
  • Getting a 3G plan will be optional, and I would imagine that this would impact the price of the device (which would be cheaper with a 3G contract). I would expect to see both GSM and CDMA in the device.
  • New version of iTunes for content management much like podcasts in iTunes, iTunes extras is probably a good preview of things to come. Expect to see both pay-for and free content for the device.
  • This will be a content access/viewing device so expect to see new applications for this as well as new UI elements to support this. I have seen rumors of a steep learning curve, but this makes no sense, not the Apple way.
  • It will be released in March and the price will be around $800.
  • Apple will position this as a new kind of device so as not to eat into iPhone/iPod sales or MacBook sales.

Of course I will do a post-mortem when the device actually comes out.

Three Bugs with iTunes

There are three bugs in the current release of iTunes, they are so glaring I wonder how they got through QA. Maybe Apple has been working hard on the next release so has thrown a junior at the current release.

So here are the three bugs I am running into:

  1. It no longer automatically synchronizes with my AppleTV when new video podcasts are downloaded, or movies or TV shows for that matter, I always seem to have to sync manually.
  2. I have podcasts set up so that audio podcasts are placed on my iPod and video podcasts are placed on my AppleTV. iTunes provides a powerful set of controls which allow me to set that up, and it worked for a while, and then something happened. For some reason the podcasts now get automatically deselected from sync after I remove the last episode in it, and I have to manually re-enable sync when new episodes arrive.
  3. Finally syncing my iPod manually almost always results in either it crashing or iTunes locking up.

I have done a complete reinstall of iTunes, having deleted all preference files, etc… but to no avail.

Apple, what gives??