1

I have a jar that is launched every minute via CRON to capture a beach webcam image and save it to a file. Since it runs 24*7, it saves nighttime images that are of no use. I'd like the jar to analyze the file and determine whether it is a "keeper".

The only approach I can see (I haven't coded it yet) is to iterate through each pixel, look at the RGB for each and if some percentage of pixels is totally or nearly black, call it a throwaway. Is this a reasonable approach?

FWIW, the image is from a camera mounted atop the Clearwater Beach Hilton, looking southwest over the beach and Pier 60 - Heaven on earth to this Iowa boy.

URL=http\://192.163.243.248/webcams/clearwater.jpg

Thanks, Chris

CDT
  • 33
  • 4

2 Answers2

1

Assuming you are not using an image processing library (I don't know of any free open source ones, but you could check out this thread ), a more reasonable approach would be select a subset of lines. For example, examine every 20th line. If the height of the image is 640, then you need to only look at 32 lines. You could check only every 2nd or 4th or whatever pixel on each of those lines. The rationale being from pixel to pixel, or even line to line, there won't be much difference in pixel values... especially at night.

Using some kind of time range, as suggested also makes sense, but might need some tweaking since sunrise and sunset change every day.

Community
  • 1
  • 1
Bizmarck
  • 2,663
  • 2
  • 33
  • 48
  • No library here, I'm just doing this for my own entertainment. Learning a bit about image processing is a nice diversion from the daily SpringMVC grind. – CDT Dec 03 '13 at 03:34
  • Regarding a time range - sunrise and sunset change daily, so that approach would not be practical unless I were to consume a public web service that provided such times, and I know of no such service. – CDT Dec 03 '13 at 03:36
1

I ended up using the routine below to determine whether or not an image is worth keeping. It looks at every 10th pixel of every 10th row and calls the pixel dark if the sum of the red, green, and blue components is less than 30 (a number I pulled from nowhere). If 10% (another arbitrary number) or more pixels are dark, then the image is dark.

private boolean keepImage(BufferedImage bufferedImage){
    int imageHeight = bufferedImage.getHeight();
    int imageWidth = bufferedImage.getWidth();

    long pixelCount = 0;
    long darkPixels = 0;
    for(int y=0;y<imageHeight;y+=10){
        for(int x=0;x<imageWidth;x+=10){
            pixelCount++;
            int rgb = bufferedImage.getRGB(x, y);
            int red = (rgb >> 16) & 0x000000FF;
            int green = (rgb >>8 ) & 0x000000FF;
            int blue = (rgb) & 0x000000FF;
            if (red + green + blue < 30)
                darkPixels++;
        }
    }
    float darkQuotient = (float)darkPixels/(float)pixelCount;
    return darkQuotient<0.1;
}
CDT
  • 33
  • 4
  • Please let us know how successful these arbitrary numbers turn out to be. BTW, I think it would be better to parameterize these numbers. – Scary Wombat Dec 04 '13 at 00:49