Archive for July, 2008

Digitization Noise in Astrophotography

Thursday, July 31st, 2008

That magical night of perfect seeing and perfect placement of that long-sought astronomical object has arrived and you do not have to work tomorrow. You head off to the telescope for some imaging. The night could not have gone better and you now have several gigabytes of AVI files captured with your webcam ready for processing. RegiStax munches the AVI files to produce what initially appear to be fabulous images. Wavelet-sharpening, RL-Deconvolution, and some high-pass-filtering goes well. Just one more step before you amaze the world with your perfect images: curves/levels adjustments in PhotoShop. “Yikes! Where did all of these rings and bars come from when I try to bring out some detail from the darker parts of my images?”

Greetings from the land of digitization errors!

“But, I could see all the detail through the eyepiece before I fired up the camera and I was watching the screen before the capture. The image was stunning. There was no twinkling from poor seeing and no real noise was visible at all. It was perfect data!”
Yes, too perfect.

Image stacking, like the sort RegiStax does, is used to improve signal to noise. It is also capable of sorting through the images to find and stack only the best ones to overcome distortions due to poor seeing (atmospheric turbulence), but that is a subject for another essay. Yes, stacking multiple images of the same object is a great way to reduce noise in astrophotography. It can also increase the dynamic range in the final image. Before we go on, we need to (mis)define a few terms.

Image Stacking is a technique of improving an image through the combination of multiple images, often hundreds. There are many ways to combine the images and different reasons for doing things a particular way. For now, just think of image stacking as averaging many images of the same thing.

Bit Depth is the number of bits your camera produces in each color (typically ranges from 8 to 16 with 8-bits being common with webcams). It is also used to define how many bits are used in the stacking of images (typically this is either 16 or 32), the bit depth of the accumulation buffer.

Signal to Noise Ratio (SNR) is exactly as it sounds, the ratio of the signal level to the noise level. It is a measure of the quality of the image – or more specifically the quality of the parts of the image that have that signal. In photon limited situations, bright areas frequently have a higher SNR than the dark areas.

Dynamic Range can be defined a couple of different ways. One way is just 2 raised to the power of the bit depth. So, an image with a bit depth of 8 has a dynamic range of 2**8 or 256. This can be somewhat misleading though. More typically, the dynamic range is defined as the ratio of the brightest signal to the noise level or minimum usable signal level. In images with little or no noise these two definitions result in the same value.

Minimum Usable Signal is often defined as the signal level where the SNR is equal to some (arbitrary) value (often the value of 1 is used).

Digitization Noise (or Error) is the inability of a digital system to represent changes in signal that are less than one bit. There is no such thing as 1.5 counts. Digital signals from imaging systems are almost always integers. Any signal in between the integer steps gets truncated to the next lowest integer. The resultant image has obvious discrete stair-steps in brightness. Sometimes this is called Posterization.

Digitization Level is the integer step in image brightness equivalent to a change of one count in the digitized image.

Digitization errors are frequently overlooked when considering how to set up an imaging system. They should not be though since there are ways to overcome them. I’m not talking about trading that 8-bit webcam in for a multi-thousand-dollar 16-bit imaging system either. One way I’m not going to talk about is extending the dynamic range to larger/brighter signal levels by the High Dynamic Range (HDR) technique. The HDR technique relies on the combination of multiple images with different exposures to add detail from short exposures to areas in the longer exposure images where those images are saturated. Instead I’d like to focus on pulling detail out of the dark areas of our images with a set of properly taken single-exposure images.

