The size of the moon mystery
I am sure you have heard that the moon changes its size. When you're in love and you're lucky, the moon is almost twice in size compared to normal situations. Some people say the reason is the atmosphere which acts as a lens. Others think that it is only a matter of comparison to other objects such as trees nearby. Whatever explanation you read, it's quite subjective.
The size of the moon science
Ok, we're programmers, aren't we? We rely on facts, right? So here's the experiment:
- Take a nice camera which supports setting time and aperture manually.
- Set your camera to maximum zoom level.
- Go out, take some photographs of the moon in order to detect the best settings so that the moon is sharp and lighting is just fine.
- Remember the settings
- Take photos of the moon with those settings every time you think the moon is large or small.
- Calculate the size of the moon in pixels
The camera won't lie, would it? By counting the bright pixels we can effectively measure the size of the moon - at least in pixels.
If the size is the same across all photos, then it's a bug in our brain. If the size differs, then there's room for speculation
- the moon really grows (but what does it eat?)
- there's an atmospherical lens effect
- the moon has an elliptical curve and is sometimes nearer, sometimes further away from earth
But I'll leave that open until your task is completed. Of course you want to know in advance if your software can calculate the moon size accurately.
Given a few optimized pictures of the moon, please calculate the size of the moon. The optimization is: the pixels are either black or white. Nothing in between. No antialiasing. That makes it easy, doesn't it?
The caveat: the moon is not always full, you know ... it can be a sickle! But even in shape of a sickle, the size of the moon is larger. So you'll calculate the full size, please.
- Your program takes a PNG as input, e.g. as file name command line argument, piped into
stdinor as a Bitmap object (of a standard framework library) if you write a function instead of a program.
- Your program works with any reasonable input bitmap size, not necessarily square. Minimum width and height of 150 pixels are guaranteed.
- The full moon covers at least 25% of the picture.
- Your program outputs the calculated size of the moon in pixels as if it were a full moon.
- We assume that the moon is a perfect sphere.
- The exact size is always an integer number, but you can output a decimal number if your calculation returns that.
- The accuracy should be between 98% and 102%. (That's rather a guess than something I could guarantee to be achievable. If you think it's too hard to reach, please leave a comment.)
- The center of the moon isn't necessarily in the middle of the picture.
- The minimum visible area is 5% of the moon or 1.25% of the total number of pixels.
- The picture is taken in a way that the whole moon would fit the image, i.e. the total number of pixels is an upper boundary for the moon size.
- The moon will not be cropped / clipped.
You can generate your own samples using the blend file if you like. I have created the following pictures for you. You can count pixels in a PNG file using WhitePixelCounter.exe (needs .NET) to check whether the image contains black and white pixels only and how many of them.
The following 256x256 pixel images differ in the amount of white pixels, but should all result in a calculated moon size of 16416 pixels.
And these 177x177 pixel images should return 10241 pixels. The images are basically the same, but this time a camera with a different focal length was used.
Non-square and non-centered samples with a result of 9988:
Oh, I don't have a reference implementation for now and I even don't know whether I am able to implement something. But in my brain there is a strong belief that tells me it must be mathematically solvable.
This is Code Golf. The shortest code on 2015-03-30 gets accepted.