{"id":56,"date":"2004-12-20T23:31:41","date_gmt":"2004-12-21T07:31:41","guid":{"rendered":""},"modified":"2016-05-25T23:34:39","modified_gmt":"2016-05-26T06:34:39","slug":"livecam-contrast-detection","status":"publish","type":"post","link":"https:\/\/mikeindustries.com\/blog\/archive\/2004\/12\/livecam-contrast-detection","title":{"rendered":"Hey, Where Did Seattle Go?"},"content":{"rendered":"<p>Last weekend, I noticed that the Seattle weather turning to crap has also turned a good deal of the livecam images in the Mike Industries live header to crap.  As it turns out, the moisture we get this time of year in the Northwest can turn a scenic Puget Sound view into an indistinguishable blob of grey in about 15 minutes.  To make matters worse, the livecam is actually a Sony DV cam and not a proper high-resolution digital still camera, so a poorly defined subject area really makes for a blurry and unimpressive shot.<\/p>\n<p>Here is a sampling of what the header looks like under different circumstances (Note: If you can&#8217;t see the live header, make sure you have Flash installed and click the &#8220;Live&#8221; theme in the sidebar) &#8212;<\/p>\n<h3>Header on a good day<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/blog\/images\/inline\/livecamheader_1.jpg\" width=\"450\" height=\"121\" border=\"0\" alt=\"\" \/><\/p>\n<h3>Header when it&#8217;s extremely foggy<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/blog\/images\/inline\/livecamheader_2.jpg\" width=\"450\" height=\"121\" border=\"0\" alt=\"\" \/><\/p>\n<h3>Header at night<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/blog\/images\/inline\/livecamheader_3.jpg\" width=\"450\" height=\"121\" border=\"0\" alt=\"\" \/><\/p>\n<h3>Header with no image<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/blog\/images\/inline\/livecamheader_4.jpg\" width=\"450\" height=\"121\" border=\"0\" alt=\"\" \/><\/p>\n<p>Now, all of this wouldn&#8217;t be so bad if I wasn&#8217;t using the livecam as a masthead for my site, but I quite intentionally am, so I needed another solution.  If I could only show something else when the view outside was crappy, then that would be great.<\/p>\n<p>But how can you programmatically detect crappiness in photos?  Luckily in my case, it wasn&#8217;t so hard.  <\/p>\n<p>Contrast.<\/p>\n<p>If the contrast of any given photo from the livecam is not sufficiently high, I can deduce one of two things: it&#8217;s really foggy or rainy out, or it&#8217;s nighttime.  Both of these cases produce ugly livecam images in the header, so if I can detect when low contrast occurs, I can change the header accordingly.<\/p>\n<p>I&#8217;d heard about <a href=\"http:\/\/www.imagemagick.org\" target=\"_blank\">ImageMagick<\/a> in the past but never actually used it.  ImageMagick is basically a server module which lets you do all sorts of programmatic things with images like stretching, rotating, sizing, etc. However, it turns out you can also fetch the standard-deviation of each RGB channel of any given image.  The standard deviation of an RGB channel is the range of values which encompasses two-thirds of the total number of pixels in an image.  It&#8217;s a crude measure of contrast, but it works for my purposes.<\/p>\n<p>The next step was writing a PHP script which would suck in the standard deviation value of each channel, come up with an average, and then output a tiny text file containing only a &#8220;0&#8221; or &#8220;1&#8221; depending on if the contrast value was above or below my threshold.  Running this script via cron every 15 minutes would give me an accurate indicator of whether current conditions were defined enough to produce a good image.  And finally, in order to actually act upon that information, I could simply feed &#8220;contrast=0&#8221; or &#8220;contrast=1&#8221; into my Flash header via PHP and the FlashVars property.<\/p>\n<p>So now that I can detect when I don&#8217;t want to show the standard livecam image, I need to figure out what to show instead.  Right now, I&#8217;m simply not loading the image and leaving the header as a block of mostly negative space. The header was originally designed to look presentable without an image, so this doesn&#8217;t bother me too much.<\/p>\n<p>But I want to do more.  I feel like there&#8217;s something more useful I could do in the header when it&#8217;s either foggy or night time and I&#8217;d love to hear any suggestions.  So far, I&#8217;ve come up with these:<\/p>\n<ol>\n<li>Keep it blank.<\/li>\n<li>Bring back the crappy footage for the sake of it being a &#8220;live theme&#8221; and that&#8217;s what live themes do.<\/li>\n<li>Show nicer, higher resolution photos of a foggy scene and a night time scene when it&#8217;s appropriate (taken from a real digital camera).<\/li>\n<li>Come up with some sort of other element to load into the header (like an explanatory line of text) when conditions call for it.<\/li>\n<\/ol>\n<p>Anyway, I have no idea what to do.  Someone even suggested doing a panning lighthouse beacon when it&#8217;s foggy but that may be over the top.  Any ideas?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last weekend, I noticed that the Seattle weather turning to crap has also turned a good deal of the livecam images in the Mike Industries live header to crap.  As it turns out, the moisture we get this time of year in the Northwest can turn a scenic Puget Sound view into an indistinguishable blob of grey in about 15 minutes.  To make matters worse, the livecam is actually a Sony DV cam and not a proper high-resolution digital still camera, so a poorly defined subject area really makes for a blurry and unimpressive shot&#8230;<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[282,42],"tags":[],"class_list":["post-56","post","type-post","status-publish","format-standard","hentry","category-original","category-scenery"],"_links":{"self":[{"href":"https:\/\/mikeindustries.com\/blog\/wp-json\/wp\/v2\/posts\/56","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mikeindustries.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mikeindustries.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mikeindustries.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/mikeindustries.com\/blog\/wp-json\/wp\/v2\/comments?post=56"}],"version-history":[{"count":0,"href":"https:\/\/mikeindustries.com\/blog\/wp-json\/wp\/v2\/posts\/56\/revisions"}],"wp:attachment":[{"href":"https:\/\/mikeindustries.com\/blog\/wp-json\/wp\/v2\/media?parent=56"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mikeindustries.com\/blog\/wp-json\/wp\/v2\/categories?post=56"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mikeindustries.com\/blog\/wp-json\/wp\/v2\/tags?post=56"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}