I’ve yakked a lot already and have not even mentioned the image above. The image is a set of panels that I’d wish to use to demonstrate how stacking works and, more importantly, what properties your images need to have in order to maximize the benefits of image stacking. So, let me describe the panels in the image above. The upper left image is what I’ll call “the truth” or what we’re trying to image really looks like. Ideally it would be a noiseless image with infinite bit depth. In this example it is just an 8-bit deep region of the Moon near the terminator. Because “the truth” has finite bit depth and limited dynamic range, I need to create some data from a less than perfect camera. To do that I’ve decided my camera is going to be a 4-bit monochrome camera. Images from it will have 16 (2**4) levels from 0 to 15. You can think of this as just the portion of an image from an 8-bit camera that all falls within the lowest 4-bits. Moving to the right along the top row (row 1), I have added different amounts of noise to “the truth” and digitized it to a bit depth of 4. The noise was normally distributed (Gaussian noise) with standard deviations of 0.0 counts (noiseless other than digitization errors), 0.2 counts (noise rarely exceeding 1 count), 0.5 counts (something I’ll come to call optimal noise level), and 8 counts (this is an excessive amount of noise used only to demonstrate the power of stacking [on the dark side ;-) ]) as you go along the top row from columns 2 through 5 respectively. The image in row 1 column 2 might be thought by many to be the perfect image because it has no additional noise. Looking at it in comparison with “the truth” though shows the effects of digitization errors. The vertical banding in the image with little to no variations captured from the subtle changes seen in “the truth” is a result of those real variations falling in between the bits. Image from row 1 column 3 has a little bit of noise and the banding from digitization errors is still visible. Column 4 has enough noise that the image looks like someone printed out “the truth” on a printer that dithers patches with black and white dots (sort of like the way photos were printed in newspapers). Squint or get far enough away and it looks very much like “the truth”. The rightmost column, column 5, has so much noise that it is almost impossible to tell it contains any information from “the truth”.

The images in the rows below the top row are the result of stacking several images with the same level of noise as that image in the top row. The level of noise is the same, but a different, random pattern of noise is applied to each image before digitization (to 4 bits) and stacking. Row 2 is the result of stacking 4 images, row 3 is a stack of 16, row 4 is a stack of 256, and the bottom row, row 5, is a stack of 4096 images. Because there is no added noise, all of the images in column 2 are identical. Stacking does nothing to alter, let alone improve, the images when there is no noise. Stacking requires noise in order to work! In the progression of images in column 3, there is some improvement in the noise level, but even stacking 4096 images cannot remove the vertical banding from digitization errors. The edges of the bands have been softened somewhat and begin to reveal some real detail in their vicinity. The images in column 4 also improve in SNR as more images are stacked. They also show no signs of digitization errors. The vertical banding is gone and the bottommost image (row 5 column 4) is almost completely identical to “the (8-bit) truth”. If you are not convinced stacking does anything useful, column 5 has something to prove. After stacking 4096 images with this excessive level of noise almost all of the detail from “the truth” is revealed, however, the contrast (also the dynamic range) is greatly reduced.

“What is going on here?” Well if you have a set of essentially identical images because they have virtually no noise, stacking them is like averaging one image with a copy of itself. It does not matter how many times you average something with itself. You can only get the original image. Jumping to the 4th column with a noise level of 0.5 counts, this amount of noise is the minimum amount of noise required to eliminate digitization errors via stacking. More noise will also work, but you’ll have to stack more images to get the same SNR as you get with a stack of fewer images with a noise level of 0.5 counts. In this sense, a noise level of 0.5 counts is optimal.

“OK, so why didn’t it work in column 5 with a noise level of 8 counts?” I cheated, but for the good reason of making an important point! “The truth” represents not only reality, but also the proper camera settings for taking images. The image I selected for “the truth” was adjusted so that my 4-bit camera would produce data that was properly exposed. The brightest pixels would be exposed to 95% of full scale. The darkest area also was offset from zero by 2 counts in our 4-bit camera. Looking at your images, and preferably the histogram distribution of pixel values, is essential to avoid other problems and artifacts in the stacking process. 95% of full scale with a minimum offset of at least 2 counts is nearly ideal for a noise level of 0.5 counts. Column 5 is an example of what happens when these values are set improperly for the level of noise present. Before digitization, “the truth” plus the noise in each image resulted in the range of pixel values extending well beyond the 0-15 range our 4-bit camera outputs. Our camera cannot reproduce anything outside the 0-15 range. As a result anything less than 0 becomes 0 and anything greater than 15 becomes 15. When these truncated images are averaged, the statistics are skewed. The black pixels with positive noise have no blacker pixels (black plus negative noise) to average against. You are only averaging positive noise and so the black pixels from “the truth” appear gray in the stack. Similarly, the brightest pixels can’t get any brighter and their average in the stacking process is only averaging negative noise and the result is less than white. So, the final image has lower contrast and a suboptimal dynamic range even though it has a high SNR.

