tag:blogger.com,1999:blog-59318499956400106452024-03-05T16:59:17.162-08:00One Too ManySegFaulthttp://www.blogger.com/profile/15548538258060982007noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-5931849995640010645.post-34632426847979674402011-08-06T23:22:00.000-07:002011-08-07T01:27:24.668-07:00Retinex Image Processing Batch Script<i>Target platform: Windows OS (tested on Windows 7).</i><br /><br />How would you like to turn a photo like this one:<br /><br /><table style="width:auto;"><tr><td><a href="https://picasaweb.google.com/lh/photo/dXodz7JA7ACQjNI54vAe3w?feat=embedwebsite"><img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLgcReJ63KHIr62cEYodmKFjt74TGg1ZkvVs1j8f1xyWVYttcyWs6Agc7BiXD9yi-z8KaDi5jAX9QOpAoCaiIhKhcMsaHytLxHaz1w-h9g6wy61dqfzfjwqGKnACF4Q8KHe_bxTJHm3X6VzBQ/s288/IMG_0266_2R.jpg" height="174" width="333" /></a></td></tr><tr><td style="font-family:arial,sans-serif; font-size:11px; text-align:right">From <a href="https://picasaweb.google.com/s.finucane001/Blogger?authuser=0&feat=embedwebsite">Blogger</a></td></tr></table><br /><br />Into a photo like this one:<br /><br /><table style="width:auto;"><tr><td><a href="https://picasaweb.google.com/lh/photo/LmMr__lrXUHma4KNx2WMMA?feat=embedwebsite"><img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2o2SMasRUZXEWNKWPeMidhblW-W_G1OQs_6NuOxaxgfoBSMa-cuDIpGFZXb6v7TWGl2DOBr2ntL57xiB5nPpUPA4781F48HyTrapCzpe0e0Tfj7AVm3var0QIEZ-zaLfR2ds5h7QbfRlzty8/s288/IMG_0266_2R_retinex.jpg" height="174" width="333" /></a></td></tr><tr><td style="font-family:arial,sans-serif; font-size:11px; text-align:right">From <a href="https://picasaweb.google.com/s.finucane001/Blogger?authuser=0&feat=embedwebsite">Blogger</a></td></tr></table><br /><br /><b>AUTOMATICALLY???</b> (and in batch-loads at a time!!!)<br /><br />In my previous post, I introduced the art and science of book scanning, and announced that I am going digital... painfully digital. In this post, I will present the reader with a simple, yet powerful batch script that (when setup as forthwith described) will clear up any lighting issues one may encounter when attempting to digitize that lovely collection of Shakespearean sonnets! Hooray! :)<br /><br />Let's hope this is not much ado about nothing, Mr. W.H., eh? eh?<br /><br /><h3><u>Step One:</u> <i>Create folders and files!</i></h3><br /><br />Create a new folder anywhere you like, and name in anything you wish. I called my folder ePress (and will subsequently refer to this folder as the root folder for this project).<br /><br />Now, create a file within this root folder and name it: "retinex.bat" (sans quotes). Leave the file empty for now...<br /><br />Next, create a folder within the root folder, and name it "bin" (sans quotes).<br /><br />Within the "bin" folder, create another folder and name it "img" (you know by now, right?)<br /><br />One last time (I swear) create a folder within the "img" folder, and name it "magick" (sic, and sans quotes).<br /><br />Finally... you should now have the following structure:<br /><div style="color:#C40000"><br /><code><br />root/retinex.bat<br />root/bin/img/magick<br /></code><br /></div><br /><br /><h3><u>Step Two:</u> <i>Download ImageMagick Binaries (*.exe files)</i></h3><br /><br />Visit <a href="http://www.imagemagick.org">http://www.imagemagick.org</a> and find the binary release for your operating system. Now, DO NOT download the installer... You will need the release that comes as a *.zip file, as it contains all of the individual executables that comprise the ImageMagick (TM) tool-set.<br /><br />At the time of the post, the following was the direct link to the zip file: <a href="http://www.imagemagick.org/download/binaries/ImageMagick-6.7.1-Q16-windows.zip">DOWNLOAD</a>.<br /><br />Once you have the zip file (sometimes called the "portable" version), extract all of the executables (and whatever other junk: www, etc...) to the "magick" folder you created in step one. All we are really concerned about here is obtaining the "convert.exe" program!<br /><br /><h3><u>Step Three:</u> <i>Create some more folders...</i></h3><br /><br />Within the root folder (ePress, for me...) create a folder and name it "tmp" (sans quotes).<br /><br />Next, within the "tmp" folder, create a folder and name it "retinex" (you get the idea)...<br /><br />Go BACK to the ROOT folder now...<br /><br />Within the root folder, create a folder and name it "output".<br /><br />Within the "output" folder, create a folder and name it "retinex".<br /><br />Phew! You should now have the following new structures:<br /><br /><div style="color:#C40000"><br /><code><br />root/tmp/retinex<br />root/output/retinex<br /></code><br /></div><br /><br /><h3><u>Step Four:</u> <i>Paste batch code into "retinex.bat" file!</i></h3><br /><br />First off, let me say that this code IS NOT an original concept! In fact, I only adapted one of the many scripts available to perform retinex image processing... this particular script was a shell script from <a href="http://www.fmwconcepts.com/imagemagick/">Fred's ImageMagick Scripts</a><br /><br />Now, on with the show...<br /><br />Paste the following code into the file (that you created earlier) called "retinex.bat":<br /><div style="color:#11A600"><br /><code><br /><br />@ECHO OFF<br />CLS<br />echo -- RETINEX (R) IMAGE PROCESSING --<br />echo SCRIPT BY: Sean A. Finucane<br />echo July 22, 2011<br />echo __________________________________<br />echo Adapted from:<br />echo Fred's ImageMagick Scripts, <br />echo Retinex Bash Script<br />echo ----------------------------------<br />REM RETINEX IMAGE PROCESSING (HSL)<br />SET tmpA="%~dp0tmp\retinex\retinex_A.mpc"<br />SET tmpB="%~dp0tmp\retinex\retinex_B.cache"<br />SET tmpH="%~dp0tmp\retinex\retinex_H.png"<br />SET tmpS="%~dp0tmp\retinex\retinex_S.png"<br />SET tmp0="%~dp0tmp\retinex\retinex_0.png"<br />SET tmp1="%~dp0tmp\retinex\retinex_1.png"<br />SET tmp2="%~dp0tmp\retinex\retinex_2.png"<br />SET tmp3="%~dp0tmp\retinex\retinex_3.png"<br />REM PATH TO OUTPUT FILE<br />FOR %%I IN (echo %1) DO SET outputname=%%~nI<br />SET outfile="%~dp0output\retinex\%outputname%.png"<br />REM PATH TO IMAGE MAGICK CONVERT.EXE<br />SET convert="%~dp0bin\img\magick\convert.exe"<br />REM LOGARITHM TO USE FOR RETINEX ALGORITHM<br />SET formula="log((u+1))"<br />REM<br />echo Output file will be: %outfile%<br />echo --------<br />REM<br />echo REPAGING... Please wait.<br />echo --------<br />%convert% -quiet -regard-warnings %1 +repage %tmpA%<br />REM HSL COLOR MODE PROCESSING<br />REM Save original<br />echo HSL COLOR MODE PROCESSING... Please wait.<br />echo --------<br />%convert% %tmpA% %tmp0%<br />REM Convert to HSL reusing $tmpA for Lightness<br />echo Convert to HSL... Please wait.<br />echo --------<br />%convert% %tmpA% -colorspace HSL -channel R -separate %tmpH%<br />%convert% %tmpA% -colorspace HSL -channel G -separate %tmpS%<br />%convert% %tmpA% -colorspace HSL -channel B -separate %tmpA%<br />REM PROCESS IMAGE<br />echo Processing Reflectance Images - Please Wait, this may take some time...<br />echo --------<br />REM Get three resolution sizes (in this case, default=5, 20, and 240<br />SET res1=5<br />SET res2=20<br />SET res3=240<br />REM Create reflectance images at each resolution size<br />echo STAGE 1:<br />echo --------<br />%convert% %tmpA% ( +clone -blur 0x%res1% ) -fx %formula% %tmp1%<br />echo --------<br />echo STAGE 2:<br />echo --------<br />%convert% %tmpA% ( +clone -blur 0x%res2% ) -fx %formula% %tmp2%<br />echo --------<br />echo STAGE 3:<br />echo --------<br />%convert% %tmpA% ( +clone -blur 0x%res3% ) -fx %formula% %tmp3%<br />echo --------<br />echo Finalizing... Please wait.<br />echo --------<br />REM Average results (normalize as log reduces range of values)<br />%convert% %tmp1% %tmp2% %tmp3% -evaluate-sequence mean -normalize %tmp1%<br />REM Convert back to RGB and OUTPUT!<br />%convert% %tmp0% -colorspace HSL %tmpH% -compose CopyRed -composite %tmpS% -compose CopyGreen -composite %tmp1% -compose CopyBlue -composite -colorspace RGB %outfile%<br /></code><br /></div><br /><br />... and VOILA! You may now drag and drop any SINGLE image file into the "retinex.bat" file, and it will be subsequently processed. As I mentioned previously, the primary advantage of retinex processing is the ability to improve a WIDE variety of images AUTOMATICALLY (i.e. without the need to tweak settings). The primary disadvantage is that the process is really quite S.L.O.W.<br /><br />But, if you create a file (name it whatever you wish, as long as it is in the same directory as "retinex.bat") and paste the following batch script code into it:<br /><br /><div style="color:#11A600"><br /><code><br /><br />@ECHO OFF<br />SET batchProg=retinex.bat<br />SET curDirectory=%~dp0<br />:NEXT_ITER<br />IF [%1]==[] GOTO FINISH<br />REM OTHERWISE, WE SHOULD PERFORM THE DESIRED OPERATION<br />CALL "%curDirectory%%batchProg%" "%%~dp1%%~n1%%~x1"<br />REM SHIFT THE ARGUMENT VARIABLES (%1 = %2, etc...)<br />SHIFT<br />GOTO NEXT_ITER<br />:FINISH<br />PAUSE<br /></code><br /></div><br /><br />... you will then be able to drag and drop whole groups of files into the above batch file AT ONE TIME! Hooray for batch processing! :)<br /><br />My file was cryptically named "batch_retinex.bat"...SegFaulthttp://www.blogger.com/profile/15548538258060982007noreply@blogger.com0tag:blogger.com,1999:blog-5931849995640010645.post-46901923965279225752011-08-04T23:37:00.000-07:002011-08-07T00:57:33.540-07:00Going Digital... Painfully digital.There's nothing quite like spending countless hours of your life slaving over a <a href="http://en.wikipedia.org/wiki/Image_scanner#Flatbed">flatbed scanner</a>, and trudging through the <a href="http://en.wikipedia.org/wiki/Ascii">ascii</a> fields of neverendor in the <a href="http://www.youtube.com/watch?v=dQw4w9WgXcQ&ob=av3e">digitaurus rexus hades galaxy</a>. Uncool, to the n double factorial degree.<br /><br />There is some hope, however, for us mere mortals who foolishly embark down the <a href="http://en.wikipedia.org/wiki/Alice's_Adventures_in_Wonderland">rabbit hole</a> into the realm of pseudo-reality -the nether space which sits so seemingly innocuously between our world and the land of dreams, the space in which reality becomes coarse, and vaguely familiar. All who dare enter, beware. The hope, of which I previously spake, is that you are NOT ALONE! Alas! Thine misery is spread! :)<br /><br />My personal experience with the daunting task of digitizing all records, papers, books, music, videos, etc... began very recently (July / August 2011). Armed with my flatbed scanner, and many <a href="http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=Operating+System+Concepts&x=0&y=0#/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=University+Physics&rh=i%3Aaps%2Ck%3AUniversity+Physics">over-priced textbooks</a>, I set forth this simple goal: to digitize all of my school books by the end of the summer (the end of September). I soon realized that a flatbed scanner is a sub-prime tool when current <a href="http://en.wikipedia.org/wiki/Life_expectancy#Life_expectancy_variation_over_time">human life-spans</a> are factored into the efficiency calculations.<br /><br />Slow to be discouraged (i.e. stupid, or maybe naive at best), I began researching the methods employed by intelligencia web-wide. Ahhhh.... the sticky inter-web catches much. My initial (very short) research session turned up little usable information. Ahhhh.... the power of keywords unknown. Ironically, the knowledge I was seeking popped up randomly on the front page of a web-site (that I had just come across) known as: <a href="http://hackaday.com/">http://www.hackaday.com/</a> . I love <a href="http://www.google.com/search?q=serendipity">serendipity</a>. And hackaday.com.<br /><br />Hack-A-Day had featured the following website and book scanner design: <a href="http://www.diybookscanner.org/">http://www.diybookscanner.org/</a><br /><br />Somehow, I never managed to search something as simple as "book scanner"... hmm..... although, my initial search was literally one google query regarding digitizing books... not scanning them... because that was what I was failing at, scanning them.<br /><br />My next blog will delve into the devilish details of applying <a href="http://scantailor.sourceforge.net/">ScanTailor</a> modifications to a scanned set of pages (using a camera, somewhat like the design that is referenced above) and using the <a href="http://www.imagemagick.org/">ImageMagick (TM)</a> "convert.exe" program to apply <a href="http://en.wikipedia.org/wiki/Color_constancy#Retinex_Theory">Retinex</a> image processing to the scanned pages (like NASA does to its images).<br /><br />Stay tuned! :)SegFaulthttp://www.blogger.com/profile/15548538258060982007noreply@blogger.com0tag:blogger.com,1999:blog-5931849995640010645.post-16907673397057049522011-03-09T15:39:00.001-08:002011-03-09T15:59:19.329-08:00JumpLoader and Yii :: Uploading Files with the Yii FrameworkI will try my best to keep this article like an inverted pyramid of information... but with this first sentence, I've already blown it, haven't I? Oh well. Odds are that if you're reading this post, you are looking for some simple widget / component for your Yii based web application that will allow a user to upload files to the server. Never fear, the JumpLoader yii component is here! [http://www.yiiframework.com/extension/jumploader-java-uploader]<br /><br />What can this JumpLoader component do for you? Simple: it can be easily integrated into your Yii application as an extension, added as a component, and then used as a widget in your application's view files. Yes, it really is that easy. You can simply follow the link provided above to learn more about downloading and installing the JumpLoader Java Loader extension for the Yii Framework).SegFaulthttp://www.blogger.com/profile/15548538258060982007noreply@blogger.com0tag:blogger.com,1999:blog-5931849995640010645.post-58756953925758171312011-03-01T09:50:00.000-08:002011-03-01T10:30:25.463-08:00To Hell With It All, and Back Again? Chapter 1: Genesis<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigjyHC-yEzV80PVBMCO5zI9ydHhOM_WhQi5yH48y4c86ipqTIWfkdw-SnX55S8rJ71LQqBF3b-5HC7CAr4OLYO8ngUR8W7va1J1MY6Va-sPUto4k98SitQsGBqfocTzpMAHg0qYVOdeHkTKXw/s1600/2011-02-28+21.24.27.jpg"><img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigjyHC-yEzV80PVBMCO5zI9ydHhOM_WhQi5yH48y4c86ipqTIWfkdw-SnX55S8rJ71LQqBF3b-5HC7CAr4OLYO8ngUR8W7va1J1MY6Va-sPUto4k98SitQsGBqfocTzpMAHg0qYVOdeHkTKXw/s320/2011-02-28+21.24.27.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5579180012499378434" /></a><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBar47I2g183lTEcFmLKb55R7G5vS0unA2dUQHNKO4iYmLmqXidIk-IVroH6Iek0iB4OmzIn-tsN_zdF3OLDm0lJrKG2K38J4UlHwqbkJtSlnohyphenhyphenM8QACH0nAeoHtTV8z_5bp12AKguZjNN8Y/s1600/2011-02-28+21.24.07.jpg"><img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBar47I2g183lTEcFmLKb55R7G5vS0unA2dUQHNKO4iYmLmqXidIk-IVroH6Iek0iB4OmzIn-tsN_zdF3OLDm0lJrKG2K38J4UlHwqbkJtSlnohyphenhyphenM8QACH0nAeoHtTV8z_5bp12AKguZjNN8Y/s320/2011-02-28+21.24.07.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5579179865240355266" /></a><br />We've all gone down the path at some point: the black, shadowy stretch of what is possible; the path which connects the imagined with the realized, the make-believe with reality; the path of which successful failures dare not speak, of which failed successes reminisce, and of which the few and the proud often brag. How should we know this path when it approaches us? Just look for the sign which says, "Glory and despair await all those who dare... and for the rest of you, there are cookies and sandwiches in the back."<br /><br />Now, let's get down to business. I am writing all of this with the hope that it will lend some semblance of aid to the poor schmuck (like myself) who decides to tackle similar (if not identical) projects... plus, I really would like a record of what the hell I've done wrong, and (on occasion) what I've done right. The Lord knows that our failures are our greatest victories.<br /><br />My current project involves the design, development, and implementation of a Gantt Chart Generator of a sort. This generator, of a sort, is to be built within the Yii web application framework. Currently, I have produced a "rapid prototype" (which translates as: "a heap of code shoe-stringed within a single class, with few specialized functions to speak of, all rolled up and covered in a papier-mache interface"). This prototype takes advantage of the available widget functionality of Yii... and, more specifically, inherits from an extension known as "Open Flash Chart 2 Widget". Essentially, I extended this widget (subsequent "OFC2Widget") to provide the specific Gantt Chart generator that I desired. Of course, there are issues (euphemism for errors) that need resolved, but the widget does produce a simple gantt chart.<br /><br />The task at hand is to redesign the internal structure of this proto-widget.SegFaulthttp://www.blogger.com/profile/15548538258060982007noreply@blogger.com0