In column 3 with a noise level of 0.2 counts, the data does not have enough noise to eliminate the digitization errors. There is enough noise to help near the transition from one count level to the next, but the amount of noise does not allow this statistical process to reach all the way to the middle of the gap between digitization levels. You can get to 1.2, for example, but not to 1.5. The limited noise does average down quickly though.

In theory, the image in row 4 column 4 should be equivalent to “the truth”. Stacking 256 images should give you a factor of 16 (square root of 256) improvement in dynamic range, or 4 more bits. Because the information content of “the truth” in my example data is limited to 8 bits, there should be no further improvement by stacking additional images. And in fact, the bottom two images in column 4 are identical. Since stacking has added new levels of digitization between those present in the 4-bit version and the result has decreased the noise to a comparable level, the dynamic range, by either definition, has increased as well. The increase in dynamic range is dependent upon proper exposure of the images relative to the amount of noise present, however, and is not guaranteed.

“So, you are telling me that I need to set up my camera so that I always have some visible noise?” No, I’m not. There are objects/scenes that do not have a high dynamic range requirement. In particular, you are not always interested in accessing detail in the deep shadows or darkest portions of your image. In those cases, you probably want to minimize your noise and concentrate on the ability of the stacking process to reduce the effects of seeing (twinkling).

Bottom Line: You need some noise to get any improvement in SNR from the stacking process. There is an optimal amount of noise, half a count standard deviation, that will minimize digitization errors. Whatever level of noise you select, you need to set the camera properties (gain and offset if available) so that the range of data including noise falls within the digitization range of the camera. Don’t run the histograms to the left and right limits! With proper exposure settings, the minimum stack size should be 256 images – no less – to get a 4-bit improvement in “quality of the stacked image” and a lot more under typical (less than optimal) circumstances.

Fossil fuels: Eden’s apple

Tuesday, July 22nd, 2008

There is war underway that you may not be fully aware of. It is not the biblical battle between good and evil that began in the Garden of Eden, but there are parallels. The battle is of epic proportions and involves some of the most powerful forces on the planet. At stake may very well be civilization itself. No I am not talking about the war on terror, at least not directly, that is only the most visible battle in a much broader war. This war is being fought over a wasteful way of life and the ongoing pursuit riches. The war has been fought for years, but only now have the fiercest battles begun. Battles in this war have names like Water, Poverty, Disease, Pollution, Energy. It is an aspect of the energy battle I wish to address here.

If you watch TV, read the news (electronically I hope), or engage in polite office conversation you are probably aware that Bush and other fossil fuel friendly politicians have been seeking ways to drill for oil in various places like ANWR for years. Most recently they seek to open up more off shore coastal areas for exploration with the stated goal to bring down the price of oil. You have probably also heard of Al Gore’s challenge to switch the production of electricity, essentially all of it, over from fossil-fueled power plants to renewable sources (like wind and solar) within 10 years. Interestingly, legendary oil man T. Boone Pickens has been in the media talking about his reasons for investing heavily not on drilling, but on wind power. In the middle is just about everyone else, you and me, and we are the real force to be reckoned with. We are the key to each side’s success. We are already causing things to happen much faster than anyone anticipated. And for once, this is a good thing. I’d like to explain in a bit more detail just what is going on, what is at stake, and what you can do about it.

In the past year, the UN released a report on climate change usually referred to as the IPCC report. The report is a substantial work of several volumes based on input from hundreds of scientists around the world. The report details the nature of climate change, the causes, the effects, and the ramifications of climate change on civilization. Also partaking in writing the report were politicians. The final report paints a not too gloomy picture of climate during the next hundred years. What you may not know is that the report is based a lot on climate models. In order to be accurate, models need to include all aspects of the problem. In order to be precise, those aspect need to be well understood. The less well understood, yet important, aspects of the climate system being modeled result in a large uncertainty/confidence in the models predictions. During final editing and negotiations, the report focused on the most robust conclusions. Namely that humans dumping CO2 into the atmosphere is primarily responsible for the observed climate changes. Predictions for the next 100 years, however, did not include some of the feedback mechanisms which are the least well characterized. Virtually all of these are positive feedbacks which would increase the rate/magnitude of climate change. So instead of talking about a sea level rise of 12 meters by the end of the century, we are instead reading in the report about changes of 2 feet. You may think that they were just being careful – perhaps so. You have certainly read about the unexpectedly rapid melting of the polar ice cap in the Arctic. Just a year ago, it was believed that the ice cap at the north pole would melt near the end of the century. Now the observational evidence – not models – indicates that it may be gone in less than 15 years. Glaciers are melting at accelerated rates throughout the globe. Remote sensing imagery indicates that spring is arriving earlier each year. You can question a lot of the details, but the overall evidence strongly suggests that things are changing and they are changing fast.

Climate models do tell us a lot about what specific processes are important. In particular they tell us that the increases in CO2 that have already occurred and are likely to occur from the continued reliance on fossil fuels to meet our increasing energy needs. Whether you believe the observed climate change is due to man or natural causes, it is quite clear the dumping more CO2 into the atmosphere is not going to help matters. The US annual energy consumption is of the order of 100 exojoules (or 100 Quadrillion BTUs). The way that energy is produced and used results in over half of it being wasted through inefficient production or conversion to useful work. This site shows the details of production and consumption for 2002. The overwhelming majority of our energy needs are obtained from fossil fuels (Oil, Coal, and Natural Gas). A few things derived from from this data are noteworthy. Light duty transportation (cars and small trucks) uses the bulk of the oil with an average efficiency of 25%. The generation of electricity primarily comes from coal with an efficiency of better than 30%. The bulk of natural gas is used by homes and industry and achieves an efficiency of 80%. The latter is not surprising since the natural gas use is primarily for producing heat (furnaces, hot water, …). The take away message here is that using fossil fuels to produce heat to make things spin – generators and vehicle wheels -  is horribly inefficient.

So why are they so determined to dig up every last bit of fossil fuel and burn it? Because it represents the fundamental value of the extant energy companies. They own the rights and means to exploit these fuels for profit. And, the profits are huge! There is also a huge investment in infrastructure to convert and distribute these fuels. The consumer is well equipped to consume them. The energy companies are faced with a difficult choice: go with what has made them great or risk changing to an unknown. Humans do not like change and uncertainty, they like the familiar and comfortable. That is true at least when they are comfortable – and the energy providers are very comfortable. Even when the topic of Peak Oil arises, there is so much coal in the US that the comfort level remains acceptable.

The problem is that climate change is real and it is probably changing faster than even the neutered IPCC scientists would like to have reported. Peak Oil has very likely already happened. China and India are on par with the US now for energy consumption (as a nation not per capita – there is a lot more room for their growth in that respect). Oil is $135 a barrel! The price of oil is determined by the limited supply and that is why the US is in Iraq and is worried about Iran. Despite its public statements, Saudi Arabia could not meaningfully increase its oil output if it wanted to. Peak oil likely occurred in 2006 or 2007. That is why the fossil fuel complex and their politicians are pushing so hard for more production in the US. Yes, they can make lots of money, but they really want to keep the addiction going. They are worried that we might just decide to switch. And they should be worried. Who would have thought that the US consumer, in love with their gas guzzling SUVs, would reduce consumption of SUVs & pick-ups to the point that GM would consider selling the Hummer brand and that Ford would virtually halt production of its very profitable pick-up line? Who would have thought that Toyota could not produce enough Prius hybrids? It did happen and it happened fast. The power is in the consumer’s wallets and we are beginning to realize what real power we have.

So what do we switch to? Last year’s fad was ethanol from corn. What a joke that is. When you account for the farming and fertilizer costs, the transportation aspects, and the production fuel needs, ethanol from corn produces 11 gallons for every 10 gallons of fuel consumed in production. This is why the production of fuel must never compete with the production of food. There simply is not enough productive land area or, more importantly, fresh water to waste on fuel production. Nuclear energy will not and should not become the dominant source of long-term energy. The current implementations of nuclear power either produce hideously lethal waste or the stuff of terrorist’s dreams. Either is a security nightmare. There are a few alternative nuclear technologies emerging, but in the long term they cannot become the dominant source of our energy needs on Earth (subject of a future post). We need to rely on either geothermal or solar power sources (including, biomass, wind, wave, and direct solar – not space solar power). The path to future sustainability of our civilization is to promptly curtail our use of fossil fuel in favor of geothermal and solar derived energy sources. Don’t bite the apple!

Many of the alternative forms of energy are compatible with our existing infrastructure. If we achieved just one thing: the widespread use of electric vehicles (80+% efficient fed by renewable energy sources like wind) for our light-duty transportation needs – we would not need to import any oil. If we added to that a bio-fuel, like bio-diesel from algae, for our long-haul and aviation fuel needs we could stop using fossil oil altogether (except for its, IMHO, proper use as a raw material for the production of other materials).  Coal is a bigger problem. It is the primary source of electrical power in the US and it is also the most potent (dirty) source of CO2. We have lots of it in the US and it will be very difficult to stop using it. There are thousands of coal-fired power plants and whole industries associated with mining, transporting and consuming coal. Fortunately, local politicians and voters have essentially shut down the building of new coal-powered electrical generation facilities by denying them permits to build.

We have a vast resource available to us that we are mostly unaware of. We also have a history for rapidly bringing the resources of our industrial might to meet to challenge. The US industrial complex (primarily the automotive sector) during World War II was challenged by president Roosevelt to produce 45,000 tanks, 60,000 planes, and 6,000,000 tons of shipping. In the three years from 1942 to 1944, they built 88,400 tanks, 229,600 planes and 34,000,000 tons of ships. There is no reason to think that we could not produce a couple of million multi-megawatt wind generators (1 coal fired plant = 1000 Megawatt) in 10 years. All we have to do is want to do it. Today, we have idled an immense resource in the automotive industrial sector which could be promptly retooled for the production of wind and tidal energy generators. Given the support of congress and the ‘next’ president, we could quickly, albeit at a high cost, reemploy this idled expertise and capacity to produce and deploy an enormous production capacity for wind power generation. It would aid an ailing industry, put the unemployed to work, generate new exports (more on the state of our economy in a future post), generate tax revenue, generate income for the farm economy, devalue the importance of the Middle East, reduce the price of oil, and put us on a path to reducing our CO2 emissions to a tiny fraction of what they are today. More importantly, it would buy us all time to figure out what to do next.

If you have stuck with me this far – thank you. I have a few suggestions for how you can contribute. First  download and read a free book (PDF) called Plan B 3.0 by Lester R. Brown of the Earth Policy Institute. This is the book that is fundamentally behind the Al Gore initiative and has been disseminated widely among the industrial and political elite. It is a long read that is initially somewhat depressing. You’ll come to understand why things are the way they are in the world. The remainder of the book is uplifting in that it clearly delineates a plan to overcome the challenges we face. If you cannot read the whole thing, try to read Chapters 11 and 12. If you read chapter 13, the summary, you’ll probably need to go back and read the whole book to understand it. These are the near-term things related to this post. After reading the book, I hope you will go out and replace all of your incandescent light bulbs with high quality compact fluorescent lamps (GE, Philips – not the generic imported trash-brands that do not last long). Buy a new car that is a hybrid (preferably a plug-in hybrid) or use mass transit systems. Seriously look at solar power. After running all of the plumbing to heat my pool with natural gas (yes I’m guilty as charged, but repentant – the future does not have to be Spartan), I installed a solar pool heater. It works great! It cost a little more up front, but it will last 3 or 4 times as long as a gas unit and I do not have to pay for the sunshine it uses. I’m looking at solar PhotoVoltaics next. I also switched from oil heat to natural gas last year. Probably the biggest thing I did was to switch my electric hot water heater for a natural gas one. I’m thinking about adding a solar water heater to the loop. There is more you can do, but that will be the subject of future posts.

First Post!

Sunday, July 20th, 2008

It seems only proper that upon my return to a web presence via this blog that I thank my nephew Jeremy for providing and setting up the host for this blog.

Several years ago, I had a very static web site hosted by my internet provider. A few years later (and still several years ago) I built a LAMP system and hosted a new site from home. The new one was a place for experimentation with the M & P of LAMP. I learned a lot except in the areas of system security. The site was hacked and in the process of infecting virtually every bit of my code with nastiness the site became unrecoverable (I did not learn much about backing things up either). I’ve learned my lesson and I’m back certainly older and hopefully wiser.

My intent for this blog is two-fold. I want to create a place for the exchange of ideas that are of interest to me and hopefully you. I also want to have a focus on photography via a photoblog and tutorials. It is going to take some time before I pull together the remaining bits and pieces for this and generate some content.

Thanks for visiting.

Joe