tag:blogger.com,1999:blog-71653298462817915782024-02-19T13:04:35.974+08:00Random ideas of a drinking catNo cats. Just some Linux stuff, and some photography experiments.Anonymoushttp://www.blogger.com/profile/12050625263370191802noreply@blogger.comBlogger31125tag:blogger.com,1999:blog-7165329846281791578.post-13182459809826658202013-12-01T19:00:00.000+08:002013-12-01T20:47:24.659+08:00OpenCL on the Samsung Chromebook ARM - Benchmarks<div style="text-align: center;">
<i>This is a second post on using OpenCL on the Chromebook ARM. The previous one gives instructions to <a href="http://drinkcat.blogspot.sg/2013/11/opencl-on-samsung-chromebook-arm-under.html" target="_blank">install OpenCL drivers and SDK on the Samsung Chromebook ARM</a>, without requiring to boot a separate Ubuntu, by using <a href="https://github.com/dnschneid/crouton" target="_blank">crouton</a>. This post compares </i><i>OpenMP and </i><i>OpenCL performance of the Chromebook ARM with a 4-year old laptop.</i></div>
<h3>
Test setup</h3>
<div>
In these tests, I compare my 4-year old Dell laptop with the Samsung ARM Chromebook. It's obviously not a very fair comparison: The laptop is quite obsolete now (and will actually be replaced soon). On the other hand, the Samsung ARM is a budget device, with a ridiculously low power consumption.<br />
<br /></div>
<table align="center" border="1" style="text-align: center;">
<tbody>
<tr><td></td><td><b>Dell Latitude E6400</b></td><td><b>Samsung Chromebook ARM</b></td></tr>
<tr><td><b>CPU</b></td><td>Intel Core2 Duo T9950 @ 2.66Ghz<br />
(no hyperthreading)</td><td>Samsung Exynos 5 Dual (5250)<br />
(Cortex A15; 1.7GHz dual core cpu)</td></tr>
<tr><td><b>RAM</b></td><td>4 GB</td><td>2 GB</td></tr>
<tr><td><b>GPU</b></td><td>NVIDIA Corporation G98M<br />
(Quadro NVS 160M)<br />
256MB dedicated RAM</td><td>ARM Mali T604<br />
(quad core)</td></tr>
<tr><td><b>OS</b></td><td>Archlinux<br />
(gcc 4.8.2)</td><td>Ubuntu 12.04 in crouton<br />
(gcc 4.6.3)</td></tr>
</tbody></table>
<br />
As a benchmark test suite, we use <a href="https://www.cs.virginia.edu/~skadron/wiki/rodinia/index.php/Main_Page" target="_blank">Rodinia</a>, a CUDA/OpenMP/OpenCL test suite from the University of Virginia.<br />
<br />
The test suite does not compile unmodified, and for some OpenCL tests, the number of threads need to be reduced to fit in the limited memory of both computers. Complete instructions and patches can be found in <a href="https://github.com/drinkcat/rodinia-benchmark" target="_blank">my github repository</a>.<br />
<h3 style="-webkit-text-stroke-width: 0px; color: black; font-family: 'Times New Roman'; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">
Test results - OpenMP</h3>
<div>
First we show comparisons using OpenMP, that only makes use of the CPU. We expect the Intel laptop to be far superior, and this is what we get:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj58IJuXbdFx_Llz7ePlfKsjnopzvjJdpBQL1frlrACcEj59-pvwoOWse5WMDSzGsX0Ijj42XM2aXCEONNkrYRmXPKgnyXtdg4jbFYH8V1eCW-QyrRkOTxYTXIolzHchQX7ayMUI_T7g7M/s1600/results-1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj58IJuXbdFx_Llz7ePlfKsjnopzvjJdpBQL1frlrACcEj59-pvwoOWse5WMDSzGsX0Ijj42XM2aXCEONNkrYRmXPKgnyXtdg4jbFYH8V1eCW-QyrRkOTxYTXIolzHchQX7ayMUI_T7g7M/s640/results-1.png" width="640" /></a></div>
The ARM CPU alone is between 1.75 and 4.5 times slower (average: 2.87 times slower). Not a big surprise considered the lower frequency and simpler architecture. On the other hand, the Chromebook stays cool (no fan!), while the Dell laptop blows out hot air on the side.</div>
<div>
<h3>
Test results - OpenCL</h3>
</div>
<div>
We can then compare the GPUs, using OpenCL tests in Rodinia:<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjR2UAUjLhh4oQWV6jaHAsag9bHSO1ePynWA50_oE098bGbgTcBARbB5VzXIBjpUZiG3gEKkR6ru5wKC7gkYD8Y0Maqr6kr0lZwM339vprqchEwibvHuUNYBsbYwgEEPIdJ9MY4UPzt_Cs/s1600/results-2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjR2UAUjLhh4oQWV6jaHAsag9bHSO1ePynWA50_oE098bGbgTcBARbB5VzXIBjpUZiG3gEKkR6ru5wKC7gkYD8Y0Maqr6kr0lZwM339vprqchEwibvHuUNYBsbYwgEEPIdJ9MY4UPzt_Cs/s640/results-2.png" width="640" /></a></div>
And this is where we get a nice surprise: the ARM GPU is very close in performance in most tests. Excluding ParticleFilter, which is 8 times slower, the GPU is, in the worst case, 1.94 times slower, and it is even 1.8 times faster in the Kmeans test (average: 1.25 times slower).</div>
<div>
<br /></div>
<div>
For some reason, I could not get the OpenCL code to compile on the Samsung ARM for LavaMD (it fails with CL_INVALID_KERNEL_ARGS), but I didn't try very hard. Let me know if you find a way! It would also be interesting to figure out why ParticleFilter is so slow.</div>
<div>
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: 'Times New Roman'; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">
<h3>
Test results correctness</h3>
</div>
</div>
<div>
The benchmark timings need to be taken with a bit a precaution, in case the results are garbled. Some tests do not produce any output, so it's hard to tell if the computation is correct. On the other hand, hotspot produce some output that can be plotted:</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi57i5wGUVX9zO-lPzDVFZJt457hIQKtX-0cNCl7N0BdZrgvy8sXW88Gg2Dc3itE0ah3AYiPJHKBLyAnHyCakXvM2UeqzXnArFXai53nipayuOj1mfGQjC-I9zSVwXWWTGV_HZ7A1NP6d8/s1600/hotspot.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="160" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi57i5wGUVX9zO-lPzDVFZJt457hIQKtX-0cNCl7N0BdZrgvy8sXW88Gg2Dc3itE0ah3AYiPJHKBLyAnHyCakXvM2UeqzXnArFXai53nipayuOj1mfGQjC-I9zSVwXWWTGV_HZ7A1NP6d8/s640/hotspot.png" width="640" /></a></div>
<div>
<br /></div>
<div>
As you can see, the results look identical in all cases.</div>
<div>
<br /></div>
<div>
To analyse the differences more precisely, we can measure some average numerical error between data results x and y of 2 different implementations, as follows:</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzt8cZrVEv3CW1Mpkj38mtrkia_MD5KVnOSGdQOspotetRCf4Bc-sofkm-6SaXxcStf9839bSkK1otkU492kCAiPfK34opZzWs59EQJOpUNcsqS6m5XaO8Fl47IRKOu2cSY26x3Shh9wU/s200/tex2png--10.cgi.png" width="100" /></div>
<div>
<br /></div>
<div>
And a summary of these errors, for 2 of the tests, where some output is created:<br />
<br />
<table align="center" border="1" style="text-align: center;">
<tbody>
<tr><td><b>Test</b></td><td><b>Variable</b></td><td colspan="3"><b>Error</b></td></tr>
<tr><td></td><td></td><td>x86 OpenMP<br />
vs<br />
x86 OpenCL</td><td>x86 OpenMP<br />
vs<br />
ARM OpenMP</td><td>x86 OpenCL<br />
vs<br />
ARM OpenCL</td></tr>
<tr><td><b>HotSpot</b></td><td>output</td><td>1.132563e-06</td><td>0</td><td>3.017828e-09</td></tr>
<tr><td rowspan="3"><b>CFD</b></td><td>density</td><td><span style="background-color: red;">249862.2</span></td><td>0</td><td>1.143825e-07</td></tr>
<tr><td>density_energy</td><td><span style="background-color: red;">253706.2</span></td><td>0</td><td>1.060202e-07</td></tr>
<tr><td>momentum[1]</td><td><span style="background-color: red;">322420.1</span></td><td>0</td><td>1.065893e-07</td></tr>
</tbody></table>
</div>
<br />
As you can see, running the OpenMP code on ARM and x86 gives identical results. The OpenCL results are also very close. That basically means the comparisons above between the 2 laptops is fair.<br />
<br />
When it comes to differences between OpenMP and OpenCL code, the HotSpot test shows a good agreement between the 2 versions. On the other hand, the CFD test outputs very different results between the 2 implementations. This is worrisome as CFD is one of the tests that shows most improvement using OpenCL compared to OpenMP...<br />
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: 'Times New Roman'; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">
<h3>
Test results - overall</h3>
<div>
The next graph shows all the results aggregated.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdNN-74l9OmnrwGXGoc_SYdPZVxk1ECYsK_YwJbB1z3K-lgV-zcrcFCpt2fPRIa7lfGbjKreIzfWGulnF1HqlMOFhTTViVqLPJ_hwZx3mckeRR_Y4QxMVsIyM4UJxE5b4Vo0n5HaL6am4/s1600/results-0.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdNN-74l9OmnrwGXGoc_SYdPZVxk1ECYsK_YwJbB1z3K-lgV-zcrcFCpt2fPRIa7lfGbjKreIzfWGulnF1HqlMOFhTTViVqLPJ_hwZx3mckeRR_Y4QxMVsIyM4UJxE5b4Vo0n5HaL6am4/s640/results-0.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div>
Assuming OpenCL and OpenMP implementations give similar results (which is actually doubtful in some cases, see the previous section), running OpenCL code on the Samsung Chromebook ARM can help a lot in terms of performance: On the Dell laptop, using OpenCL improves performance by a factor 2.25 on average. On the Chromebook ARM, the ratio is 4.1! And this is without any attempt at optimizing the code for the Mali architecture, which is quite different from a normal GPU (in particular, it has no local memory, so data does not need to be copied back and forth).</div>
<div>
<br /></div>
<div>
I'd also like to try some real applications, my next project is to get <a href="http://www.darktable.org/" target="_blank">darktable</a> running (a RAW photo developer). Do let me know if you have some real applications using OpenCL! I'll follow up with another post if I get them to work.</div>
</div>
Anonymoushttp://www.blogger.com/profile/12050625263370191802noreply@blogger.com0tag:blogger.com,1999:blog-7165329846281791578.post-25715647509213369292013-11-23T18:27:00.000+08:002013-11-23T18:27:46.381+08:00OpenCL on the Samsung Chromebook ARM, under crouton<div>
<div style="text-align: center;">
<i>In this post we’re going to look into OpenCL development on the <a href="http://drinkcat.blogspot.com/2013/06/chromebook.html" target="_blank">Samsung Chromebook ARM</a>, using crouton, and turn your</i><i> Chromebook into a </i><i>tiny </i><i>supercomputer for CFD or bioinformatics.</i></div>
<br /></div>
<div>
ARM recently posted some <a href="http://malideveloper.arm.com/develop-for-mali/features/graphics-and-compute-development-on-samsung-chromebook/" target="_blank">instructions about OpenCL development on the Chromebook ARM</a>, but these require creating a separate Ubuntu installation that you boot off a USB drive, and are quite lenghty. The instructions I provide here are very simple: They make use of <a href="https://github.com/dnschneid/crouton" target="_blank">crouton</a>, that allows you to run Chrome OS and Ubuntu in parallel, so that you can develop OpenCL applications without rebooting.<br />
<h3>
Download required files</h3>
</div>
<div>
Download the following files, and put them in Chrome OS <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Downloads</span> folder:
<br />
<ul>
<li><a href="https://github.com/dnschneid/crouton" target="_blank">crouton</a>: Read the information there if you do not know (yet) what crouton is all about. One important note, crouton requires that you switch your Chromebook to developer mode, which wipes all the data on the Chromebook (but that's required by the ARM approach as well).</li>
<li>Chrome OS does not provide an OpenCL driver, but you can get it from <a href="http://malideveloper.arm.com/develop-for-mali/drivers/mali-t6xx-gpu-user-space-drivers/" target="_blank">this page</a>: Mali Binary User Space Driver, Linux r3p0-02rel0 (22nd October 2013), X11 version. You can use this <a href="http://malideveloper.arm.com/downloads/drivers/binary/r3p0-02rel0/linux-x11-hf-r3p0-02rel0.tgz" target="_blank">direct link</a> to get the tarball.<br />Luckily, the newer userspace drivers work with the current kernel drivers in Chrome OS.</li>
<li><a href="http://malideveloper.arm.com/develop-for-mali/sdk/mali-opencl-sdk/" target="_blank">ARM Mali OpenCL SDK</a>, so you can test some pretty examples.</li>
</ul>
</div>
<h3>
Create crouton chroot</h3>
<div>
We are going to create a <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">precise</span> chroot (Ubuntu 12.04, but other releases should also work). You need at least the <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">x11</span> target to be installed, as Mali libraries depend on X11 libraries. This is actually an artificial dependency: OpenCL itself does not require X11, but the ARM Mali library is a single blob that provides OpenCL and OpenGL ES, and the latter depends on X11 libraries.<br />
<br />
We’re going to install <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">xfce</span>, as it pulls in the <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">x11</span> target, and gives you a nice and light desktop environment.</div>
<br />
<div>
Open a crosh shell, and create the chroot:</div>
<div class="code">
sudo sh -e crouton -r precise -t xfce</div>
<div>
This will take a while, depending on your Internet connection speed.<br />
<br />
Then start XFCE:</div>
<div class="code">
sudo startxfce4 -n precise</div>
<div>
Alternatively, if you’d rather stay in the command line, you can simply type:</div>
<div class="code">
sudo enter-chroot -n precise</div>
<h3>
Install OpenCL userspace drivers</h3>
<div>
Then, inside the chroot (if you have started XFCE, open a terminal), extract the Mali libraries:</div>
<div class="code">
mkdir -p ~/mali/lib<br />
tar xvf ~/Downloads/linux-x11-hf-r3p0-02rel0.tgz -C ~/mali/lib/
</div>
<div>
You also need to install 2 extra dependencies:</div>
<div class="code">
sudo apt-get install libxcb-dri2-0 libxcb-render0</div>
<div>
The libraries that we need to run OpenCL code, in particular <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">libOpenCL.so</span>, are now located in <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">~/mali/lib</span>. We could install these in <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">/usr/lib</span> or <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">/usr/local/lib</span>, so that the dynamic linker could find them automatically. However, in this case, we prefer setting an environment variable, in order to avoid touching the original Ubuntu filesystem:</div>
<div class="code">
export LD_LIBRARY_PATH=$HOME/mali/lib</div>
<h3>
Try out an example from Mali OpenCL SDK</h3>
<div>
Let's try an example from the SDK. First, you need to install some essential tools:</div>
<div class="code">
sudo apt-get install make g++</div>
Then, extract the SDK:
<br />
<div class="code">
cd ~/mali<br />
tar xvf /home/nicolas/Downloads/Mali_OpenCL_SDK_v1.1.0.0a36a7_Linux.tar.gz<br />
cd Mali_OpenCL_SDK_v1.1.0
</div>
<div>
Now modify <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">platform.mk</span>. We are not doing any cross-compilation here, so <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">CC</span> and <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">AR</span> can simply be set as:</div>
<div class="code">
CC:=g++<br />
AR=ar</div>
<div>
You can pick any example in the <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">samples</span> directory, but <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">mandelbrot</span> is probably the most "spectacular". First compile it:</div>
<div class="code">
cd samples/mandelbrot<br />
make</div>
Then run it:
<br />
<div class="code">
./mandelbrot</div>
<div>
The output is quite verbose, I’m yet to figure out how to make use of instrumentation and debugging features of the Mali OpenCL library:</div>
<div class="code">
[PLUGIN INFO] Plugin initializing<br />
[PLUGIN DEBUG] './override.instr_config' not found, trying to open the process config file<br />
[PLUGIN DEBUG] './mandelbrot.instr_config' not found, trying to open the default config file<br />
[PLUGIN ERROR] Couldn't open default config file './default.instr_config'.<br />
[PLUGIN INFO] No configuration file found, attempting to use environment<br />
[PLUGIN INFO] CINSTR GENERAL: Output directory set to: . <br />
[PLUGIN INFO] No instrumentation features requested.<br />
Profiling information:<br />
Queued time: 0.115ms<br />
Wait time: 0.605292ms<br />
Run time: 2218.38ms
</div>
<div>
In exchange for 2 seconds of GPU time, you get a nice Mandelbrot fractal in <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">output.bmp</span>.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJxryEjuZUiLJhtA_eHtly7QP32zjUyoo3p0MOkxtc-_HpgK0NbhqtccZMznfayUUWmBTjM1qfrJ61FqQ09k2AxRRF5DBnet5RSAeHuxaUhTD1o66um07vbidTHg8ylwmNM3kWZXjhq2I/s1600/output.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJxryEjuZUiLJhtA_eHtly7QP32zjUyoo3p0MOkxtc-_HpgK0NbhqtccZMznfayUUWmBTjM1qfrJ61FqQ09k2AxRRF5DBnet5RSAeHuxaUhTD1o66um07vbidTHg8ylwmNM3kWZXjhq2I/s400/output.png" width="400" /></a></div>
<br /></div>
That’s it! The next post will focus on some benchmarks, and comparison with a x86 laptop GPU and OpenMP implementations.Anonymoushttp://www.blogger.com/profile/12050625263370191802noreply@blogger.com0tag:blogger.com,1999:blog-7165329846281791578.post-89135123070127779942013-10-06T19:00:00.000+08:002013-12-17T20:08:58.699+08:00Running Chromium OS in QEMUIf you'd like to have a taste of Chrome/Chromium OS before buying an actual Chromebook, the recommended way used to be to download the <a href="http://chromeos.hexxeh.net/" target="_blank">Hexxeh images</a>, and run them in a virtual machine (Virtualbox). However, these images are now quite outdated.<br />
<br />
The steps I mention here use development Chromium OS builds, made available by the Chromium developers. The resulting "experience" is still quite different from running Chrome OS on a proper device: there is no graphics acceleration, there are no applications installed by default, and the user interface is painfully slow. However, this is still good enough to get a general idea (or do some development).<br />
<h3>
Fetch the image</h3>
<div>
First, go the <a href="http://build.chromium.org/p/chromiumos/builders" target="_blank">Chromium OS builders page</a>, then click the architecture you want. This following assumes you are picking <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">amd64 generic full</span><span style="font-family: inherit;"> (only use </span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">full</span><span style="font-family: inherit;"> images, don't even try the other ones), but other architectures should also work. </span><span style="font-family: inherit;">On the next page, choose one of the builds, for example, </span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><a href="http://build.chromium.org/p/chromiumos/builders/amd64%20generic%20full/builds/9624" target="_blank">#9624</a></span><span style="font-family: inherit;">. Then, under step </span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">16. Report</span><span style="font-family: inherit;">, click on </span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Artifacts</span><span style="font-family: inherit;">. You are presented with a list of files: download</span> <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">chromiumos_qemu_image.tar.xz</span>.</div>
<h3>
Extract the image</h3>
<div>
Now, let's extract the image. It is a 8GB file, but contains mostly mostly zeros. We use dd to recreate a <a href="http://en.wikipedia.org/wiki/Sparse_file" target="_blank">sparse file</a>, to save a significant amount of disk space:</div>
<div class="code">
$ tar xvfO chromiumos_qemu_image.tar.xz chromiumos_qemu_image.bin |<br />
dd of=chromiumos_qemu_image.bin conv=sparse</div>
<div>
If you have a lot of hard drive space, you can ignore that, and simply run:</div>
<div class="code">
$ tar xvf chromiumos_qemu_image.tar.xz</div>
<div>
<h3>
Start QEMU</h3>
</div>
<div>
Now, let's start QEMU:</div>
<div class="code">
$ qemu-system-x86_64 -enable-kvm -m 1024 -net nic -net user -redir tcp:9922::22 -hda chromiumos_qemu_image.bin</div>
<div>
If permissions are setup properly, you do not need to run this as root.<br />
The parameters serve the following purpose:</div>
<div>
<ul>
<li><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">-enable-kvm</span>: Makes sure we use hardware virtualisation extensions.</li>
<li><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">-m 1024</span>: Give 1GB of memory to Chromium OS. If you don't specify this, the default is 128MB, which is far from enough to run Chromium OS.</li>
<li><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">-net nic -net user</span>: creates a virtual ethernet interface</li>
<li><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">-redir tcp:9922::22</span>: Since those are development builds, they come with an SSH server. This redirects local port 9922 to the chroot's port 22 (more on this later)</li>
<li><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">-hda chromiumos_qemu_image.bin</span>: Use the image as hard drive.</li>
</ul>
<div>
And now you should see Chromium OS booting. In some cases, you may be unlucky, and the build you have picked may be broken (remember, those are development builds). In this case, pick an older build (2-3 days older at least), and retry.</div>
<h3>
Access the virtual machine via SSH</h3>
<div>
This is mostly useful for developers. The SSH server only allows login via public keys (no password authentication). To setup the public key, follow the following steps:</div>
<div>
<ul>
<li>Setup a <a href="http://www.debian.org/devel/passwordlessssh" target="_blank">SSH private/public key pair</a> on the host machine, if you don't have one already.</li>
<li>Copy the content of <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">~/.ssh/id_rsa.pub</span> into a pastebin, Google Doc, or whatever web page you can access from the Chromium OS.</li>
<li>In Chromium OS, browse to the pastebin/Google Doc, and copy the key information.</li>
<li>Then press <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Ctrl-Alt-T</span>: this opens a new crosh shell, and type:</li>
</ul>
<div class="code">
> shell<br />
$ cd<br />
$ mkdir .ssh<br />
$ cat > authorized_keys</div>
<div>
<ul>
<li>Then paste the content of the key, using <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Ctrl-Shift-V</span>, and press <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Ctrl-D</span> to terminate.</li>
</ul>
<div>
Now you can access your QEMU "Chromiumbook" from your host, using:
</div>
<div class="code">
ssh chronos@127.0.0.1 -p 9922
</div>
And you can even mount a shared directory on the virtual machine with something like:</div>
</div>
<div class="code">
sshfs chronos@127.0.0.1:Downloads/ssh ssh.qemu -p 9922</div>
I you later restart QEMU, you will need to login in Chromium OS before the steps above work again.<br />
<div>
That's it! I find this particularly useful when I develop for <a href="https://github.com/dnschneid/crouton" target="_blank">crouton</a>/<a href="https://github.com/drinkcat/chroagh" target="_blank">chroagh</a>, as I only have a <a href="http://drinkcat.blogspot.sg/2013/06/chromebook.html" target="_blank">Samsung ARM Chromebook</a>. With this setup, I can test my code on <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">x86</span> and <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">x86_64</span> architectures.</div>
</div>
Anonymoushttp://www.blogger.com/profile/12050625263370191802noreply@blogger.com1tag:blogger.com,1999:blog-7165329846281791578.post-13299128982666885562013-09-30T19:00:00.000+08:002013-09-30T20:22:44.783+08:00Tracking your DHL package in conky<i>(or converting the DHL tracking page from HTML to plain text, using XSLT)</i><br />
<br />
So, let me explain the problem: You have that package shipped by DHL, and its tracking number. And you're so eager to receive it, that you end up checking the package tracking page every 5 minutes. Your productivity falls to zero.<br />
<br />
But, worry no more! Let's put the package status inside your <a href="http://conky.sourceforge.net/" target="_blank">conky</a>, so that you can just have a quick look on the side of your screen, and continue working.<br />
<br />
Just in case you don't know (but really, you should), conky is the information bar on the right of the screenshot below:<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxGSYELIb-hn-EuUGvzGHyU8Udn8QHo3R3nMPmGGP_s6Xs9CUSvdzt9qh3P9ZHoiApVdf5xNil8ql9KrsjX7Vv9xyMHYXKj9FnMZjw50Ol8kPsiy5EUMBByShkIQ3LUXBeYf7Ko7FH8nM/s1600/screenshot.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxGSYELIb-hn-EuUGvzGHyU8Udn8QHo3R3nMPmGGP_s6Xs9CUSvdzt9qh3P9ZHoiApVdf5xNil8ql9KrsjX7Vv9xyMHYXKj9FnMZjw50Ol8kPsiy5EUMBByShkIQ3LUXBeYf7Ko7FH8nM/s640/screenshot.png" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">conky is the information bar on the right on the display. CPU/RAM usage, disk free space, network status, temperature, a calendar, my DHL tracking thing, then weather in a few places.<br />
In case you wonder, and the background is somewhere in Hue, Vietnam.<br />
And don't worry about the gimp error, really.</td></tr>
</tbody></table>
The idea is to write the code that can generate this:<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhiHmvhkZdMT1yKtxbHx95xml84Mvpry-meejWD6YKX1wqXOGKTaSqO3NzxdURFZzaSrHoh6wP6I0NscszUAlwIpe8WC9yLPvlcN-MGecfLBn9VSYyxS_RJ7vNf_s4QOOpg2MkuCnxeJcc/s1600/screenshot-zoom.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhiHmvhkZdMT1yKtxbHx95xml84Mvpry-meejWD6YKX1wqXOGKTaSqO3NzxdURFZzaSrHoh6wP6I0NscszUAlwIpe8WC9yLPvlcN-MGecfLBn9VSYyxS_RJ7vNf_s4QOOpg2MkuCnxeJcc/s1600/screenshot-zoom.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Yes, they spelled my name wrong...</td></tr>
</tbody></table>
<br />
From something as ugly looking as this:
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXl5il02eErmPPv1puE4dS04mNmqh0B9iEHFp3mq8Q07fbdrmUm9WtwqvjkzsyYx7p5Mtvrx6iqjLjA7KmpOCIW6uXbJA06b80_ZUaVD4p0buqt9PVLWLKy-OKRyzKZwn1sLVPePcq2jY/s1600/screenshot-dhl.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="268" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXl5il02eErmPPv1puE4dS04mNmqh0B9iEHFp3mq8Q07fbdrmUm9WtwqvjkzsyYx7p5Mtvrx6iqjLjA7KmpOCIW6uXbJA06b80_ZUaVD4p0buqt9PVLWLKy-OKRyzKZwn1sLVPePcq2jY/s400/screenshot-dhl.png" width="400" /></a></div>
<h3>
I don't care how it works, I just want to get it running</h3>
Ok! After all the point of this was to increase your productivity, right? You can fetch the script from <a href="https://github.com/drinkcat/tracking-conky" target="_blank">my github</a>.<br />
<br />
Then call it with:<br />
<div class="command">
./dhl <AWB></div>
<div>
Where <span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><AWB></span> is the Waybill number (tracking number). It produces a text-only tracking information for your package.<br />
<br />
You can integrate it in your conky with something like:
<br />
<div class="code">
${font Monospace:size=6}${execi 60 ~/.conky/dhl <AWB> | head -n 3 | fold -w 16}$font</div>
<br />
Replace <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">~/.conky/dhl</span> with the path to where you copied the script. Change <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">head</span> parameter if you want more lines, and <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">fold</span> inserts new lines every 16 characters (change that depending on your conky width).
<br />
<br />
Now, if you want to know how it works, so you can fix it if it breaks, or update the code for other shipping companies, continue reading.<br />
<h3>
Inspecting the HTML source</h3>
The tracking URL looks like this (where <span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><AWB></span> is your tracking number):
<br />
<div class="code">
http://www.dhl-usa.com/content/us/en/express/tracking.shtml?brand=DHL&AWB=<AWB></div>
Looking at the HTML source, we notice that the interesting stuff is enclosed in a table:
<br />
<div class="code">
<table border="0" summary="Summary of table content"></div>
Then, you have a succession of <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">thead</span>/<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">tbody</span> tags. The first <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">thead</span> contains general information about the package, that we are not interested in. It starts like this (notice it has class "<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">tophead</span>"):<br />
<div class="code">
<thead class="tophead"></div>
The next <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">thead</span> shows the date valid for the following entries. We are only interested in the first column here (the one that contains the date).<br />
<div class="code">
<thead><br />
<tr><br />
<td colspan="5" class="emptyRow"></td><br />
</tr><br />
<tr><br />
<th scope="col" colspan="2" axis="length"<br />
style="width: 40% ;text-align:left">Thursday, September 19, 2013 </th><br />
<th scope="col" axis="length"<br />
style="width: 30% ;text-align:left ">Location</th><br />
<th scope="col" axis="length"<br />
style="width: 9%;text-align:left">Time</th><br />
<th scope="col" axis="length" class="lastChild"<br />
style="width: 25% ;text-align:left">&nbsp;</th><br />
</tr><br />
</thead></div>
Finally, the bulk of the events are enclosed in <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">tbody</span>. The first column is a incremented number, the second one is a description of what happened (passed customs, arrived at destination, etc.), the third one tell you the location (but this is often repeated in the description), and the fourth one is the time.
<br />
<div class="code">
<tbody>
<br />
<tr>
<br />
<td class="" style="width: 5% ;text-align:left">18</td><br />
<td class="" style="text-align:left">With delivery courier</td><br />
<td class="" style="text-align:left">SINGAPORE - SINGAPORE</td><br />
<td class="">7:27 PM</td>
<br />
<td class="lastChild "><!--start contentteaser -->
<br />
<div class="dhl">
<br />
<div><div class="clearAll">&nbsp;</div></div><br />
</div><!--end contentteaser --></td><br />
</tr>
<br />
</tbody>
</div>
Ok, now we have an idea of the structure, let's parse that!
<br />
<h3>
Parse HTML with XSLT</h3>
Ok, so let's say you have the DHL tracking page downloaded to <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">/tmp/dhl.tmp</span>, and an XSLT file in <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">dhl.xslt</span>, you can parse the page with:
<br />
<div class="command">
xsltproc --html dhl.xslt /tmp/dhl.tmp</div>
The XSLT file looks like this:
<br />
<div class="code">
<?xml version="1.0" encoding="UTF-8"?>
<br />
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<br />
<xsl:output method="text" encoding="utf-8" />
<br />
<xsl:template match="/">
<br />
<xsl:for-each select="//table[@summary='Summary of table content']/*[self::thead|self::tbody][not(@class)]">
<br />
<xsl:choose>
<br />
<xsl:when test="name(.) = 'thead'">
<br />
<xsl:value-of select="tr/th[1]"/>
<br />
<xsl:text>
<br />
</xsl:text>
<br />
</xsl:when>
<br />
<xsl:otherwise>
<br />
<xsl:if test="floor(tr/td[1]) = tr/td[1]">
<br />
<xsl:value-of select="normalize-space(tr/td[4])"/>
<br />
<xsl:text>: </xsl:text>
<br />
<xsl:value-of select="normalize-space(tr/td[2])"/>
<br />
<xsl:text>
<br />
</xsl:text>
<br />
</xsl:if>
<br />
</xsl:otherwise>
<br />
</xsl:choose>
<br />
</xsl:for-each>
<br />
</xsl:template>
<br />
</xsl:stylesheet>
</div>
Let's take it step by step. It starts like this:
<br />
<div class="code">
<?xml version="1.0" encoding="UTF-8"?>
<br />
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<br />
<xsl:output method="text" encoding="utf-8" />
<br />
<xsl:template match="/"></div>
Nothing special here, apart from the <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">text</span> output mode, so that <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">xsltproc</span> outputs a text file (and not another XML file...).<br />
<br />
Now begins the fun. We look for a table with <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">summary</span> attribute <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">'Summary of table content'</span>. Inside that table, we look for <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">thead</span> and <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">tbody</span> elements, that do not have a class attribute set, so we can exclude the <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">'tophead'</span> row, that we are not interested in.
<br />
<div class="code">
<xsl:for-each select="//table[@summary='Summary of table content']/*[self::thead|self::tbody][not(@class)]"></div>
Now, <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">thead</span> (containing only the date of the following events) and <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">tbody</span> (containing events) need to be parsed differently. This is done with <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">xsl:choose</span>:
<br />
<div class="code">
<xsl:choose>
<br />
<xsl:when test="name(.) = 'thead'">
<br />
...
<br />
</xsl:when>
<br />
<xsl:otherwise>
<br />
...
<br />
</xsl:otherwise>
<br />
</xsl:choose></div>
For <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">thead</span>, we just want to show the date, that is the first <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">th</span> inside a <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">tr</span> (<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">tr/th[1]</span>). Then we print a new line with <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">xsl:text</span>.
<br />
<div class="code">
<xsl:when test="name(.) = 'thead'">
<br />
<xsl:value-of select="tr/th[1]">
<br />
<xsl:text>
<br />
</xsl:text>
<br />
</xsl:value-of></xsl:when>
</div>
For <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">tbody</span>, it is slightly more complicated. First, we check that the first column is indeed a number (this removes the last row in the table, which is another type of summary): this is done with a "trick" (<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">floor(tr/td[1]) = tr/td[1]</span>). Then we print the time (4th column), followed by a colon, and the event description (2nd column).<br />
<div class="code">
<xsl:otherwise>
<br />
<xsl:if test="floor(tr/td[1]) = tr/td[1]">
<br />
<xsl:value-of select="normalize-space(tr/td[4])"/>
<br />
<xsl:text>: </xsl:text>
<br />
<xsl:value-of select="normalize-space(tr/td[2])"/>
<br />
<xsl:text>
<br />
</xsl:text>
<br />
</xsl:if>
<br />
</xsl:otherwise>
</div>
That's it! Then you can put everything in a shell script, see <a href="https://github.com/drinkcat/tracking-conky/blob/master/dhl" target="_blank">the complete code on github</a> for details.<br />
<h3>
It's so cool, I want more!</h3>
I get it. I, too, have become of fan of parsing XML/HTML from scripts. See <a href="http://drinkcat.blogspot.sg/2013/06/parse-xml-from-shell-scripts.html" target="_blank">this post</a> for another example.</div>
Anonymoushttp://www.blogger.com/profile/12050625263370191802noreply@blogger.com0tag:blogger.com,1999:blog-7165329846281791578.post-34545417093182035552013-07-25T19:00:00.000+08:002013-09-30T19:08:25.405+08:00Bokeh-fixing: Opening and cleaning an Olympus OM 50mm f/1.8In the previous post, I talked about the <a href="http://drinkcat.blogspot.sg/2013/07/olympus-om-50mm-f18-on-mft.html" target="_blank">Olympus OM 50mm f/1.8</a>, and how I find it interesting to use on my Micro Four Thirds camera (Panasonic DMC-GX1), along with some sample shots.<br />
<br />
When taking some night shots, with an object close in focus, I could see obvious defects in the <a href="http://en.wikipedia.org/wiki/Bokeh" target="_blank">bokeh</a>, that is, the round circle of light coming from a distant, out-of-focus, light.<br />
<br />
The next image is taken by pointing at a spot light about 200m away, but setting the focus at its closest position (0.45m). This gives a large bokeh:<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglvBbnVFfceqJ87Bfyv83QacDBRuqSJwT_5k9wiNve9FGcrzkSHrveS5YKR_BFzxzMk4yGugnXfpgyjy5Ph967XC1m2mXEDrLeeXJUyJF7IlriSaAlgrWmDIK907nQFqR0QhZ81Frbuxw/s1600/P1200733a.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglvBbnVFfceqJ87Bfyv83QacDBRuqSJwT_5k9wiNve9FGcrzkSHrveS5YKR_BFzxzMk4yGugnXfpgyjy5Ph967XC1m2mXEDrLeeXJUyJF7IlriSaAlgrWmDIK907nQFqR0QhZ81Frbuxw/s320/P1200733a.JPG" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Spot light is about 200m away, focus set at 0.45m, aperture f/1.8. ISO 1600, 1/40s. The bokeh dimension is about 1000x1000 pixels, that is a little more than a fifth of the width of the image.</td></tr>
</tbody></table>
Clearly, something is wrong here: there are some black dots and strange reflections on the left side of the bokeh circle.<br />
<br />
By looking inside the lens, I can see something that looks like oil drops, apparently not far from the back, maybe behind the outermost lens. I'm wondering if it comes from the aperture mechanism, since it's slow and has obvious oil marks on it, but I can't tell for sure.<br />
<br />
I looked up online, and <a href="http://www.dpreview.com/forums/thread/2643603" target="_blank">some people on dpreview forums</a> advise that it may not be worth the fuss trying to open it up, and it would be easier to buy a new one, considered the price. On the other hand, it is such a cheap lens (~25USD with shipping) that it would not be a disaster if I broke it. Looking further, I found some diagrams on <a href="http://olympus.dementix.org/Hardware/" target="_blank">Olympus Dementia</a>, but even if you can figure out which exact model of lens you have (Olympus made multiple fairly different versions over the years), it still does not tell you how to open it.<br />
<br />
Anyway, since my problem looked like to be at the back, and since there are 3 obvious screw there, I decided to start on that side:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKqxyAERAOv-kTIK3G24l1UeCrz2QjVaxsabTZm5tr99CvgCXSNnomZbz-DhPsCk8TGi9gXZkNfe_ucPuVoZFsDcrzvZ7E-_xbUGQXb6yQOd5AjxPTMbPh5p6PLm39K8xS0PA8xFSqocw/s1600/P1200736a.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKqxyAERAOv-kTIK3G24l1UeCrz2QjVaxsabTZm5tr99CvgCXSNnomZbz-DhPsCk8TGi9gXZkNfe_ucPuVoZFsDcrzvZ7E-_xbUGQXb6yQOd5AjxPTMbPh5p6PLm39K8xS0PA8xFSqocw/s640/P1200736a.JPG" width="640" /></a></div>
<br />
It comes out easy. The lever to unlock the lens from the mount falls down (left on the picture below), but it isn't very tricky to find out how to put it back:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBl-iaoRPWB9AKDNU18Odju7EayB3-F9Qm5MW97G146X6ZDaZ7pFkDdnKMMGaqeLln21E8VPl-63tznmtEmLs5h62_W8R6l2H_QNmS8Obit5NGf7J6MKprNuiutgTMQr-GkDkzF8D2c8k/s1600/P1200740a.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBl-iaoRPWB9AKDNU18Odju7EayB3-F9Qm5MW97G146X6ZDaZ7pFkDdnKMMGaqeLln21E8VPl-63tznmtEmLs5h62_W8R6l2H_QNmS8Obit5NGf7J6MKprNuiutgTMQr-GkDkzF8D2c8k/s640/P1200740a.JPG" width="640" /></a></div>
<br />
Then, a big part of the aperture mechanism comes out easily. This mechanism contains a spring that opens the aperture to the maximum. When the aperture lever is pressed (right of the picture), the spring is extended, and the lens stops down to the desired setting on the aperture ring. I took out the whole thing, taking care of keeping all the elements together. The lever falls out, but it's easy to figure out how to put it in again:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxFUqKvJtEbxuSsTAsFevDyaVTkNfOYzPndIEZsJplZJ7YuNhyRW5GkypMHgx0kKwLBqzNJhSUbTJRQqSOp4u9RsOF3dLb9AHj6Pw5Ndwh-qAk4YBcQ8O-EQMcM1UQEcStNiLSDqRVp38/s1600/P1200741a.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="518" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxFUqKvJtEbxuSsTAsFevDyaVTkNfOYzPndIEZsJplZJ7YuNhyRW5GkypMHgx0kKwLBqzNJhSUbTJRQqSOp4u9RsOF3dLb9AHj6Pw5Ndwh-qAk4YBcQ8O-EQMcM1UQEcStNiLSDqRVp38/s640/P1200741a.JPG" width="640" /></a></div>
<br />
Then I'm left with this, and nothing obvious to remove. I want to remove the metal ring at the top, as it looks like there is oil right behind the glass that it is holding. It is screwed to the bottom part, but hard to remove. I notice some glue near the joint, so I scratch it off with a box cutter:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicJsVShyphenhyphenrAZ40VSkfuPU9YRKYw30XdxgGxIiz_m0tyqLb8BuKadlXowhqpmeFDrXyeQLpz8pQAgaBwyVndp6CQTCsukIbSZa-PmAKGLhOamLibACWwo5kaynZxMRM8VkmagDfu1SlQ_1w/s1600/P1200743a.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicJsVShyphenhyphenrAZ40VSkfuPU9YRKYw30XdxgGxIiz_m0tyqLb8BuKadlXowhqpmeFDrXyeQLpz8pQAgaBwyVndp6CQTCsukIbSZa-PmAKGLhOamLibACWwo5kaynZxMRM8VkmagDfu1SlQ_1w/s640/P1200743a.JPG" width="640" /></a></div>
<br />
And after this, I managed to open it up, using a soft cloth to give me more grip and avoid damaging the lens (you can see some scratch on the screw thread, that's where the glue was):<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyxAcYrQkVKrHdMECLlR7hpnnECE5S3-p-o2E1kc1Hn0t5RJtUbWxSIJDQM5vVvzcJDB1NnAVFM4FZM5ZELED0Tfp2ajOwHvCuJ-LEz5LSxRyNPlgdFWFtkc1Tkb5m-ogo6_2v7ZiiNUQ/s1600/P1200744a.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="528" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyxAcYrQkVKrHdMECLlR7hpnnECE5S3-p-o2E1kc1Hn0t5RJtUbWxSIJDQM5vVvzcJDB1NnAVFM4FZM5ZELED0Tfp2ajOwHvCuJ-LEz5LSxRyNPlgdFWFtkc1Tkb5m-ogo6_2v7ZiiNUQ/s640/P1200744a.JPG" width="640" /></a></div>
<br />
The top glass is now free, and the easiest is to remove it by gravity: invert the lens, hold it in a soft cloth so that the glass does not fall down too hard, and shake it a bit.<br />
<br />
No oil on that lens, but, luckily, I could spot it on the lens just below. I did not want to introduce any liquid in the lens, so I removed it the best I could, possibly smudging around instead of properly removing it, actually. A more proper way would have been to find the way to take out that glass, but, well, that would have required significantly more work.<br />
<br />
After getting convinced that most of it was removed (or at least evened out...), I reassembled it, and took the same picture. Notice the improvement!<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXbwKCA5Alxv0pdHDqt1q70VRuqzv1EwT4b8qz8CLcPHdj_-c0ROvDqUvOfk_CBncTAxSF9i1mDrreF9-q7_IMBsLRQ7Fzs24BzpyFaisXvB20r1M1NJD1e9aio8bdDS3_q37koYpljHE/s1600/before-after.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXbwKCA5Alxv0pdHDqt1q70VRuqzv1EwT4b8qz8CLcPHdj_-c0ROvDqUvOfk_CBncTAxSF9i1mDrreF9-q7_IMBsLRQ7Fzs24BzpyFaisXvB20r1M1NJD1e9aio8bdDS3_q37koYpljHE/s640/before-after.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Left: before, Right: after. There is still a slight smudge on the right, but it is noticeably better.</td></tr>
</tbody></table>
And my 13.5 USD 50mm f/1.8 recovers it's original beautiful bokeh!Anonymoushttp://www.blogger.com/profile/12050625263370191802noreply@blogger.com0tag:blogger.com,1999:blog-7165329846281791578.post-23684836279495014492013-07-22T19:00:00.000+08:002013-09-30T19:08:09.089+08:00Olympus OM 50mm f/1.8 on Micro Four ThirdsOne of the strong points of the Micro Four Thirds (MFT) system is that, thanks to its short <a href="http://en.wikipedia.org/wiki/Flange_focal_distance" target="_blank">flange focal distance</a>, you can mount lenses designed for almost any other camera system.<br />
<br />
I believe you can get the best deals by buying Olympus OM lenses: There is no current camera supporting those lenses anymore, but they were produced in mass in the 80's and 90's. These are ingredients for a high supply, low demand, therefore low prices on auction websites.<br />
<br />
This is especially true of the Olympus OM 50mm, f/1.8, that used to be a kit lens with many film Olympus cameras. Almost a year ago, I bought one on eBay, for 13.50 USD (+ 11 USD shipping). I mounted it on my Panasonic DMC-GX1, using a OM to MFT adapter (less than 10 USD).<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtcjlSxGLS8rQE3L9kGKXyQKIIGpt0_Qsu_OcyAL1bc5S2pjE8DkiCeZB8M7YiEDaDWKVSvpO6cAAypeRxPK_BMVD2yuw7Vsq4I67RkoUP3VktCwjZSSLc5noSE8uWJZ-QH4LGYQQXzF0/s1600/P1200737a.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtcjlSxGLS8rQE3L9kGKXyQKIIGpt0_Qsu_OcyAL1bc5S2pjE8DkiCeZB8M7YiEDaDWKVSvpO6cAAypeRxPK_BMVD2yuw7Vsq4I67RkoUP3VktCwjZSSLc5noSE8uWJZ-QH4LGYQQXzF0/s400/P1200737a.JPG" width="397" /></a></div>
<br />
I originally bought this lens to use it as part of a <a href="http://drinkcat.blogspot.sg/2013/02/tilt-adapter-for-micro-four-third-part1.html" target="_blank">custom tilt-shift adapter</a>, but realised that the <a href="http://drinkcat.blogspot.sg/2013/02/tilt-adapter-for-micro-four-third-part2.html" target="_blank">50mm focal length is usually too narrow</a>, and purchased a Promaster 28mm f/2.8 for that purpose (OM mount as well).<br />
<br />
This lens is really amazing (especially considered its price): It becomes a short telephoto lens on the MFT system (100mm full-frame equivalent), which gives you interesting constraints: you have to focus on details, or put some distance between you and your subject. The large aperture makes it particularly interesting in low-light conditions (museums, night markets, etc.). On the other hand, it does require ND filters in bright daylight, as you are hitting the maximum shutter speed of the camera (1/4000s for the GX1): a 3-stop ND filter, that is ND8 or 0.9 optical density, works perfectly for these situations. I actually never stop the aperture down: I would rather switch to another lens if I want more depth of field.<br />
<br />
Focusing is not easy, especially without a viewfinder. MFT cameras provide a magnified view to help you focus, but, with a bit of practice, I'm able to get a reasonably good focus without using that mode, by moving the ring back and forth until I have a good idea of the best position.<br />
<br />
The lens I got was in good condition, except for the aperture, that is a bit sluggish: you need to jiggle the aperture ring to get it back to f/1.8 if you stop it down. I could also see some oil on the aperture blades: probably the reason why the mechanism is not working as well as expected. But again, since I only use it at maximum aperture, this is not really a concern for me.<br />
<br />
I used that lens for a number of night shots, and realised that the <a href="http://en.wikipedia.org/wiki/Bokeh" target="_blank">bokeh</a> is not exactly as round and nice as it should be: there is some "dirt" on the left side of the disk (when held in landscape orientation). This does not show up clearly in most shots, but it looks quite silly when the same pattern repeats in different locations on the frame:<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL9tPXUjNQHsQJoLnlF7_1T51CqO8HQcrVAAup22CeV3KHAoYpt1q1HKRkJ0P4vdUZdFMxbtgGuLxE830B2JQubW5usjrNs2tROqZdmy2UDsCGZzAd4flC_-D_AQ9oBNkJrMJCKPRI0w4/s1600/P1150710.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL9tPXUjNQHsQJoLnlF7_1T51CqO8HQcrVAAup22CeV3KHAoYpt1q1HKRkJ0P4vdUZdFMxbtgGuLxE830B2JQubW5usjrNs2tROqZdmy2UDsCGZzAd4flC_-D_AQ9oBNkJrMJCKPRI0w4/s320/P1150710.JPG" width="240" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Each of the bokeh rings shows some black spots at the bottom: looking through the lens, I can see some oil marks.</td></tr>
</tbody></table>
The next post will show you how I managed to fix the problem, by opening up the lens.<br />
<br />
In the mean time, I uploaded on Flickr a <a href="https://www.flickr.com/photos/96267469@N06/sets/72157634684493531/" target="_blank">collection of photos taken with that lens</a>:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://www.flickr.com/photos/96267469@N06/sets/72157634684493531/" target="_blank"><img border="0" height="800" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8XXzf6H5gDURK9UeitDSZPUMe9J680EnXnh0-Tb6patfiE_8h1MtlMaqBWyhf3SPH_MqTmfy7uT0nY12_M_ow-C0tUWlA1SxCUHMstW1LpHOX6N6UuHkqz0Egmrf3uvnuwhYt72ZRm0k/s800/montage.jpg" width="457" /></a></div>
<br />
<br />Anonymoushttp://www.blogger.com/profile/12050625263370191802noreply@blogger.com0tag:blogger.com,1999:blog-7165329846281791578.post-90828472293295578082013-06-19T18:00:00.000+08:002013-06-19T18:35:24.142+08:00Good morning haze!Yesterday morning Singapore woke up under <a href="http://sg.news.yahoo.com/singapore-hit-haze-indonesia-forest-fires-060558314.html" target="_blank">thick haze</a> due to forest fires in nearby Sumatra. <a href="http://sg.news.yahoo.com/haze-reaches--unhealthy--level-in-singapore-085448213.html" target="_blank">Not healthy</a>: You can feel it in your throat, and some corridors smell like <a href="http://en.wikipedia.org/wiki/Scamorza" target="_blank">Scamorza</a> (some delicious Italian smoked cheese).<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://upload.wikimedia.org/wikipedia/commons/thumb/8/85/Scamorza.jpg/800px-Scamorza.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="239" src="http://upload.wikimedia.org/wikipedia/commons/thumb/8/85/Scamorza.jpg/800px-Scamorza.jpg" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">It smells just like that... (Image from <a class="extiw" href="http://de.wikipedia.org/wiki/User:Necrophorus" title="de:User:Necrophorus">Necrophorus</a>@<a href="http://en.wikipedia.org/wiki/File:Scamorza.jpg" target="_blank">Wikipedia</a>, GFDL)</td></tr>
</tbody></table>
Anyway... it gives some "interesting" light when the sun is low.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhm6trT1f1ssGhFNBztIXtaDOCKddGrXuqad78GlmWVmGpqYnFH4mz6qAQE3PU_FYOLm2mdw58qyyQCD-lM_0It2mp1yMps6jb8DgkKMFjLAaQUwcmZ1ZxwdqbGK5kZTKGb_JIABcsTmzg/s1600/P1200433.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhm6trT1f1ssGhFNBztIXtaDOCKddGrXuqad78GlmWVmGpqYnFH4mz6qAQE3PU_FYOLm2mdw58qyyQCD-lM_0It2mp1yMps6jb8DgkKMFjLAaQUwcmZ1ZxwdqbGK5kZTKGb_JIABcsTmzg/s640/P1200433.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Good morning purée... (slightly underexposed)</td></tr>
</tbody></table>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZKshyKpNp8NCJ0LAi7VyX5PCNdeaG9hb-366dOyuORsHhhD5Okyak_psSkVgaYFZgbI0-33AZ0Z70_s7zpi-TrJ4l1lo2it3TfPhUCrylSKMYBsB6ssuDA79jGUvz-j3gcLk2_Pndd80/s1600/P1200442.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZKshyKpNp8NCJ0LAi7VyX5PCNdeaG9hb-366dOyuORsHhhD5Okyak_psSkVgaYFZgbI0-33AZ0Z70_s7zpi-TrJ4l1lo2it3TfPhUCrylSKMYBsB6ssuDA79jGUvz-j3gcLk2_Pndd80/s640/P1200442.JPG" width="480" /></a></div>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrm-fgppiv7PUNPwMuyxkN9y3CUVdj3NAS0w8dqrUf4a2T8Dei7vc8yFZIth3IKJx7VDNOgVhY_2lOdHHzvLXmkfYG8yW1D0dDnxRlr5YK46PUeBNhy3Y4MlFkOP2Uf62OoFMwpe8tKIs/s1600/P1200449.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrm-fgppiv7PUNPwMuyxkN9y3CUVdj3NAS0w8dqrUf4a2T8Dei7vc8yFZIth3IKJx7VDNOgVhY_2lOdHHzvLXmkfYG8yW1D0dDnxRlr5YK46PUeBNhy3Y4MlFkOP2Uf62OoFMwpe8tKIs/s640/P1200449.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Red sun, still high above the horizon (~1h before sunset).</td></tr>
</tbody></table>
Anonymoushttp://www.blogger.com/profile/12050625263370191802noreply@blogger.com0tag:blogger.com,1999:blog-7165329846281791578.post-8436448427814642462013-06-09T19:00:00.000+08:002013-06-15T18:21:04.850+08:00Parse XML from shell scriptsAs part of the <a href="https://github.com/dnschneid/crouton" target="_blank">crouton</a>/<a href="https://github.com/drinkcat/chroagh" target="_blank">chroagh</a> project, I wanted to be able parse D-bus configuration file, to figure out what user account the system D-bus runs under.<br />
<br />
The configuration file looks like this:<br />
<div class="code">
# /etc/dbus-1/system.conf<br />
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"<br />
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"><br />
<busconfig><br />
<br />
<!-- Our well-known bus type, do not change this --><br />
<type>system</type><br />
<br />
<!-- Run as special user --><br />
<user>dbus</user><br />
<br />
<!-- Fork into daemon mode --><br />
<fork/><br />
<div>
.....</div>
<div>
</busconfig></div>
<div>
<br /></div>
</div>
<div>
Yes, that's XML. And normally, XML and shell scripts are not exactly good friends...<br />
<br />
What we want to be able to do here is to fetch the content of the <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">user</span> tag.<br />
<h4>
Solution 1 - sed</h4>
</div>
<div>
Well, that's without doubt the easiest:</div>
<div class="code">
sed -n 's|.*<user>\(.*\)</user>|\1|p' /etc/dbus-1/system.conf</div>
Problem is that the is no guarantee that there would be no other user tag<sup>[1]</sup>, in other parts of the file, and, who knows, the tag might be commented out. We also do not handle "misplaced" newlines in the file...<br />
<br />
<sup>[1]</sup> Actually, there is no other user tag, according to the dtd file, but not necessarily in a general case... And well, this post is boring if I stop here, right?<br />
<div style="orphans: auto; text-align: start; text-indent: 0px; widows: auto;">
<h4>
Solution 2a - xmllint</h4>
<div>
A more proper and generic solution, making use of the xmllint parser:</div>
<div class="code">
echo "cat /busconfig/user/text()" | xmllint --shell /etc/dbus-1/system.conf</div>
</div>
<div>
Problem is, xmllint is not really script-friendly, and outputs some garbage along with the desired output.</div>
<div class="code">
$ echo "cat /busconfig/user/text()" | xmllint --shell /etc/dbus-1/system.conf<br />
/ > cat /busconfig/user/text()<br />
-------<br />
dbus<br />
/ > $</div>
<div>
In my case, I know how a valid username looks like, so I just pipe the output through <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">grep '^[a-z][-a-z0-9_]*$'</span>, and that's the solution that is used in my code. Also, xmllint is installed by default on Chrome OS, so that's good enough for me.<br />
<h4>
Solution 2b - xmllint and write</h4>
<div>
An improved version would be:</div>
<div>
<div class="code">
echo "cd //busconfig/user/text()<br />
write tmp" | xmllint --shell /etc/dbus-1/system.conf<br />
cat tmp</div>
This is cleaner, as the full text of the tag is written to a file, but this requires an intermediate file, so, maybe not that nice...<br />
<h4>
Solution 2c - xmllint, write, and fd/3</h4>
Maybe an even nicer one, assuming <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">/dev/fd</span> exists (as it does on recent Linux distributions):<br />
<div class="code">
exec 3>/dev/null<br />
echo "cd //busconfig/user/text()<br />
write /dev/fd/3" | xmllint --shell /etc/dbus-1/system.conf 3>&1 1>/dev/null 2>/dev/null<br />
exec 3<&-</div>
<div>
No temporary file!<br />
<h4>
Solution 3 - xsltproc</h4>
</div>
</div>
</div>
<div>
Finally, the most powerful version, using XSLT:</div>
<div class="code">
xsltproc - /etc/dbus-1/system.conf <<END<br />
<?xml version="1.0" encoding="utf-8"?><br />
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><br />
<xsl:output method="text" encoding="utf-8" /><br />
<xsl:template match="/"><xsl:value-of select="/busconfig/user"/></xsl:template><br />
</xsl:stylesheet><br />
END</div>
<div>
That's as good as it gets, and you could easily do much more complicated things with XSLT. But, that's a bit overkill for our purpose (and <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">xsltproc</span> is not installed in Chrome OS).</div>
Anonymoushttp://www.blogger.com/profile/12050625263370191802noreply@blogger.com0tag:blogger.com,1999:blog-7165329846281791578.post-27842463560462243992013-06-02T19:00:00.000+08:002013-06-03T10:52:31.307+08:00ChromebookSince the adventure during my last trip, where <a href="http://drinkcat.blogspot.com/2013/05/archlinux-swapping-hard-drives-between.html" target="_blank">my (work/home/main) laptop suddenly died</a>, I realized that carrying a heavy and expensive laptop is not the best idea while travelling (in terms of risk of theft, damage, but also weight to carry around).<br />
<br />
A tablet would be an option, but they do not offer the flexibility I want (keyboard, photo editing, etc.), and they are generally not easy to hack. <a href="http://en.wikipedia.org/wiki/Netbook" target="_blank">Netbooks</a> seems to be a thing of the past, so I went for a <a href="http://www.google.com/intl/en/chrome/devices/" target="_blank">Chromebook</a>.<br />
<br />
I went for the second cheapest (<a href="http://www.google.com/intl/en/chrome/devices/samsung-chromebook.html#ss-cb" target="_blank">Samsung ARM Chromebook</a>, USD 249), the cheapest being a bit too heavy and bulky (<a href="http://www.google.com/intl/en/chrome/devices/acer-c7-chromebook.html#ac-c7" target="_blank">Acer C7</a>, USD 199), and maybe less exciting with a standard x86 processor.<br />
<br />
It is unfortunately not available in Singapore (at least not through usual channels), and some websites, such as Amazon, do not want to ship it to Singapore. Fortunately for me, <a href="http://www.bhphotovideo.com/" target="_blank">B&H Photo Video</a> does not care, and shipped it to me for USD 52. Three days later, I received my new toy, with no GST to pay (total amount below SGD 400, see <a href="http://www.customs.gov.sg/leftNav/trad/cle/Internet+PurchasesPostal+Parcels.htm" target="_blank">here</a>).<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisbpjoOiCnGpqyry3D6EK3ufoQE1BtcP94yxTzAZPMFAgciFMq4oQLEsEtOwF6l_t65vDRKC6X9fEgzWIoq5u7jJ2PcUcjxNcFzzhHi8fBqAFI8VF6pCQ3ZSKzoLiNezT98ZXWSwDdpAA/s1600/P1190436.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisbpjoOiCnGpqyry3D6EK3ufoQE1BtcP94yxTzAZPMFAgciFMq4oQLEsEtOwF6l_t65vDRKC6X9fEgzWIoq5u7jJ2PcUcjxNcFzzhHi8fBqAFI8VF6pCQ3ZSKzoLiNezT98ZXWSwDdpAA/s400/P1190436.JPG" width="300" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Samsung ARM Chromebook (running <a href="http://archlinuxarm.org/" target="_blank">Archlinux</a>/XFCE using <a href="https://github.com/drinkcat/chroagh" target="_blank">chroagh</a>, but more on that later).</td></tr>
</tbody></table>
Well, I won't repeat what other reviews say online (there are plenty), but, basically:<br />
<ul>
<li>First, you pay what you get for. Don't expect it to behave like a laptop with a price tag 10 times higher (a friend said: "<span data-ft="{"tn":"K"}" id=".reactRoot[1].[1][4][1]{comment10152807994830327_19969103}.0.[1].0.[1].0.[0].[0][2]">Fake Macbook!! Oh no, Korean!!</span>", and, well, that's not completely inaccurate): The body is plastic, and this is not a powerhouse. But still, for the price, I find it awesome.</li>
<li>Very light (1.1kg) and thin (1.8cm).</li>
<li>No fan, no moving parts: No noise at all, little heat, and long battery life (~6h).</li>
<li>Dual-core ARM processor (1.7Ghz): This is a bit better than your last generation cell phone (well, it does out-of-order execution so it's probably a step faster), but it seems to do the job fairly well.</li>
<li>Chrome OS:</li>
<ul>
<li>Very good browsing experience, very fast. Youtube works well in general, but tends to lag when you do other things at the same time: not ideal if you have your music playlist on Youtube.</li>
<li>You need connectivity for most stuff. There are a few offline apps (I haven't tried many), but most things will require a Wifi connection.</li>
</ul>
<li>Movie playback (from files, non-Youtube) is a problem: It could not read some x264-encoded files, even in SD quality. I mean, it could, but only displayed one frame per second or so... Maybe this could be improved in later versions of Chrome OS by optimizing the video decoder (e.g. use whatever hardware acceleration facilities the processor has).</li>
<li>Finally, and this is critical for me: hackability. This is not an Apple device or a locked Android phone. Google lets you do whatever you want with your computer, including wiping Chrome OS to install something else, or installing another Linux in parallel (<a href="https://github.com/dnschneid/crouton" target="_blank">crouton</a>/<a href="https://github.com/drinkcat/chroagh" target="_blank">chroagh</a>).</li>
</ul>
<div>
In short, mildly recommended for the normal user, Chrome OS is great, but really needs a working connection to be used to its full potential. And this is not always the case while travelling.</div>
<div>
<br /></div>
<div>
Strongly recommended for the more advanced user, as you can install a regular Linux in parallel: either as Dual-boot, or as a chroot inside Chrome OS, where you can switch between Chrome OS and your Linux with a simple key combination. I used the wonderful <a href="https://github.com/dnschneid/crouton" target="_blank">crouton</a> to install Ubuntu, and ported it to support Archlinux (<a href="https://github.com/drinkcat/chroagh" target="_blank">chroagh</a>). More on that for a later post.</div>
Anonymoushttp://www.blogger.com/profile/12050625263370191802noreply@blogger.com0tag:blogger.com,1999:blog-7165329846281791578.post-58762784932698164452013-05-26T19:00:00.000+08:002013-06-03T10:49:14.538+08:00Archlinux - Swapping hard drives between computersMy good old Dell Lattitude E6400 didn't survive my last week-end trip to Vietnam...<br />
<br />
For no apparent reason, the power button stays on for a few seconds, then switches off. The num lock light blinks, indicating a processor error... Luckily, I bought a 4th year of warranty, which would expire in 2 months time. Called up Dell on Tuesday, they came on Thursday (next business day), swapped the logic board, and it works again!<br />
<br />
In the mean time, I found a Lenovo Thinkpad T410 at the office, which is roughly as old as my Dell (and the keyboard is covered by something that looks like mould, but that's another story). I could use the Windows installation on that computer, but I suffer from a strong allergy to Windows, so I decided to do something slightly smarter instead of risking mental breakdown.<br />
<br />
Both the E6400 and the T410 are good professional laptops, and the hard drives can be taken out in less than 5 minutes - read: those are not Macs where you need to dismantle the whole computer to swap a component, only 5 screws need to be removed on each computer (1 to take out the hard drive assembly, and 4 to remove the drive itself).<br />
<br />
Anyway, took out the T410 hard drive, replaced it with my drive from the E6400, booted the T410, and immediately got my Archlinux running, with X server, network, and everything. The fact that both computers have similar hardware, and both use a nVidia graphics card, made the task slightly easier (no extra driver to install or xorg.conf to reconfigure), and the new screen resolution was automatically detected (the T410 features a pathetic 1280x800, vs a slightly better 1440x900 for the E6400).<br />
<br />
Now, just for a minute, imagine how complicated it would have been to do the same with a Windows system (re-installation? problems with key activation?).<br />
<br />
Anyway, that got me thinking that I should carry such a big laptop on holidays, so I ordered a <a href="http://www.samsung.com/us/computer/chromebook" target="_blank">Samsung Chromebook</a>, with the idea of install Archlinux on it. And I will soon need a new laptop to replace my E6400...
<br />
<br />
Just one picture of my trip to Ho Chi Minh City:<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaM9d3uJ3xMNkdJBy-ppdjWIN5IRG1KgWiDmKIAOBHIfoqr84jVagH5Uqg7HbrvfUyz5-kqMzuWULqAco4dw6HIYGukibyDULSO4tJGSRrEd8TlWgp7rhtAlntl0OFCJ3LTQy0DtdZszo/s1600/P1190243.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaM9d3uJ3xMNkdJBy-ppdjWIN5IRG1KgWiDmKIAOBHIfoqr84jVagH5Uqg7HbrvfUyz5-kqMzuWULqAco4dw6HIYGukibyDULSO4tJGSRrEd8TlWgp7rhtAlntl0OFCJ3LTQy0DtdZszo/s400/P1190243.JPG" width="300" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Somewhere in Saigon: Doll waiting to cross the road. Or celebrating <a href="http://en.wikipedia.org/wiki/Reunification_Day" target="_blank">Reunification day</a>, not sure...</td></tr>
</tbody></table>
Anonymoushttp://www.blogger.com/profile/12050625263370191802noreply@blogger.com1tag:blogger.com,1999:blog-7165329846281791578.post-1137745977698533692013-04-24T19:00:00.000+08:002013-06-03T10:49:03.077+08:00Thunderstorm - Video<div style="text-align: center;">
<i>The previous post shows you <a href="http://drinkcat.blogspot.com/2013/04/tropical-storm-composite-shot.html" target="_blank">pictures of a thunderstorm</a>, and how to create a composite from the images. This one shows you how to make a video from the images.</i></div>
<br />
Two week-ends ago, a fairly strong thunderstorm struck, with clear views from my window. I mounted my camera on a tripod, and I took close to 1000 shots in about 45 minutes, each with 2 seconds exposure.<br />
<br />
The previous post shows you some <a href="http://drinkcat.blogspot.com/2013/04/tropical-storm-composite-shot.html" target="_blank">sample pictures, as well as a composite of many lightnings</a>.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhR6CG3eVfo0YVTWPLd6xy2cPHaptMYSVgPrTYlgQe3WlbRHo4w2EmMf_cxRR7qvINPATEcueihpUFCS_xSppY0Xz58aO0YvRvCbWSjDGTfqQQ4PGp2ilbei3X92YwSBfZZDE1Vzqsd_c/s1600/compose-fromdiff.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhR6CG3eVfo0YVTWPLd6xy2cPHaptMYSVgPrTYlgQe3WlbRHo4w2EmMf_cxRR7qvINPATEcueihpUFCS_xSppY0Xz58aO0YvRvCbWSjDGTfqQQ4PGp2ilbei3X92YwSBfZZDE1Vzqsd_c/s400/compose-fromdiff.jpg" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><a href="http://drinkcat.blogspot.com/2013/04/tropical-storm-composite-shot.html" target="_blank">Composite shot</a>, see previous article.</td></tr>
</tbody></table>
This post will show you how to make a video from these images. Just playing those images at normal video speed (25 frames per second) will not work: because of the 2 seconds exposure I use, lightnings only appear on 1 images, at most 2. Played at 25 fps, each lightning would only appear for 1/25s: barely noticeable.<br />
<br />
The idea is therefore to create some <a href="http://en.wikipedia.org/wiki/Afterimage" target="_blank">burn-in effect</a>, where the bright lightning stay for a number of frames, slowing fading away. The resulting video is below (go to <a href="http://vimeo.com/64485466">Vimeo</a> for higher resolution):<br />
<br />
<div style="text-align: center;">
<iframe allowfullscreen="" frameborder="0" height="281" mozallowfullscreen="" src="http://player.vimeo.com/video/64485466" webkitallowfullscreen="" width="500"></iframe>.</div>
<h3>
Technique</h3>
The first step to create a video is to resize the images to HD format, that is 1080p (1920x1080):<br />
<div class="code">
mkdir sm1080<br />
ls *.JPG | xargs -I{} convert -crop 4380x2464+143+67 -resize 1920x1080 -quality 95 {} sm1080/{}</div>
I also do a bit of cropping, as my original framing shows some of the wall next to the window.<br />
<br />
We then add the required "burn-in" effect, so that bright light will appear quickly, and slowly fade away. I tried several methods to create this effect, but this very simple method seems to work best:<br />
<ol>
<li>Get the maximum between the last output frame and the current frame.</li>
<li>Blend this maximum image with the current frame (93% maximum, 7% current): this is your next output frame.</li>
<li>Iterate on the next input frame.</li>
</ol>
The idea is that a bright lightning will appear immediately, through the maximum operator: if the frame is bright, at step 2, the current frame is the same as the maximum frame, therefore you get 100% of the current frame. For following images, the current frame is less bright, so the brightness decays at a 93% rate. That is, the lightning will disappear almost completely within 29 frames (slightly more than a second). See Wikipedia on <a href="http://en.wikipedia.org/wiki/Exponential_decay" target="_blank">exponential decay</a> for more details.<br />
<br />
I tried different parameters, 90% made lightnings appear for a too short duration, and 95% led to significant artifacts: 93% seems to be a sweet spot.<br />
<br />
This simple Ruby script, that calls ImageMagick, does the job for you:<br />
<div class="code">
#!/usr/bin/ruby<br />
<br />
list = Dir.new(".").to_a.select{|x| x.match(/.*\.JPG/)}.sort<br />
<br />
system("mkdir output")<br />
system("rm output/*")<br />
system("cp #{list[0]} output/#{list[0]}")<br />
list.each_cons(2){|k1, k2|<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>system("convert output/#{k1} #{k2} -evaluate-sequence max output/max-#{k2}.tiff")<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>system("composite output/max-#{k2}.tiff #{k2} -blend 93% output/#{k2}")<br />
}</div>
I output the maximum images as TIFF, as to avoid additional JPEG compression artifacts.<br />
<br />
It is easy to check out the resulting video with mplayer:<br />
<div class="code">
mplayer mf://sm1080/output/*.JPG -mf fps=25:type=jpg</div>
Once you are happy with the results, you can then encode the output (I chose highest quality x264 encoding):<br />
<div class="code">
mencoder mf://sm1080/output/*.JPG -mf fps=25:type=jpg -ovc x264 -x264encopts preset=veryslow:tune=film:crf=15:frameref=15:fast_pskip=0:threads=auto -o video.avi
</div>
The video can be seen in 720p on <a href="http://vimeo.com/64485466">Vimeo</a>, and in 1080p on <a href="http://www.youtube.com/watch?v=pQOGZcWx1EU" target="_blank">Youtube</a> (unfortunately, Youtube does not let me choose a good thumbnail image, so I switched to Vimeo for this reason).Anonymoushttp://www.blogger.com/profile/12050625263370191802noreply@blogger.com0tag:blogger.com,1999:blog-7165329846281791578.post-47364178085443487662013-04-21T17:00:00.000+08:002013-06-03T10:49:03.078+08:00Thunderstorm - Composite shotOne of the nice (and sometimes a little scary) things about living under the tropics is those very intense thunderstorms, especially at night.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUUucQNAThA89EA9J9DztyhIiB5d-BaR0ABS-cou-kaK_lkABLMWXs4cadmP-nhazKI2BWOFbxeWFSdzSMDLDyI2aqvJgB4UEUej54lpUo7Igd7XfrYnHXWx84JQGi4Qrs77w9RQ7ie8o/s1600/compose-fromdiff.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUUucQNAThA89EA9J9DztyhIiB5d-BaR0ABS-cou-kaK_lkABLMWXs4cadmP-nhazKI2BWOFbxeWFSdzSMDLDyI2aqvJgB4UEUej54lpUo7Igd7XfrYnHXWx84JQGi4Qrs77w9RQ7ie8o/s640/compose-fromdiff.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Composite of an evening thunderstorm.</td></tr>
</tbody></table>
Last weekend a big one struck, so I mounted my camera (Panasonic DMC-GX1) on the window ledge, using my Gorillapod, and set the kit lens 14-42mm at its widest angle. Luckily, the rain was quite localized, so it wasn't raining much outside my window: no worries about getting my camera wet!<br />
<br />
I use the camera in burst mode, more precisely the "H" mode, that allows maximum speed while keeping the maximum resolution. I keep the trigger pressed using my <a href="http://drinkcat.blogspot.sg/2012/12/simple-remote-trigger-for-panasonic.html" target="_blank">home-made remote trigger</a>. All these shots are taken at f/5.0, with 2 seconds exposure, at ISO 160, slightly underexposed when there is no lightning, but sometimes overexposed for the brightest ones. Only mistake: I should have fixed the white balance, some of the shots clearly use different balances.<br />
<br />
The interval between shots is short, around 400ms, meaning that we expose almost all the time, and therefore are able to capture most lightnings. Actually, some lightnings last for a fairly long time, and can be seen over 2 consecutive shots.<br />
<br />
In total, I have close to 1000 shots, acquired over 45 minutes. Here are some of the best ones:<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdPjMhJEDiqOsIiolPG23EQCm64BQWXP3lWhyAOZNdnVtIYOh_AZZ7IaSZ_RdbJbjTwL3FCKPauk7zpiJ85KcVn9G5q_YuXq3xPua8qTNrDSjj1dpcl8j0f901zqZWaGH6e6RBPL1hSfg/s1600/P1180227.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdPjMhJEDiqOsIiolPG23EQCm64BQWXP3lWhyAOZNdnVtIYOh_AZZ7IaSZ_RdbJbjTwL3FCKPauk7zpiJ85KcVn9G5q_YuXq3xPua8qTNrDSjj1dpcl8j0f901zqZWaGH6e6RBPL1hSfg/s640/P1180227.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">2 lightnings next to each other</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCNRt4_t7OrC9zEUtIjaSmS77fzxJfPA95DCIg6vnnRGk-uXHE-kDhyphenhyphen5ifi6KR0BUnm6qinr2MWBTxkcZpFXYVTugUrMSxpDJL3WANbKe6iowpvm06Kz4ccsBt5D6Gg19KX8d3gPc1twg/s1600/P1180375.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCNRt4_t7OrC9zEUtIjaSmS77fzxJfPA95DCIg6vnnRGk-uXHE-kDhyphenhyphen5ifi6KR0BUnm6qinr2MWBTxkcZpFXYVTugUrMSxpDJL3WANbKe6iowpvm06Kz4ccsBt5D6Gg19KX8d3gPc1twg/s640/P1180375.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Intra-cloud lightnings, those are attenuated, probably because the light has to go though clouds and rain.</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJQYNaIYXx50b1g6iqsrAj-cWOATHtxj9VXet42XN5Leo7huo-rSldsHx4Iij77-i1ScJza5e7LpHiRdCTV99HdQ58CSz5j04qWyrezzOf6IkmFozbcTGR0a8KP2OY9VchLTLCqFs3xdg/s1600/P1180419.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJQYNaIYXx50b1g6iqsrAj-cWOATHtxj9VXet42XN5Leo7huo-rSldsHx4Iij77-i1ScJza5e7LpHiRdCTV99HdQ58CSz5j04qWyrezzOf6IkmFozbcTGR0a8KP2OY9VchLTLCqFs3xdg/s640/P1180419.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">A bit overexposed, but notice how the sky becomes blue, at night.</td></tr>
</tbody></table>
<br />
The 13 nicest images of the series can be seen in this <a href="https://picasaweb.google.com/107363214762755220776/SingaporeStormApril132013?authuser=0&authkey=Gv1sRgCKfM9Yfai4OKOw&feat=directlink" target="_blank">Picasa album</a>:<br />
<br />
<div style="text-align: center;">
<embed flashvars="host=picasaweb.google.com&captions=1&hl=en_US&feat=flashalbum&RGB=0x000000&feed=https%3A%2F%2Fpicasaweb.google.com%2Fdata%2Ffeed%2Fapi%2Fuser%2F107363214762755220776%2Falbumid%2F5868844158674381985%3Falt%3Drss%26kind%3Dphoto%26authkey%3DGv1sRgCKfM9Yfai4OKOw%26hl%3Den_US" height="400" pluginspage="http://www.macromedia.com/go/getflashplayer" src="https://picasaweb.google.com/s/c/bin/slideshow.swf" type="application/x-shockwave-flash" width="600"></embed><br /></div>
<br />
I am going to do 2 things with those images: a composite image of all the lightnings, and a video, that I will show in the next post.<br />
<h3>
Composite</h3>
I tried a few different ways to get a nice composite, here is what I think works best:<br />
<ol>
<li>Select the nicest images, that have a clear lightning in it.</li>
<li>For each of these, take a difference image to the previous one in the series. That is, we want to remove all the background light (man-made light and other background lighting), and only take out the extra light created by the lightning. An image explains it best:
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqewd3os91aUvNrNkWZ85mJzzW3PSsCF2ctoZmvzi3QYQm_dOkiFBbXdMVP1PiVpQoHD4NItA606CnFVBYnwy0oBsg_BUzOEL7yXTANNkd-GqkylqRUC9-XMjcB82d3FexY7068Gm79JA/s1600/montagediff-227.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqewd3os91aUvNrNkWZ85mJzzW3PSsCF2ctoZmvzi3QYQm_dOkiFBbXdMVP1PiVpQoHD4NItA606CnFVBYnwy0oBsg_BUzOEL7yXTANNkd-GqkylqRUC9-XMjcB82d3FexY7068Gm79JA/s640/montagediff-227.jpg" width="377" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">From top to bottom: 1. Number 226 in sequence, no lightning; 2. Number 227 in sequence, strong lightning; 3. Difference between 227 and 226: all man-made lights have disappeared.</td></tr>
</tbody></table>
Obtaining these difference images is straightforward with <a href="http://www.imagemagick.org/" target="_blank">ImageMagick</a>:<br />
<div class="code">
convert ../P1180226.JPG P1180227.JPG -evaluate-sequence subtract diff/P1180227.JPG</div>
</li>
<li>The composition itself is done is <a href="http://www.gimp.org/" target="_blank">Gimp</a>: First, open one of the original images in Gimp, that does not contain a lightning. Then, drag and drop all the differences images in the <i>Layers</i> window.</li>
<li>Hide all these new layers (i.e. until you are back to the original image).</li>
<li>Move one of the difference layer above your original image (start with the brightest lightnings), and show it.</li>
<li>Choose <i>Screen</i> as <a href="http://docs.gimp.org/en/gimp-concepts-layer-modes.html" target="_blank">layer mode</a>. <i>Lighten</i> may also work, but produces results that are not as nice in my opinion.</li>
<li>Go to <i>Colors</i>, then <i>Levels</i>, and increase the input black level until you only see mostly the lightning, without too much increase in the background light in the sky. You can also change the input white level if you want the lightning to appear brighter.</li>
<li>Repeat from step 5.</li>
</ol>
This shows you the progression of the composition, starting from the original image, step 0:<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiojqgowZj0dU0wXUHLqNSGZ1lvJHuB44AKs1fYJpZiw8wOt17t2C99igs8stY2G3wH8OgYeB3QpQJv3h7qTLXl1rFZXbrKx-qzVwmRYCmX-jzVAj0D5FQj-FmPfU5htxfLUEWwALm-iqg/s1600/montage-compose-fromdiff.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiojqgowZj0dU0wXUHLqNSGZ1lvJHuB44AKs1fYJpZiw8wOt17t2C99igs8stY2G3wH8OgYeB3QpQJv3h7qTLXl1rFZXbrKx-qzVwmRYCmX-jzVAj0D5FQj-FmPfU5htxfLUEWwALm-iqg/s640/montage-compose-fromdiff.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Montage of the progression of the composite image. One image is added at each step (2 images from 3 to 5).<br />
For step 1, the black level is not increased significantly, so as to get the blue sky on the right.</td></tr>
</tbody></table>
The image at step 12 is the one shown at the beginning of this post, after slight color adjustments.
<br />
<br />
<div style="text-align: center;">
<i>If you like my posts, you can now follow me on <a href="https://plus.google.com/114450893074168390185/posts" target="_blank">Google Plus</a>, <a href="https://twitter.com/drinkcatx" target="_blank">Twitter</a>, or via <a href="http://feeds.feedburner.com/drinkcat" target="_blank">RSS</a>, thanks!</i></div>
Anonymoushttp://www.blogger.com/profile/12050625263370191802noreply@blogger.com0tag:blogger.com,1999:blog-7165329846281791578.post-69094328010341780792013-04-09T19:00:00.000+08:002013-06-03T10:49:03.081+08:00Macro video - Correcting chromatic aberration, white balance, and soundtrack<div style="text-align: center;">
<i>This post is about taking macro videos, that is, videos of small objects, at relatively high magnification. In other posts, you can find a general introduction on taking <a href="http://drinkcat.blogspot.com/2013/03/macro-photography-cheap.html" target="_blank">macro pictures using a close-up filter</a>, and how to <a href="http://drinkcat.blogspot.com/2013/03/macro-photography-correcting-chromatic-aberration.html" target="_blank">correct chromatic aberration</a>.</i><br />
<i>The previous post shows how to <a href="http://drinkcat.blogspot.com/2013/04/macro-video.html" target="_blank">force the lens aperture on the DMC-GX1</a>, this post gives technical details to correct chromatic aberration, white balance, and improve the soundtrack.</i></div>
<br />
As mentioned in the <a href="http://drinkcat.blogspot.com/2013/04/macro-video.html" target="_blank">previous post</a>, the Panasonic DMC-GX1 is severely limited when it comes to video mode: it does not allow manual setting of the aperture and white balance.<br />
<br />
Once we managed to <a href="http://drinkcat.blogspot.com/2013/04/macro-video.html" target="_blank">trick the lens to force a slow aperture</a>, we get this this not-so-nice video, with chromatic aberration (red/blue fringes in the corner of the images), incorrect white balance (the music box looks too white), and noisy soundtrack:<br />
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen="" frameborder="0" height="315" src="http://www.youtube.com/embed/aan3prPY2W0" width="560"></iframe></div>
<br />
With a few operations, we'll show how to turn it into this nicer looking one:<br />
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen="" frameborder="0" height="315" src="http://www.youtube.com/embed/5IlDgwzRR94" width="560"></iframe></div>
<br />
<br />
<a name='more'></a>For this purpose, I'm going to use the following (free and open source) tools:<br />
<ul>
<li><a href="http://www.ffmpeg.org/" target="_blank">FFmpeg</a> and <a href="http://www.mplayerhq.hu/" target="_blank">mencoder</a> for video frame processing.</li>
<li><a href="http://hugin.sourceforge.net/" target="_blank">hugin</a>/<a href="http://wiki.panotools.org/Main_Page" target="_blank">panotools</a> for the <a href="http://wiki.panotools.org/Fulla" target="_blank">fulla</a> tool, to correct chromatic aberration.</li>
<li><a href="http://www.imagemagick.org/script/index.php" target="_blank">ImageMagick</a> to fix the white balance.</li>
<li><a href="http://audacity.sourceforge.net/" target="_blank">Audacity</a> for the audio processing</li>
<li><a href="http://www.kdenlive.org/" target="_blank">kdenlive</a> for general video editing (but any other tool would do).</li>
<li>Everything assumes you're running Linux, but it should be doable on Windows/Mac OS X with a bit of effort.</li>
</ul>
<h3>
Extract frames from the video</h3>
<div>
The DMC-GX1 creates a MP4 video file. However, the tools at our disposal for chromatic aberration and white balance correction work on images. Therefore, we need to extract each frame from the video, which is easily done with FFmpeg:<br />
<div class="code">
mkdir mjpeg<br />
ffmpeg -qscale 1 -i video.MP4 -f image2 -qscale 1 mjpeg/image-%05d.jpg</div>
This outputs 1 JPEG file for each frame of the video. The <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">qscale</span> parameters should create JPEG files of a slightly better quality than the default.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEho4KM50UvK06Czmr3wXNDuXVw1Ahz-RxGkijWaFA4jVQrB4-NE1_p2_5BUgFK5E9ugGap3rhuvo61BBDKY2WgWGcOYwTmJbfssiFloPAhzDbLTvHpwX7dro4apfeNWFocWbD1EXXu6fMY/s1600/image-00100.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEho4KM50UvK06Czmr3wXNDuXVw1Ahz-RxGkijWaFA4jVQrB4-NE1_p2_5BUgFK5E9ugGap3rhuvo61BBDKY2WgWGcOYwTmJbfssiFloPAhzDbLTvHpwX7dro4apfeNWFocWbD1EXXu6fMY/s640/image-00100.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Sample frame from the video (near the start, the wheel is not moving yet). Some chromatic aberration can be seen (especially on the teeth of the wheel at the top right), and the white balance is clearly off.</td></tr>
</tbody></table>
<h3>
Correct chromatic aberration</h3>
<div>
Now, let's fix the chromatic aberration (red and blue fringes in the corners of the images), that is caused by our <a href="http://drinkcat.blogspot.com/2013/03/macro-photography-cheap.html" target="_blank">cheap close-up filter</a>:<br />
<div class="code">
cd mjpeg<br />
ls *.jpg | xargs -I{} fulla -r -0.0046300:0.0177484:-0.0198170:0.9971389 -b 0.0007956:-0.0029477:0.0041624:1.0069115 -e 90 {}</div>
</div>
</div>
<div>
For more details on how to find the parameters, have a look at this post on <a href="http://drinkcat.blogspot.com/2013/03/macro-photography-correcting-chromatic-aberration.html" target="_blank">correcting chromatic aberration of still images</a>.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiq06yZ3RHD2ni_cJN-f5O0e6roLeM2qBGDinTTjZdmkK6umnrMFzRRsIvw14TK9TkkwQakZm_wCqrD3vn4d73CQ2nOtvJkM8-2GWCfQWwnRpD-7_CTYYFJMzYNPepkzE9d9COvnYRl23A/s1600/image-00100_corr.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiq06yZ3RHD2ni_cJN-f5O0e6roLeM2qBGDinTTjZdmkK6umnrMFzRRsIvw14TK9TkkwQakZm_wCqrD3vn4d73CQ2nOtvJkM8-2GWCfQWwnRpD-7_CTYYFJMzYNPepkzE9d9COvnYRl23A/s640/image-00100_corr.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Sample frame, corrected for chromatic aberration: the teeth of the wheel look sharper, and do not exhibit blue and red fringes.</td></tr>
</tbody></table>
</div>
<h3>
Correct white balance</h3>
<div>
White balance correction deserves an article on its own. I will probably write up something in the next few weeks. To make it short, we first take 2 pictures of the scene, one with a fairly correct balance ("Flash"), the other one with "Auto".<br />
<br />
The auto white balance is very bad in this situation, as the scene is mostly yellow. This makes the camera believe that the scene is yellow because of the lighting, so it corrects it to a grayish color.<br />
<br />
Looking at the EXIF of the good image (using exiftool, or any decent image editor), we see the following:</div>
<div class="code">
White Balance : Flash<br />
Red Balance : 3.034873<br />
Blue Balance : 1.451461
</div>
<div>
While the EXIF of the wrong image looks like this:</div>
<div class="code">
White Balance : Auto<br />
Red Balance : 2.34967<br />
Blue Balance : 1.896324</div>
<br />
These numbers tell you that the Auto balance puts less red (2.34967) than the flash balance (3.034873), and more blue (1.896324 vs 1.451461). Therefore, we need to boost the red channel (multiply by a factor 3.034873/2.34967 = 1.246), while reducing the blue channel (1.451461/1.896324 = 0.681)<br />
<br />
We can compute the corrected images using Imagemagick's convert <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">color-matrix</span> option. The following performs a batch operation on all the images:<br />
<div class="code">
mkdir ../mjpegcorr/<br />
ls *_corr.jpg | xargs -I{} convert {} -color-matrix \<br />
" 1.246 0.0 0.0 0.0, 0.0, 0.0 \<br />
0.0 1 0.0 0.0, 0.0, 0.0 \<br />
0.0 0.0 0.681 0.0, 0.0, 0.0 \<br />
0.0 0.0 0.0 0.0, 0.0, 0.0 \<br />
0.0 0.0 0.0 0.0, 0.0, 0.0 \<br />
0.0 0.0 0.0 0.0, 0.0, 0.0" \<br />
../mjpegcorr/{}
</div>
<div>
<br /></div>
<div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAKd5Namm8Zv1UI1NBrGnKBfvpBVjI5l7BlAnfDbGXb9SVeqgHuaxCu106fo55YOfDKMoIDrUbmn-wGH6V1XxpDKVZqBBRdWSURwngDUyo1UiYHL5Snf2h44Ji3Tq9JOwkaFpnxyCo1Sc/s1600/image-00100_corr_wb.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAKd5Namm8Zv1UI1NBrGnKBfvpBVjI5l7BlAnfDbGXb9SVeqgHuaxCu106fo55YOfDKMoIDrUbmn-wGH6V1XxpDKVZqBBRdWSURwngDUyo1UiYHL5Snf2h44Ji3Tq9JOwkaFpnxyCo1Sc/s640/image-00100_corr_wb.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Chromatic aberration and white balance corrected image.</td></tr>
</tbody></table>
I think the result's balance is still a little bit off, but it is already much more realistic than the original. A following article will focus on this, and see how and if we can correct it in a better way.</div>
<div>
<h3>
Rebuild the video from the frames</h3>
</div>
<div>
Now that we have a bunch of corrected JPEG files, we can recreate a MJPEG video file:<br />
<div class="code">
cd ../mjpegcorr<br />
mencoder mf://*_corr.jpg -mf fps=25:type=jpg -ovc copy -oac copy -o ../corr.avi</div>
</div>
<a href="http://en.wikipedia.org/wiki/Motion_JPEG" target="_blank">MJPEG</a> is a simple video file format, where each frame is a compressed JPEG file. We use the <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">-ovc copy</span> option, so that the frames are not recompressed.<br />
<div>
<div>
<h3>
Fix the audio</h3>
</div>
</div>
<div>
The audio contains quite a lot of background noise. I first extracted the audio from the original MP4 file using kdenlive, then processed it using audacity, using the "Noise Removal" effect, followed by amplification. The noise removal also removes some of the signal, but the result sounds much better.<br />
<br />
A better way would be to increase the signal, e.g. by fixing the music box on a resonance box, or by using a dedicated microphone, closer to the source (but... the DMC-GX1 does not have a mic input, so that doesn't really solve the problem...).</div>
<div>
<h3>
Merge the audio and video together</h3>
</div>
<div>
Finally, I use kdenlive to merge the audio and video, cut the video (remove the shaky beginning, and some of the end), recompress it to x264, and you get this nice video!<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen="" frameborder="0" height="315" src="http://www.youtube.com/embed/5IlDgwzRR94" width="560"></iframe></div>
<br /></div>
<div style="text-align: center;">
<i>There is a comment box below, feel free to ask questions, or make remarks!</i><br />
<i><br /></i>
<i>If you like my posts, you can now follow me on <a href="https://plus.google.com/114450893074168390185/posts" target="_blank">Google Plus</a>, <a href="https://twitter.com/drinkcatx" target="_blank">Twitter</a>, or via <a href="http://feeds.feedburner.com/drinkcat" target="_blank">RSS</a>, thanks!</i></div>
Anonymoushttp://www.blogger.com/profile/12050625263370191802noreply@blogger.com0tag:blogger.com,1999:blog-7165329846281791578.post-54319569358812681162013-04-04T19:00:00.000+08:002013-06-03T10:49:03.080+08:00Macro video<div style="text-align: center;">
<i>This post is about taking macro videos, that is, videos of small objects, at relatively high magnification. In other posts, you can find a general introduction on taking <a href="http://drinkcat.blogspot.com/2013/03/macro-photography-cheap.html" target="_blank">macro pictures using a close-up filter</a>, and how to <a href="http://drinkcat.blogspot.com/2013/03/macro-photography-correcting-chromatic-aberration.html" target="_blank">correct chromatic aberration</a>.</i><!---<br />
<i>The next post covers more details on correcting white balance and chromatic aberration on the video.</i>--></div>
<div style="text-align: center;">
<br /></div>
This post will show you how to take videos of small objects. I used my Reuge music box as an example, since it is small, and it moves (playing some nice music in the process, of course)... The final result is shown here:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen="" frameborder="0" height="315" src="http://www.youtube.com/embed/5IlDgwzRR94" width="560"></iframe></div>
<br />
My camera, the Panasonic DMC-GX1, is in the medium range of what Panasonic offers, which, unfortunately, means that there is no manual control of aperture or white balance in video mode. There is no technical reasons for that, only commercial ones, and, well, that's a shame: there is enough feature differentiation between the DMC-GH2/GH3 and the GX1 without adding artificial limitations.<br />
<a name='more'></a><br />
<br />
An alternative would be to use the <a href="http://www.gh1-hack.info/wiki/PToolSoftware" target="_blank">Ptool hacked firmware</a>. It allows the DMC-GF1 to use manual control in video mode. This patch is also compatible for the DMC-GX1, but, so far, only allows custom video bitrates on that camera.<br />
<br />
This post will show you how to circumvent these limitations. To get a nice macro video, we need 3 things:<br />
<ul>
<li>Force the lens aperture to its largest value (f/22), to get a decent depth of field. This also mean we need a lot of light on the scene. For this purpose, I put a tabletop lamp right on top of my music box (a few centimeters away).</li>
<li>Fix the white balance. The camera only allows auto white balance in video mode. In this case it does a particularly bad job at it, because the scene is mostly yellow, and turns everything into a grayish thing.</li>
<li><a href="http://drinkcat.blogspot.com/2013/03/macro-photography-correcting-chromatic-aberration.html" target="_blank">Correct chromatic aberration</a> introduced by the <a href="http://drinkcat.blogspot.com/2013/03/macro-photography-cheap.html" target="_blank">macro filter</a>.</li>
</ul>
<h3>
Forcing lens aperture</h3>
<div>
This part is a bit tricky, and, well, do it at your own risk. I did not break neither my camera nor my lens by doing it 5-6 times, but that's no guarantee it won't break your camera/lens: I don't take any responsibility... ,-)</div>
<div>
<br /></div>
<div>
By default, when it is not connected to a camera, any Micro 4/3 lens is at maximum aperture (lowest f/ number). Actually, even when connected to the camera, the lens is always at maximum aperture until you press the shutter button: this allows for easier manual focus, and gives more light for the live preview on the LCD.</div>
<div>
<br /></div>
<div>
This following picture shows my Panasonic 45-150mm, disconnected from the camera: clearly, the aperture is wide open (f/5.6 at 150mm).</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikyQ-RJ9jd3UYYdBrDlmhkJ9pQajsXgnhiQHYe048E_Pe4nHO1bUp2JH1IDyluwVSoCtQ2cs-tmCQeJ0sdMSOTypLbnWTUSxREFip48GBz3WvM0Uko0yjfBeG5WwiU7rf5Le8YQkd0Lac/s1600/P1170873.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikyQ-RJ9jd3UYYdBrDlmhkJ9pQajsXgnhiQHYe048E_Pe4nHO1bUp2JH1IDyluwVSoCtQ2cs-tmCQeJ0sdMSOTypLbnWTUSxREFip48GBz3WvM0Uko0yjfBeG5WwiU7rf5Le8YQkd0Lac/s400/P1170873.JPG" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Lens in it's "normal" state: aperture is wide open.</td></tr>
</tbody></table>
<div>
There is a trick to force the aperture to stay closed. What you need to do is the following (this idea comes from the always excellent <a href="http://m43photo.blogspot.sg/2012/02/reverser-ring-for-macro.html" target="_blank">Micro 4/3 Photography blog</a>):</div>
<div>
<ol>
<li>Put the camera in M mode, and set the aperture to the desired setting (here: f/22), with a long exposure (say 10 seconds).</li>
<li>Put the camera in manual focus, and set it to the desired distance (for macro shots: as close as possible).</li>
<li>Press the shutter.</li>
<li>While the camera is exposing, remove the lens. For some reasons, this will cause the shutter to close and open, but the aperture of the lens will stay at f/22, with the desired focus.</li>
</ol>
<div>
Look through your lens, it worked!</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1mZegwBZ_08cGjdUTNo520F7ITOQvBlCc2boPS6swkGA2DI4FdbfmWvZqh7HGAQSk1H9J5JbqbLjOKnHM3ghMwK630f_RnQV3s_q0-4HdnpcJzfaJdsbn2t9dDnrhyNxcMZ6gROrtDH0/s1600/P1170874.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1mZegwBZ_08cGjdUTNo520F7ITOQvBlCc2boPS6swkGA2DI4FdbfmWvZqh7HGAQSk1H9J5JbqbLjOKnHM3ghMwK630f_RnQV3s_q0-4HdnpcJzfaJdsbn2t9dDnrhyNxcMZ6gROrtDH0/s400/P1170874.JPG" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Lens with aperture closed.</td></tr>
</tbody></table>
<div>
Now, the fun bit. As soon as you mount the lens back on the camera, the aperture will reopen, and, well, you can start over... The trick here is to prevent the camera from communicating with the lens, by blocking the electrical connectors on the left of the picture above.<br />
<br />
I do this with masking tape. I first put a big piece of tape on a large part of the lens:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEix7LihLJEVwvLCGSc50jihsC7-ZSD_Pypg1grzkrAfMFIKZUd1LaCbZQPKbyCwJxLcLXClOu5Pu3GpRJleV_o1_6uFXY1mwOa7vEPRvmA6Uq2bx0u5i0xiZcp5B539vAhvRR9Rff3gHiY/s1600/P1170848.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEix7LihLJEVwvLCGSc50jihsC7-ZSD_Pypg1grzkrAfMFIKZUd1LaCbZQPKbyCwJxLcLXClOu5Pu3GpRJleV_o1_6uFXY1mwOa7vEPRvmA6Uq2bx0u5i0xiZcp5B539vAhvRR9Rff3gHiY/s400/P1170848.JPG" width="400" /></a></div>
<br />
And then carefully remove the excess tape:<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVnICd7YfwdZwRAXNo9H1R31WyE25ctRQa0vJk9empoBtbpdKksooa-ZYfVXTuMMtlhoumrh2JvpZHQGBxeqCykltKgbZOEPqZvFrka3E2jVlR7xyIU9KU8VgfSP3vMIPlqG_uzwz-HTA/s1600/P1170859.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVnICd7YfwdZwRAXNo9H1R31WyE25ctRQa0vJk9empoBtbpdKksooa-ZYfVXTuMMtlhoumrh2JvpZHQGBxeqCykltKgbZOEPqZvFrka3E2jVlR7xyIU9KU8VgfSP3vMIPlqG_uzwz-HTA/s400/P1170859.JPG" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">"Modified" lens: the Micro 4/3 electrical contacts are isolated.</td></tr>
</tbody></table>
Make sure the tape is not loose (the last thing you want is a piece of tape on your sensor). Also make sure that it covers all connectors: The camera and/or lens may not appreciate to have only part of the pins carrying voltage.<br />
<br />
Use a low-residue tape (like masking tape), so that you don't end up with dirty connectors on your lens and/or camera. Also, masking tape only leaves low residue if you peel it off quickly: once you're done with your video, remove the tape: don't leave it on for weeks, or you'll get so nasty glue left over...<br />
<br />
You now have a "legacy" lens, 150mm, f/22, with the focus set to its closest setting. Put it back on the camera. If the camera complains, you need to set the "Shoot without lens" option. The camera will of course not allow you to change aperture, nor will it tell you what is the aperture (or the focal length, or which lens is mounted: you get the idea). As with all native Micro 4/3 lens, the focus is "by-wire", so you will not be able to change that either. And you won't get image stabilization, since the lens gets no power.<br />
<br />
Put the <a href="http://drinkcat.blogspot.com/2013/03/macro-photography-cheap.html" target="_blank">close-up filter</a> on the lens, mount the camera on a tripod, and you are now ready to shoot your macro video!<br />
<br />
The following video is what I obtain, straight out of the camera. The white balance is obviously wrong, there is some chromatic aberration on the edges of the image, and the soundtrack needs some cleanup, but that's a start:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen="" frameborder="0" height="315" src="http://www.youtube.com/embed/aan3prPY2W0" width="560"></iframe></div>
<br />
The next post will go into the technical details of fixing the white balance, chromatic aberration, and background noise in the soundtrack.
<br />
<br />
<div style="text-align: center;">
<i>If you like my posts, follow me on Google Plus, Twitter, or via RSS, using the links on the top right of this page.</i></div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/12050625263370191802noreply@blogger.com0tag:blogger.com,1999:blog-7165329846281791578.post-32572794505937471272013-03-18T18:02:00.000+08:002013-04-09T20:07:50.423+08:00Macro photography on the cheap - Correcting chromatic aberration<i>In this series I show how you can use a cheap close-up filter to take macro pictures. The previous post is a <a href="http://drinkcat.blogspot.com/2013/03/macro-photography-cheap.html" target="_blank">general introduction</a>, and this post will show you how to fix</i><i> chromatic aberration introduced by the filter.</i><br />
<i><br /></i>
As shown in the previous post, the cheap 8x close-up filter introduces a lot of chromatic aberration (CA), especially at high magnification (45-150mm lens at maximum focal length). This is obvious when taking a picture of a black and white checkered pattern.<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8du3P-4DKwQeip7Y15v6i4cdFIHR0dIHzHavCf9RNuykgRZiQHl_3ao_NQSdC1ctBYe3dYBXHV2txXLLVpKsf1yzbxA2xuEW8WgH6EjHEzAl2hbY-PxvCsn-D4n_lkLoMDcO_vrujZUI/s1600/P1160594.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8du3P-4DKwQeip7Y15v6i4cdFIHR0dIHzHavCf9RNuykgRZiQHl_3ao_NQSdC1ctBYe3dYBXHV2txXLLVpKsf1yzbxA2xuEW8WgH6EjHEzAl2hbY-PxvCsn-D4n_lkLoMDcO_vrujZUI/s400/P1160594.JPG" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Checkered pattern (1mm square size), uncorrected.</td></tr>
</tbody></table>
Can we fix this? After all, the Micro 4/3 is known to <a href="http://m43photo.blogspot.sg/2011/02/chromatic-aberration-and-lens.html" target="_blank">fix lens distortion and CA in software</a>. The idea is that Panasonic could manufacture optically inferior lenses, with fewer elements, hence cheaper/lighter, and fix some of the image imperfection in software. Since there is no viewfinder, the user would never notice these corrections.<br />
<br />
Here, I'm pushing this to the limit: adding a very cheap close-up adapter, that introduces a lot of CA, and seeing how we can recover a decent-looking image.<br />
<a name='more'></a><br />
<br />
What you will need here:<br />
<ul>
<li><a href="http://hugin.sourceforge.net/" target="_blank">hugin</a>/<a href="http://wiki.panotools.org/Main_Page" target="_blank">panotools</a></li>
<li>Ruby</li>
<li><a href="http://www.sno.phy.queensu.ca/~phil/exiftool/" target="_blank">exiftool</a></li>
<li>All these commands are easier to run on Linux. There are ways of doing similar stuff on Windows (cygwin?) and MacOS X, but I won't go into that.</li>
</ul>
<h3>
Test pattern</h3>
I couldn't find a simple test pattern (read: a 2-minute Google search didn't output anything good), so I decided to create one, with checker pattern of 1mm, 0.5mm, 0.2mm, and various grid patterns.<br />
<br />
I use some Ruby code to generate a SVG file, that can then easily be converted to pdf. The <a href="https://github.com/drinkcat/macro/tree/master/calibration" target="_blank">source code to generate the pattern</a> is available on github, and you can download the <a href="https://docs.google.com/file/d/0B8Ddhk1wLvARUV9zbEx5TVhTYmc/edit?usp=sharing" target="_blank">calibration pattern pdf</a>.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiijcrdaBBF4YqN-jz2xvz9u4Y0DJl5ObSye96WjqU5EBU5dzHVra6JeEZP9PAJ9ndc3QG3MiFFoGecP6DqwHspozGeio30qZjPcAx9YC9UOQ4RKy0drkz0hKTtrT0wU4Gluc7Nq0BT2LU/s1600/calib.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiijcrdaBBF4YqN-jz2xvz9u4Y0DJl5ObSye96WjqU5EBU5dzHVra6JeEZP9PAJ9ndc3QG3MiFFoGecP6DqwHspozGeio30qZjPcAx9YC9UOQ4RKy0drkz0hKTtrT0wU4Gluc7Nq0BT2LU/s400/calib.png" width="282" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Calibration pattern. <a href="https://docs.google.com/file/d/0B8Ddhk1wLvARUV9zbEx5TVhTYmc/edit?usp=sharing" target="_blank">Download the PDF here</a>.<br />
My printer cannot render properly the 0.2mm checker pattern, nor the 0.1mm line width. For the rest, the quality seems quite good.</td></tr>
</tbody></table>
<h3>
Parameter detection</h3>
To detect the chromatic aberration parameters, we are going to use <a href="http://wiki.panotools.org/Tca_correct" target="_blank">tca_convert</a>, which is part of the <a href="http://hugin.sourceforge.net/" target="_blank">hugin</a>/<a href="http://wiki.panotools.org/Main_Page" target="_blank">panotools</a> package. Running this command on the picture shown above:<br />
<div class="code">
$ tca_correct -o abcv image.jpg</div>
outputs something like:<br />
<div class="code">
-r -0.0025220:0.0097571:-0.0102529:0.9939710 -b -0.0086956:0.0221789:-0.0163386:1.0116266</div>
That gives you radial distortion coefficient for the red and blue channels, which you can pass as parameters to <a href="http://wiki.panotools.org/Fulla" target="_blank">fulla</a>:<br />
<div class="code">
$ fulla -r -0.0025220:0.0097571:-0.0102529:0.9939710 -b -0.0086956:0.0221789:-0.0163386:1.0116266 image.jpg</div>
which creates a new file, image_corr.jpg:<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguqJOuGQgtMUBA5cDNByuMpKvM7FUbXZ5L75MtlyxBs2HWeecZfdvryMW4rYDL6tGeEItrHeEer7V5R4y_tivI_NBSB4tkET8BwSn67UeSapqX4nE7HNp4_9uZ4-Fi17dB5_betmu_NXo/s1600/P1160594_corr.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguqJOuGQgtMUBA5cDNByuMpKvM7FUbXZ5L75MtlyxBs2HWeecZfdvryMW4rYDL6tGeEItrHeEer7V5R4y_tivI_NBSB4tkET8BwSn67UeSapqX4nE7HNp4_9uZ4-Fi17dB5_betmu_NXo/s400/P1160594_corr.JPG" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Checkered pattern, corrected.</td></tr>
</tbody></table>
You can stop here if you think those parameters are correct. In my case, I decided to go a bit further, and averaged detected parameters over a number of pictures of the test patterns.<br />
<h4>
Averaging</h4>
<div>
Instead of relying a a single picture to compute parameters, I use a series of 12 different pictures of my test pattern. I compute the parameters for all the images in a batch:</div>
<div class="code">
$ ls *.JPG | xargs -I{} tca_correct -o abcv {} | tee params.log</div>
<div>
As you can see in the following <a href="http://en.wikipedia.org/wiki/Box_plot" target="_blank">box plot</a>, there is some variability in the parameters, and some clear outliers. For each of the parameters, I chose to use the median of the 12 estimates (the median is less sensitive to outliers than the mean).</div>
<div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqV6vv_HIJ-wv9lHxWhzoEzIDfad8sQ-b_obgQapAjc-r9bR0gwTlBZFyqvxwJ812ydj4Llc-aHEoSjDez1sv7IbsZN5cPcM-Sho6qfZeE7V4zACY4MnKQOKEG9ZbpT47QZTHdX6mVk60/s1600/params.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqV6vv_HIJ-wv9lHxWhzoEzIDfad8sQ-b_obgQapAjc-r9bR0gwTlBZFyqvxwJ812ydj4Llc-aHEoSjDez1sv7IbsZN5cPcM-Sho6qfZeE7V4zACY4MnKQOKEG9ZbpT47QZTHdX6mVk60/s400/params.png" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Box plot of the parameters a, b, c and v, for the red and blue channels.<br />
The box indicates 25% and 75% percentile, while the horizontal bar is the 50% percentile (i.e. the median).</td></tr>
</tbody></table>
<br /></div>
<div>
I then use a Ruby script to compute the median:</div>
<div class="code">
$ ruby parse.rb</div>
<div>
In my case, the final parameters are:</div>
<div class="code">
$ fulla -r -0.0046300:0.0177484:-0.0198170:0.9971389 -b 0.0007956:-0.0029477:0.0041624:1.0069115 image.jpg</div>
<div>
You can download the code on <a href="https://github.com/drinkcat/macro/tree/master/tca_correct" target="_blank">github</a> (as well as the R script to show the boxplot).</div>
<div>
<h3>
Batch correction of pictures</h3>
</div>
<div>
Finally, you can correct pictures in a batch, using a command such as:</div>
<div class="code">
$ ls *.JPG | xargs -I{} fulla -r -0.0046300:0.0177484:-0.0198170:0.9971389 -b 0.0007956:-0.0029477:0.0041624:1.0069115 {}</div>
<div>
Unfortunately, fulla does not keep EXIF information, but you can recover it with this one-liner, making use of <a href="http://www.sno.phy.queensu.ca/~phil/exiftool/" target="_blank">exiftool</a>:</div>
<div class="code">
$ ls *_corr.JPG | ruby -ne 'm = $_.match(/(.*)_corr(.*)/); system "exiftool -all= -tagsfromfile #{m[1]}#{m[2]} -exif:all #{m[0]}"'</div>
<div>
<div>
<h3>
Sample pictures</h3>
</div>
</div>
<div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEji_opbLFnzFepP1FIWivyOUbxFq1xdKoBapBzy3fEKlEonuHNNiQVHxQuZJj95QqI9X1oQSQntO-k4LEzKTx8zlvnv_1fTWY-vWbdMmzr72GdCXFpGhXigXZAxWOnICPuhipXHn9qQjqA/s1600/P1160799_corr_scale.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEji_opbLFnzFepP1FIWivyOUbxFq1xdKoBapBzy3fEKlEonuHNNiQVHxQuZJj95QqI9X1oQSQntO-k4LEzKTx8zlvnv_1fTWY-vWbdMmzr72GdCXFpGhXigXZAxWOnICPuhipXHn9qQjqA/s640/P1160799_corr_scale.JPG" width="480" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Baby gecko (that I accidentally frightened, which made it stay put long enough for me to take a few pictures; it then ran away)</td></tr>
</tbody></table>
You can find a set a sample pictures <a href="https://plus.google.com/photos/107363214762755220776/albums/5853271765687058609?authkey=CMX487TjuYy7TA" target="_blank">here</a>, or see the slideshow below. The pictures are taken at f/22, 150mm, ISO 160, and chromatic aberration corrected, unless otherwise noted.<br />
<embed flashvars="host=picasaweb.google.com&captions=1&noautoplay=1&hl=en_US&feat=flashalbum&RGB=0x000000&feed=https%3A%2F%2Fpicasaweb.google.com%2Fdata%2Ffeed%2Fapi%2Fuser%2F107363214762755220776%2Falbumid%2F5853271765687058609%3Falt%3Drss%26kind%3Dphoto%26authkey%3DGv1sRgCMX487TjuYy7TA%26hl%3Den_US" height="400" pluginspage="http://www.macromedia.com/go/getflashplayer" src="https://picasaweb.google.com/s/c/bin/slideshow.swf" type="application/x-shockwave-flash" width="600"></embed>
</div>
Anonymoushttp://www.blogger.com/profile/12050625263370191802noreply@blogger.com0tag:blogger.com,1999:blog-7165329846281791578.post-68950058030971896532013-03-12T19:00:00.000+08:002013-04-09T20:07:35.519+08:00Macro photography on the cheap<div dir="ltr" style="text-align: left;" trbidi="on">
<i>In this series I will show how you can use a cheap close-up filter to take macro pictures. This post is a general introduction, and the <a href="http://drinkcat.blogspot.com/2013/03/macro-photography-correcting-chromatic-aberration.html" target="_blank">next post will show you how to fix</a></i><i><a href="http://drinkcat.blogspot.com/2013/03/macro-photography-correcting-chromatic-aberration.html" target="_blank"> chromatic aberration</a> introduced by the filter.</i><br />
<br />
There are many ways of obtaining relatively large magnification with a camera. You can find out about many of these methods on the excellent <a href="http://m43photo.blogspot.com/" target="_blank">Micro 4/3rds Photography</a> blog: using a <a href="http://m43photo.blogspot.no/2010/07/panasonic-leica-lumix-dg-macro-elmarit.html" target="_blank">dedicated macro lens</a>, <a href="http://m43photo.blogspot.no/2010/03/macro-rings.html" target="_blank">extension rings</a>, a <a href="http://m43photo.blogspot.sg/2012/02/reverser-ring-for-macro.html" target="_blank">reverser ring</a>, or a <a _blank="" href="http://m43photo.blogspot.sg/2012/09/using-10-macro-lens.html%20target=">close-up filter</a>...<br />
<div>
<br /></div>
I'm not willing to spend more than 500$ for a dedicated macro lens, so I went the cheapest possible way: using a <a href="http://dx.com/p/premium-8x-macro-effect-camera-lens-filter-52mm-17323" target="_blank">8x close-up filter</a>, that you can find for 8$ on dealextreme, and maybe cheaper on eBay. I went for the 8x filter instead of the 10x, because the latter has bad reviews: the lens element protrudes at the back of the filter, and you risk scratching your lens when mounting the filter (Fredrik Gløckner talks about it in <a href="http://m43photo.blogspot.sg/2012/09/using-10-macro-lens.html" target="_blank">this post</a>); it also seems to be optically inferior.<br />
<a name='more'></a><br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdHYsThX4YOcCYt9ZmVxb2P8V26EYV-px2lf0_eqnAiOeeRx3qAI2NmGQL7YIt67mXRy8FwOCWZFHv_b42n8bw0ClOS-4ko6Kl_o8DWhaky7aYUkhWa5jQHgKkVeHV73rICIccxWOT_Ds/s1600/P1160771.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="256" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdHYsThX4YOcCYt9ZmVxb2P8V26EYV-px2lf0_eqnAiOeeRx3qAI2NmGQL7YIt67mXRy8FwOCWZFHv_b42n8bw0ClOS-4ko6Kl_o8DWhaky7aYUkhWa5jQHgKkVeHV73rICIccxWOT_Ds/s320/P1160771.JPG" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">8$ close-up filter.</td></tr>
</tbody></table>
I tried the filter with 2 lenses: Panasonic 14-42mm, and 45-150mm. Both use a 52mm thread, so I could reuse the same filter. In each case, I use the camera in manual focus, set the focus to minimum distance, to obtain as much magnification as possible, and take a picture of a ruler.<br />
<h4>
Magnification</h4>
The magnification is defined as the ratio between the sensor size and the object size. On a Micro 4/3, the sensor size is 17.3mm, so if you can image 17.3mm of a ruler, you have a 1:1 magnification. If you get 8.15mm, you have a 2:1 magnification, etc.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQrzmzP11Oqz7TU2X6Rj6FeRXhNNnK3cC7jU9ampdFuyAsLOKvVJV2D0HUxV8MRcHWTNSpz-colaSUGMZWOZ921YnE5YQORF8Kkrnl_onGEbnCIj2b7mALuKnzJlozRPQ4IoSup9Ld2Ng/s1600/P1160603.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="248" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQrzmzP11Oqz7TU2X6Rj6FeRXhNNnK3cC7jU9ampdFuyAsLOKvVJV2D0HUxV8MRcHWTNSpz-colaSUGMZWOZ921YnE5YQORF8Kkrnl_onGEbnCIj2b7mALuKnzJlozRPQ4IoSup9Ld2Ng/s400/P1160603.JPG" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Picture of a ruler. Here, you see about 15mm of the ruler, so the magnification is 17.3:15 = 1:0.87 or 1.15x.<br />
Note the chromatic aberrations on the side of the image, but more on that later... </td></tr>
</tbody></table>
The magnification you obtain with these combinations is listed in the table:<br />
<table border="1" cellpadding="5px" style="border-collapse: collapse; margin: auto;">
<tbody>
<tr>
<td align="center"><b>Lens</b></td>
<td align="center"><b>Magnification<br />with 8x filter</b></td>
<td align="center"><b>Magnification<br />without 8x filter</b></td>
</tr>
<tr><td>14-42mm@14mm</td><td>1:5</td><td>1:10.5</td></tr>
<tr><td>14-42mm@42mm</td><td>1:2.5</td><td>1:5.3</td></tr>
<tr><td>45-150mm@45mm</td><td>1:2.7</td><td>1:13.6</td></tr>
<tr><td>45-150mm@150mm</td><td>1:0.87 (1.15x)</td><td>1:5.7</td></tr>
</tbody></table>
<br />
Clearly, only the 45-150mm lens at the maximum focal length, with the 8x filter, can be considered a true "macro" configuration. The rest does not provide enough magnification:<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg28IO2qEMrXbuxxwBVmTlPFKLcZxvTKZUZ8xkoNVcKFyzt8FpW6dDdhZFDQdsHwAUIsFNR6d4JLBRLIrGvQECtmdZhBWm5sxLyxs-fgCPVtWsyl5OfnRFNrGIP0CXidvKodBlTkU1sBBo/s1600/montage.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="160" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg28IO2qEMrXbuxxwBVmTlPFKLcZxvTKZUZ8xkoNVcKFyzt8FpW6dDdhZFDQdsHwAUIsFNR6d4JLBRLIrGvQECtmdZhBWm5sxLyxs-fgCPVtWsyl5OfnRFNrGIP0CXidvKodBlTkU1sBBo/s640/montage.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Left to right: 45-150mm@150mm, 14-42mm@42mm, 14-42mm@14mm (always using the 8x filter)<br />
My <a href="http://www.reuge.com/home" target="_blank">Reuge</a>/Romance Swiss-made music box does not seem to enjoy a lot the hot and humid weather or Singapore, leading to quite a thick layer of oxide on the metal...</td></tr>
</tbody></table>
<br />
Interestingly, the 45-150mm, without filter, is a very bad lens for close-up works: the minimum focus distance is 0.9m, and leading to worse magnification than the 14-42mm. On the other hand, the 8x close-up filter has a huge effect on this lens. Why? No precise idea, but it has something to do with the lens design.<br />
<h4>
Sample pictures</h4>
<div>
These sample pictures are taken with the 45-150mm lens, at 150mm, using a very small aperture (f/22), to get as much depth of field as possible. Sure, you will lose quite a bit a resolution due to diffraction, but I think this still gives best results, and makes focusing a little easier.</div>
<div>
<br /></div>
<div>
Macro photography needs external lighting, even on a sunny day you will not get enough light on the sensor. For this purpose, I use an external flash (an old <a href="http://www.kenrockwell.com/nikon/sb22.htm" target="_blank">Nikon SB-22</a>), which I hold at a certain distance using a <a href="http://www.ebay.com/itm/271118376948?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649" target="_blank">TTL flash extension cord</a>. The flash is unfortunately not fully compatible with Panasonic cameras (no TTL mode), so it sometimes takes a few tries to get the correct amount of light on the scene.<br />
<br />
Here is one sample picture:</div>
<div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKCTbPim1AwOjyMb5dcatzf26mfTTx2JDpn2Pd5xyBgLeZX8ogQ5Xot-_LRt3vlq6JfO8yvpT6jZTyZBZl51kxvbdoy_OnvDbi6SKR1w58trZR6YsJynWwHO0Q3zH4-TKnNf9XSP8tyGY/s1600/P1160763.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKCTbPim1AwOjyMb5dcatzf26mfTTx2JDpn2Pd5xyBgLeZX8ogQ5Xot-_LRt3vlq6JfO8yvpT6jZTyZBZl51kxvbdoy_OnvDbi6SKR1w58trZR6YsJynWwHO0Q3zH4-TKnNf9XSP8tyGY/s640/P1160763.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Original image.</td></tr>
</tbody></table>
There is some obvious <a href="http://en.wikipedia.org/wiki/Chromatic_aberration" target="_blank">chromatic aberration</a> (red and blue fringes) on the sides of the image. I will explain the <a href="http://drinkcat.blogspot.com/2013/03/macro-photography-correcting-chromatic-aberration.html" target="_blank">method to correct chromatic aberration in the next post</a>.<br />
<br />
The effect of the correction is quite striking on a 100% crop:<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTqcWYf_NNDfBPdQQqn3WntyzPSf_WxdMdX5kmPypHEvIrQ-rzB-oSlTlKehcqq0vQuRgQbRzXgTj67PdWHEz1tqo1c9tg9UqmFzO5a5RmifeC1TAAZcdcCmfA_lx3eeuS2SSroD36hg8/s1600/montage-chroma.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="160" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTqcWYf_NNDfBPdQQqn3WntyzPSf_WxdMdX5kmPypHEvIrQ-rzB-oSlTlKehcqq0vQuRgQbRzXgTj67PdWHEz1tqo1c9tg9UqmFzO5a5RmifeC1TAAZcdcCmfA_lx3eeuS2SSroD36hg8/s320/montage-chroma.JPG" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Left: Original image.<br />
Right: Chromatic aberration corrected image.</td></tr>
</tbody></table>
Even after correction, the image still looks fairly blurry, possibly due to diffraction.</div>
<br />
Finally, the corrected image looks very decent, especially considering the cost of the close-up filter.<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEin17-9WuM_uo98tv8s0AA0WyxLzUokKg7J4zeMcHqhGwvEHqj2qY4TWdIgV7bo-N_YS0v2hXUlQ08-17ReaLjbuTA9dB0l8aUwUtNNoDherdOwPOqbkDA8lj6mKPM73tyUQMPD2J6yBT8/s1600/P1160763_corr.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEin17-9WuM_uo98tv8s0AA0WyxLzUokKg7J4zeMcHqhGwvEHqj2qY4TWdIgV7bo-N_YS0v2hXUlQ08-17ReaLjbuTA9dB0l8aUwUtNNoDherdOwPOqbkDA8lj6mKPM73tyUQMPD2J6yBT8/s640/P1160763_corr.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Corrected image.</td></tr>
</tbody></table>
<br />
You can find a set a sample pictures <a href="https://plus.google.com/photos/107363214762755220776/albums/5853271765687058609?authkey=CMX487TjuYy7TA" target="_blank">here</a>, or see the slideshow below. The pictures are taken at f/22, 150mm, ISO 160, and chromatic aberration corrected, unless otherwise noted.<br />
<br />
<embed flashvars="host=picasaweb.google.com&captions=1&noautoplay=1&hl=en_US&feat=flashalbum&RGB=0x000000&feed=https%3A%2F%2Fpicasaweb.google.com%2Fdata%2Ffeed%2Fapi%2Fuser%2F107363214762755220776%2Falbumid%2F5853271765687058609%3Falt%3Drss%26kind%3Dphoto%26authkey%3DGv1sRgCMX487TjuYy7TA%26hl%3Den_US" height="400" pluginspage="http://www.macromedia.com/go/getflashplayer" src="https://picasaweb.google.com/s/c/bin/slideshow.swf" type="application/x-shockwave-flash" width="600"></embed>
</div>
drinkcathttp://www.blogger.com/profile/08991363247732795423noreply@blogger.com0tag:blogger.com,1999:blog-7165329846281791578.post-3511622857948887032013-03-01T19:00:00.000+08:002013-03-01T19:00:01.589+08:00Random blog banner - Part 2<div dir="ltr" style="text-align: left;" trbidi="on">
Alright, the previous part shows you the script that allows to <a href="http://drinkcat.blogspot.com/2013/02/random-blog-banner-part-1.html">randomly display a banner image</a>. Now, this would quickly end up being a bit messy to manage, if you want to add a new banner, then update the page with the <a href="http://drinkcat.blogspot.com/p/panoramas.html" target="_blank">list of all panoramas</a>.<br />
<br />
I wrote a Ruby script to semi-automate the process. The source can be found on <a href="https://github.com/drinkcat/randombanner" target="_blank">github</a>.<br />
<br />
We first start with a database of images, called <a href="https://github.com/drinkcat/randombanner/blob/master/images.db" target="_blank"><span style="font-family: "Courier New",Courier,monospace;">images.db</span></a>. It is a <a href="http://en.wikipedia.org/wiki/YAML" target="_blank">YAML</a> file, with this format:<br />
<div class="code">
<span style="font-family: "Courier New",Courier,monospace;">- url: https://lh4.googleusercontent.com/.../s{}/xx.jpg<br /> width: 800<br /> repeat: true<br /> offset: -30<br /> text: Krabi - Thailand<br /> date: 2012.12</span></div>
I like to use YAML, because it is easy to parse in Ruby, without being as wordy as XML, but more structured than a simple text file.<br />
<br />
The fields are:<br />
<ul style="text-align: left;">
<li><span style="font-family: "Courier New",Courier,monospace;">url</span>: source image location<span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: inherit;">. <span style="font-family: "Courier New",Courier,monospace;">s{}</span> in the URL will be replaced by the proper image width</span></span></li>
<li><span style="font-family: "Courier New",Courier,monospace;">width</span>: width to display</li>
<li><span style="font-family: "Courier New",Courier,monospace;">repeat</span>: if the panorama is a full 360° that can be repeated</li>
<li><span style="font-family: "Courier New",Courier,monospace;">offset</span>: vertical offset to center the image</li>
<li><span style="font-family: "Courier New",Courier,monospace;">text</span>: Text that will appear in the banner, and in the image description</li>
<li><span style="font-family: "Courier New",Courier,monospace;">date</span>: year and month when the image was taken</li>
</ul>
Then, the script <a href="https://github.com/drinkcat/randombanner/blob/master/banner.rb" target="_blank"><span style="font-family: "Courier New",Courier,monospace;">banner.rb</span></a> read<span style="font-family: "Courier New",Courier,monospace;">s</span> <span style="font-family: "Courier New",Courier,monospace;">images.db</span>. It generates the Javascript arrays, and insert them in <a href="https://github.com/drinkcat/randombanner/blob/master/jscode.template" target="_blank"><span style="font-family: "Courier New",Courier,monospace;">jscode.template</span></a>, creating a new <a href="https://github.com/drinkcat/randombanner/blob/master/jscode.js" target="_blank"><span style="font-family: "Courier New",Courier,monospace;">jscode.js</span></a> file, that you can then copy-paste on the blog.<br />
<br />
It will also read <a href="https://github.com/drinkcat/randombanner/blob/master/pagecode.html.template" target="_blank"><span style="font-family: "Courier New",Courier,monospace;">pagecode.html.template</span></a>, and generate <a href="https://github.com/drinkcat/randombanner/blob/master/pagecode.html" target="_blank"><span style="font-family: "Courier New",Courier,monospace;">pagecode.html</span></a> for the list of images.<br />
<br />
That's it! Looking at the code should be somehow self-documenting, if you want to modify it. I release the code in public domain, do whatever you want with it!</div>
drinkcathttp://www.blogger.com/profile/08991363247732795423noreply@blogger.com0tag:blogger.com,1999:blog-7165329846281791578.post-82822798790190279472013-02-26T19:00:00.000+08:002013-02-26T21:37:21.491+08:00Random blog banner - Part 1<div dir="ltr" style="text-align: left;" trbidi="on">
You probably have noticed: the banner image of this blog changes every time you refresh the page. Those are stitched panorama from many pictures, sometimes spanning a full 360 degrees, sometimes less (I will write something about stitching these panoramas at some point...).<br />
<br />
The code to do randomize the banner image is easily available online, I took it from <a href="http://forum.cloudmedianews.com/forum-cms/random-header-and-background-images-for-blogspot-t586.html" target="_blank">this page</a>, but it is found in so many places that I'm not sure who wrote it first.<br />
<br />
My updated version follows: <br />
<div class="code">
<span style="font-family: "Courier New",Courier,monospace;"><script type="text/javascript"><br />var banner= new Array()<br />var shift= new Array()<br />var information= new Array()<br />banner[0]="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNXX68HJ-zGPBvn2ZPOIPfpV0tnIJ8yXM9yxoKh3FEW9ycY0883_oXfM2TNYOis319rf2H2YvI-hloChdei3v1o8yXiNaBqnvPRktWXBjooDsFqJKtpz0pxXASYPc98QMuzvnlKpArbJCL/s1600/101P.jpg"<br />shift[0]="no-repeat center -50px"<br />information[0]="Jiufen - Taiwan"</span><br />
<span style="font-family: "Courier New",Courier,monospace;">//...<br />var random=Math.floor(banner.length*Math.random());<br />var query = window.location.search.substring(1);<br />var match = query.match(/.*headerimage=([0-9]+).*/);<br />if (match) {<br />document.write("Manual image index:");<br />document.write(match[1]);<br />random = match[1];<br />}<br />document.write("<style>");<br />document.write(".body-fauxcolumn-outer .cap-top {");<br />document.write(' background: #FFFFFF url("' + banner[random] + '") ' + shift[random] + ';');<br />document.write(" }");<br />document.write("</style>");<br />document.getElementById('headerinformation').innerHTML = information[random];<br /></script></span>
</div>
Let's take it step by step. I define 3 arrays: <span style="font-family: "Courier New",Courier,monospace;">banner</span>, <span style="font-family: "Courier New",Courier,monospace;">shift</span>, and <span style="font-family: "Courier New",Courier,monospace;">information</span>, each index representing one image:<br />
<ul style="text-align: left;">
<li><span style="font-family: "Courier New",Courier,monospace;">banner</span> contains the URL of the image. I extract the public link from the Picasa Web Albums. This URL can be obtained by a right-click on the image, and then "View Image". The URL looks like this: <span style="font-family: "Courier New",Courier,monospace;">https://lh6.googleusercontent.com/.../s1600/X.jpg</span>. The number after the letter <span style="font-family: "Courier New",Courier,monospace;">s</span> is particularly interesting: it defines the width of the image. I you change it, Google will very nicely resize it to the size you want. Using <span style="font-family: "Courier New",Courier,monospace;">s0</span> gives you the original resolution.</li>
<li><span style="font-family: "Courier New",Courier,monospace;">shift</span> contains some extra CSS style information. For full 360° panoramas, the image can be repeated endlessly without seems, so the parameter <span style="font-family: "Courier New",Courier,monospace;">repeat</span> is used, otherwise, the panorama is shown only once. Also, you can set an offset, so that the image gets centered vertically, so you don't get only sky or only land/sea in the banner.</li>
<li><span style="font-family: "Courier New",Courier,monospace;">information</span> contains some short description about the image.</li>
</ul>
Then, I pick a random number in the list, unless the URL is something like <a href="http://drinkcat.blogspot.com/?headerimage=0">http://drinkcat.blogspot.com/?headerimage=0</a> : In that case I force displaying image 0. That's useful for debugging.<br />
<br />
Finally, the code generates a little piece of CSS style, that will set the banner image. Also, it modifies the HTML element with id <span style="font-family: "Courier New",Courier,monospace;">headerinformation</span>, so that it shows the image information. In my case, this element is at the bottom of the banner, aligned to the right, and tells you where the image was taken.<br />
<br />
All right. All for now, next post will show how to generate the script, as well as <a href="http://drinkcat.blogspot.com/p/panoramas.html" target="_blank">this page</a>, automatically.</div>
drinkcathttp://www.blogger.com/profile/08991363247732795423noreply@blogger.com0tag:blogger.com,1999:blog-7165329846281791578.post-9369549850870834232013-02-20T19:00:00.000+08:002013-02-20T19:36:30.496+08:00Triggering Panasonic Lumix from Arduino<div dir="ltr" style="text-align: left;" trbidi="on">
As mentioned in the post about <a href="http://drinkcat.blogspot.com/2012/12/simple-remote-trigger-for-panasonic.html">how to build a remote trigger</a>, we can also use an electronic device, such as an Arduino, to trigger the camera.<br />
<br />
There are several way of accomplishing this, a simple MOSFET may do the trick, but I decided to use a optocoupler. The optocoupler electrically separates the Arduino and camera circuitry: This decreases risks of damaging the camera because of incorrect wirings on the Arduino side.<br />
<h4 style="text-align: left;">
Camera detection circuit </h4>
If you remember from <a href="http://drinkcat.blogspot.com/2012/12/simple-remote-trigger-for-panasonic.html">this post</a>,
the triggering mechanism for Panasonic cameras is a little unusual: The
resistance across 2 pins defines the trigger status: around 41.1kOhm at
rest, 5.1kOhm to pre-focus the camera, 2.2kOhm to trigger a shot.<br />
<br />
Understanding a bit more of the detection circuit inside the camera is useful here. This can be done by measuring the voltage across the 2 pins in different combinations:<br />
<br />
<table border="1" cellpadding="5px" style="border-collapse: collapse; margin: auto;">
<tbody>
<tr>
<td align="center"><b>State</b></td>
<td align="center"><b>Measured resistance</b></td>
<td align="center"><b>Voltage measured</b></td>
</tr>
<tr>
<td>Open circuit</td>
<td align="right">(infinite)</td>
<td align="right">3.08V</td>
</tr>
<tr>
<td>Trigger present</td>
<td align="right">~41.4 kOhm</td>
<td align="right">2.49V</td>
</tr>
<tr>
<td>Focus</td>
<td align="right">~5.0 kOhm</td>
<td align="right">1.05V</td>
</tr>
<tr>
<td>Trigger</td>
<td align="right">~2.1 kOhm</td>
<td align="right">0.56V</td>
</tr>
</tbody></table>
<br />
We can make an educated guess on the detection circuit used by the camera, making use of a simple voltage divider, and reading out the voltage drop on the remote trigger.<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4ZV0OMNlSdU7VT7koNgf3LWxL28dPvM6QpDXczG1hAQ94ocCj2T3EcTrtL3IOtf9aQjs99Ia7tF-zdoFiWKvt6Xl7kW_Z9fYJ0jL7bBSZ8BCfipuZ_jq5uUUIvv1TAh2uOFiLbWA4dMTw/s1600/arduino-trigger.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4ZV0OMNlSdU7VT7koNgf3LWxL28dPvM6QpDXczG1hAQ94ocCj2T3EcTrtL3IOtf9aQjs99Ia7tF-zdoFiWKvt6Xl7kW_Z9fYJ0jL7bBSZ8BCfipuZ_jq5uUUIvv1TAh2uOFiLbWA4dMTw/s1600/arduino-trigger.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Possible detection circuit on the camera (the camera resistor may be
connected on the ground side, and may be more complicated to avoid the
need for an analog to digital converter)</td></tr>
</tbody></table>
Obtaining V<sub>camera</sub> is straightforward: it is the open circuit voltage. We can guess R<sub>camera</sub> entering resistances R<sub>trigger</sub> and V<sub>detect</sub> in the following equation:<br />
<div class="separator" id="equation" style="clear: both; text-align: center;">
<img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixM2ZkqyJ6rusJ2eQTlw1xsUWbkg0RprtNLA9-HDn5Ol8PcVwTGe9Ywe8iENeBb8v3vfZ19fY6x2gsKk0jzu_wk6lElTt4d4dcw24tue_A7zih6bZdEuSa7yk5N9sXoW-9RmjehiSQEmjo/s1600/res.png" /></div>
Moving terms around, we get:<br />
<div class="separator" id="equation" style="clear: both; text-align: center;">
<img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhL3DN1BUpdYYumEaLx9vp0cLm0Euh0Ax6bbAVGXLvpZQdk9vRXoPsZ75jQmET5tOIu6gKERPEQMCPUX48BKC9qy3Rpy7KHS5XQ8asTN1-sTmahEJjFQ-kAnhLCi7Vg3WqcRIJMpwaXl5YU/s1600/res2.png" /></div>
For the 3 values above, we get, respectively, R<sub>camera</sub> = 9.8, 9.7 and 9.45 kOhm. So we have a resistor around 9.5 kOhm on the camera side.<br />
<h4 style="text-align: left;">
Triggering circuit </h4>
<div style="text-align: left;">
Now comes the triggering circuit itself, as shown in the next figure.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_aWY6RO_KUwUPi_wMwIvm2qOkH68pZqQMCM-etN3BDeoHAdgpHFqqzdBXKh-O1WntI9tTGXKBct1IGCtkr87vzgGdb0wd2L-g8KmhyvBNLL8wQJE46HtFaRv0lD-hH6ulYWv1-2I3t6wo/s1600/arduino-trigger2.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_aWY6RO_KUwUPi_wMwIvm2qOkH68pZqQMCM-etN3BDeoHAdgpHFqqzdBXKh-O1WntI9tTGXKBct1IGCtkr87vzgGdb0wd2L-g8KmhyvBNLL8wQJE46HtFaRv0lD-hH6ulYWv1-2I3t6wo/s1600/arduino-trigger2.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Triggering circuit (optocoupler drawing from <a href="http://en.wikipedia.org/wiki/File:Optoisolator_Pinout.svg" target="_blank">Wikipedia</a>).<br />
Note: The polarity of the camera connector is important: if you reverse the pins, no current can flow through the the optocoupler (no damage to the camera, it just won't work).<br />
In my case, R<sub>led</sub> = 200 Ohm, R<sub>p</sub> = 36 kOhm, R<sub>t</sub> = 0</td></tr>
</tbody></table>
<br /></div>
<div style="text-align: left;">
The optocoupler provides a separation between the Arduino circuit on the right, and the camera on the left. When Pin 2 on the Arduino is grounded, no current flows through the LED, and the transistor on the right is in the "off" state, i.e. it does not let any current through. When a voltage is applied to Pin 2 (digital 1 = 5V), the led shines on the transistor, allowing current through it ("on" state).<br />
<br />
In this case I used a <a href="http://www.toshiba.com/taec/components2/Datasheet_Sync/207/4346.pdf">TLP627</a> optocoupler. The easiest parameter to compute is R<sub>led</sub>: As indicated in the datasheet, the forward voltage of the LED is 1.15V, and we want a maximum of 25mA. A simple calculation (or an <a href="http://led.linear1.org/1led.wiz" target="_blank">online tool</a>) will tell you that a 200 Ohm resistor is required.<br />
<br />
What we want here is the circuit to have a 44kOhm resistance (~2.5V) in the
rest state, and drop the resistance to 2 kOhm (~0.5V) when the optocoupler is
on. A simple solution would be to set Rp to 42 kOhm, and Rt to 2.1 kOhm. When the optocoupler is off, the total resistance is 44 kOhm, when it is on, the optocoupler shorts Rp, and the total becomes 2.1 kOhm.<br />
<br />
If you try this combination, you will realise that it is not enough to trigger the camera: the voltage drops, but only enough to pre-focus the camera, that is a voltage around 1 V.<br />
<br />
What is happening? In reality, the optocoupler is not an ideal switch: in the "on" state, it has a small, but finite, voltage drop. In my case, this voltage drop is around 0.5 V, just what we need to trigger the camera. Therefore, we can get rid of Rt, and simply set Rp to 44 kOhm. I did not have a 44 kOhm resistor, but I realised that 36 kOhm also works, so I used that.<br />
<br />
I'm not 100% sure of the theory behind, but I suspect that the transistor can only conduct current when it is close to its saturation voltage. However, for the <a href="http://www.toshiba.com/taec/components2/Datasheet_Sync/207/4346.pdf">TLP627</a>, the saturation voltage is anywhere between 0.3 to 1.2V, according to the datasheet. Therefore, you may need to adjust Rp depending on the individual properties of your optocoupler, or you may not be able to trigger the camera at all.<br />
<a href="http://dev-control.com/piclaps-diy.php" target="_blank"><br /></a>
<a href="http://dev-control.com/piclaps-diy.php" target="_blank">These guys</a> use a <a href="http://www.image.micros.com.pl/_dane_techniczne_auto/oopc355tltv.pdf" target="_blank">LTV-355T</a> optocoupler, with Rp=1 kOhm. I'm not sure what makes that optocoupler better, if it is better. I did not use it because it is only available as a surface mount component, while the TLP627 is available as 4DIP package, compatible with breadboards and stripboards.<br />
<br />
If there is an electrical engineer in the room, maybe that person can shed some light on this. I stopped thinking about it, because the circuit works, and that is all I need ,-) <br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3GysI85cPRuVxBKt6kKxaBpbL1UQiimBt14YVBCZBubqgnykQCihAXHlIesBOhO2zpnU1NDiIGwBW1akDLQjfuw7oXlkxZAAfmf_buu-avRMy5QZQL-VO8AnPp9AEO40t9mFdEmqRQie0/s1600/P1160496-sm.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="250" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3GysI85cPRuVxBKt6kKxaBpbL1UQiimBt14YVBCZBubqgnykQCihAXHlIesBOhO2zpnU1NDiIGwBW1akDLQjfuw7oXlkxZAAfmf_buu-avRMy5QZQL-VO8AnPp9AEO40t9mFdEmqRQie0/s400/P1160496-sm.JPG" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Finished circuit on a breadboard, connected to a Freeduino (Arduino clone).</td><td class="tr-caption" style="text-align: center;"><br /></td><td class="tr-caption" style="text-align: center;"><br /></td></tr>
</tbody></table>
</div>
<h4 style="text-align: left;">
Arduino sample code</h4>
The following code will trigger the Arduino every 10 seconds. This is useful for simple time-lapse photography:<br />
<div class="code">
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">int trigger = 2;<br />int led = 13;<br /><br />int time = 10; /* time between shots, in seconds */<br /><br />void setup() { <br /> Serial.begin(9600); <br /> analogReference(INTERNAL);<br /> pinMode(trigger, OUTPUT);<br /> pinMode(led, OUTPUT);<br /> digitalWrite(trigger, LOW);<br />} <br /><br />void loop() {<br /> for (int i = time-1; i > 0; i--) {<br /> delay(1000);<br /> }<br /> delay(900);<br /> digitalWrite(trigger, HIGH);<br /> digitalWrite(led, HIGH);<br /> delay(100);<br /> digitalWrite(trigger, LOW);<br /> digitalWrite(led, LOW);<br />}</span></span></div>
This code "holds down" the shutter for 100 milliseconds, enough to allow the camera to autofocus. It also blinks the Arduino LED on pin 13, to give you a visual feedback that the code is running, in case the camera does not trigger (wrong polarity, etc.).</div>
drinkcathttp://www.blogger.com/profile/08991363247732795423noreply@blogger.com0tag:blogger.com,1999:blog-7165329846281791578.post-12768681214610230512013-02-12T19:00:00.000+08:002013-02-20T19:36:47.750+08:00Tilt adapter for Micro Four Third - Part 3 - Simple adapter<div dir="ltr" style="text-align: left;" trbidi="on">
<i>This is the third part of the series on a tilt adapter for Micro Four Third system. Please read the <a href="http://drinkcat.blogspot.com/2013/02/tilt-adapter-for-micro-four-third-part1.html" target="_blank">introduction</a> first, and the <a href="http://drinkcat.blogspot.com/2013/02/tilt-adapter-for-micro-four-third-part2.html" target="_blank">lens selection</a> guide.</i><br />
<br />
This article will show you how to build a very simple DIY tilt adapter using a body cap, a lens cap, and some plastic bag.<br />
<div style="text-align: left;">
<h4 style="text-align: left;">
Make the adapter </h4>
You will need the following items:</div>
<ul style="text-align: left;">
<li>A lens (read the <a href="/2013/02/tilt-adapter-for-micro-four-third-part2.html" target="_blank">lens selection guide</a>, you can find a suitable Olympus OM lens on eBay for 20-30 USD)</li>
<li>Micro Four Third body cap (<3$ on <a href="http://www.ebay.com/sch/Lenses-Filters-/78997/i.html?_sop=15&_from=R40&_nkw=Micro+4%2F3+body+cap" target="_blank">eBay</a>)</li>
<li>Lens cap (<2$ on <a href="http://www.ebay.com/sch/Lenses-Filters-/78997/i.html?_sop=15&_from=R40&_nkw=Olympus+OM+lens+cap" target="_blank">eBay</a>). For Olympus OM lenses, a Four Third cap (not Micro Four Third!) also works (the mount is very similar).</li>
<li>Opaque plastic bag (thick but flexible plastic is best)</li>
<li>(Optional) Some black paper</li>
</ul>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1ez8qT1_z4dNRE8J9N_lP3Grpw_Id3XiEABV-DDNgMktexTioMO3DDlCBhHhDN8GgvVNr8XRUPvYfXAu7vFOAelPjSb_mAyWk8j3b7mc7cVgs1DLcZaPv2TKRl2CUJOXEKK-1qopaDoRf/s1600/P1160181.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="141" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1ez8qT1_z4dNRE8J9N_lP3Grpw_Id3XiEABV-DDNgMktexTioMO3DDlCBhHhDN8GgvVNr8XRUPvYfXAu7vFOAelPjSb_mAyWk8j3b7mc7cVgs1DLcZaPv2TKRl2CUJOXEKK-1qopaDoRf/s320/P1160181.JPG" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Left: Olympus OM lens cap. Right: Micro Four Third body cap</td><td class="tr-caption" style="text-align: center;"><br /></td><td class="tr-caption" style="text-align: center;"><br /></td><td class="tr-caption" style="text-align: center;"><br /></td><td class="tr-caption" style="text-align: center;"><br /></td></tr>
</tbody></table>
<a name='more'></a>Cut a wide hole in the body cap. This is the difficult part, if, like myself, you don't have power tools. I first used a cutter to make a small hole in the caps. Then, I could widen the hole with a handsaw. It would be far easier to do with a drill...<br />
<br />
"Chop off" the flat part of the lens cap with a saw, so that you end up with a ring. We do this instead of cutting a hole in order to make the cap a bit thinner, so that you can tilt the lens to a larger angle.<br />
<br />
You should get the following:<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5WW_xIS635eL9TH80zS9EZ3OXgvzEtoNnKbmh-mU9fWh0fdX7pVDnQ7xd0KxwdT3UOnYQlGUWd94uOl2vwLGCprMHLya8d0PV1YXGSaloHixJGINIB29kM9BAAFJp0NT5GNL6yGb40M3m/s1600/P1160191.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="156" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5WW_xIS635eL9TH80zS9EZ3OXgvzEtoNnKbmh-mU9fWh0fdX7pVDnQ7xd0KxwdT3UOnYQlGUWd94uOl2vwLGCprMHLya8d0PV1YXGSaloHixJGINIB29kM9BAAFJp0NT5GNL6yGb40M3m/s320/P1160191.JPG" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Left: Olympus OM lens cap. The flat part is cut off with a saw.<br />
Right: Micro Four Third body cap, the hole was (painfully) open with a cutter, then using a saw.</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4Iuq4txOteNTuah9xPz11UXVq8uUJENlr0sYnyFbzUK6hI97TIMsFAcDa690we680_4t0cHddz_-ADnzqwgZp0xQCbZz3vlgnYCFODJ_SwPZq0lGYnU9Vq1RuI_wAm1JJv68gZKdbsFcG/s1600/P1160192.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="156" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4Iuq4txOteNTuah9xPz11UXVq8uUJENlr0sYnyFbzUK6hI97TIMsFAcDa690we680_4t0cHddz_-ADnzqwgZp0xQCbZz3vlgnYCFODJ_SwPZq0lGYnU9Vq1RuI_wAm1JJv68gZKdbsFcG/s320/P1160192.JPG" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Opposite side.</td></tr>
</tbody></table>
<br />
<br />
Then, cut a piece of the plastic bag, about 20cm long, and 5cm wide. The plastic I use is shiny, so, to avoid unwanted reflections, I glued a piece of black paper to one side of the plastic sheet.<br />
<br />
Roll the plastic sheet around the lens cap, fix it as securely as possible using tape, then repeat the operation on the body cap.<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-fwCicEV6KxQSZBY_RFe1pjzhW-TUNvoKUfFM37J3lWs2B3ZiWSrXakn63krZ1DP2ZPV3lK0-iD2QVjJrWjES3k70UpVt2CaQjaQjigugG8gN4DnUJ5K0ujxJAYPq1D-BkQDryfcvxfvp/s1600/adapterv1.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="212" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-fwCicEV6KxQSZBY_RFe1pjzhW-TUNvoKUfFM37J3lWs2B3ZiWSrXakn63krZ1DP2ZPV3lK0-iD2QVjJrWjES3k70UpVt2CaQjaQjigugG8gN4DnUJ5K0ujxJAYPq1D-BkQDryfcvxfvp/s640/adapterv1.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">You should get something as "nice looking" as this ,-) You can see the black paper inside the adapter.</td></tr>
</tbody></table>
You're done! Congratulations!<br />
<h4 style="text-align: left;">
Use the adapter</h4>
<div style="text-align: left;">
Set the lens focus to infinity, and aperture wide open. Mount it on the adapter, then connect the adapter to the camera.</div>
<div style="text-align: left;">
<br /></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDkkXi0vNz9-mpD6WnI-ZAYZoR22rcLrIE9kM4kTfgqbPEdkqleBA48_RRcUYr1B5WNTlyCCXiZfP1umo4Be-R8OU39LvmFke-9mSvEN4JGkC6MDDX7uQZFmyZzTzhuLr5qU90v6QVwqgN/s1600/DSCN6288.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDkkXi0vNz9-mpD6WnI-ZAYZoR22rcLrIE9kM4kTfgqbPEdkqleBA48_RRcUYr1B5WNTlyCCXiZfP1umo4Be-R8OU39LvmFke-9mSvEN4JGkC6MDDX7uQZFmyZzTzhuLr5qU90v6QVwqgN/s320/DSCN6288.JPG" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Lens and adapter mounted on the camera.</td></tr>
</tbody></table>
<div style="text-align: left;">
</div>
<div style="text-align: left;">
Be careful of one thing: the lens cap and body cap are not meant to hold the weight of a lens, and do not lock in position. ALWAYS hold both the lens and the camera if you want to avoid broken glass... That also means you cannot change the focus or aperture easily (unless you have a third hand...). This is not a big problem for the focus: you actually adjust it by moving the lens closer or further away from the camera.</div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
Also, Olympus OM lenses always keep the widest aperture unless you activate the lever at the back of the lens. To block the lever, a little piece of paper does the trick. Just make sure it doesn't fall. In practice, I always use the lens at its widest aperture, so I do not need that.</div>
<div style="text-align: left;">
<br /></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPdQsEgWQHjAms-zPfgISAp1rId_DLKi9P3LaMUr9GJdaEafHMpXiFMpooGhqffDxk62BYtrXOc85sP4C2etYHuMIufFtkvUy7UbxfyXCde5q1kJsblhbXNxxvPmtoP8FkM1K3SxgiwyP8/s1600/P1160194.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="155" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPdQsEgWQHjAms-zPfgISAp1rId_DLKi9P3LaMUr9GJdaEafHMpXiFMpooGhqffDxk62BYtrXOc85sP4C2etYHuMIufFtkvUy7UbxfyXCde5q1kJsblhbXNxxvPmtoP8FkM1K3SxgiwyP8/s200/P1160194.JPG" width="200" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Block the aperture lever if you want to be able to control the aperture.</td></tr>
</tbody></table>
<div style="text-align: left;">
Alright, now you can start playing with it! Tilt the lens around, and observe the effect you get. The issue with this adapter is that you cannot, ever, get the same picture twice, and it is hard to control the tilt angle and orientation. But maybe that's part of the fun...<br />
<br />
Another drawback is that you cannot shoot video, since there is no way to fix the lens (but I'm working on it ,-)). <br />
<h4 style="text-align: left;">
Sample pictures </h4>
<div style="text-align: left;">
Unless otherwise mentioned, pictures are taken with the 28mm f/2.8 lens, tilted to about 16°. I also show some shots at 50mm f/1.8. I always stretch the contrast (the camera metering is a bit confused and underexpose shots), and boost the saturation to increase the "toy" effect.</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhu7e9B6i_A_8qZ5hfeMKRSmF8sCVK90DtmkA2sAYMp1KQo57bsz9ohKt8tV1B0E1uN-1bUZn6X_1maPi5YAXvMVccd083b11KDuLDUYCv5jzS0OwlZ9tjW8JZS_VV_TCw_uVNcrggB9VGG/s1600/P1150816.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhu7e9B6i_A_8qZ5hfeMKRSmF8sCVK90DtmkA2sAYMp1KQo57bsz9ohKt8tV1B0E1uN-1bUZn6X_1maPi5YAXvMVccd083b11KDuLDUYCv5jzS0OwlZ9tjW8JZS_VV_TCw_uVNcrggB9VGG/s640/P1150816.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><br />
28mm lens, tilt ~16°, f/2.8, 1/2000s, ISO 160.</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmN0W8nl0bm4Sw8_BK7zhsicNnibeWDWI8kJ9n1WXcghQV3YCRQeusDwMEjdQbomJLCxKskTmDp2l4DHZH6hv91frVlV79m_7q0Cua_cFgggQqviLWYNJOw1VKQ8Jcm43gS2ZczBMaNjOs/s1600/P1150855.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmN0W8nl0bm4Sw8_BK7zhsicNnibeWDWI8kJ9n1WXcghQV3YCRQeusDwMEjdQbomJLCxKskTmDp2l4DHZH6hv91frVlV79m_7q0Cua_cFgggQqviLWYNJOw1VKQ8Jcm43gS2ZczBMaNjOs/s640/P1150855.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">28mm lens, tilt ~16°, f/2.8, 1/25s, ISO 1600.</td></tr>
</tbody></table>
<br />
You can find a set a sample pictures <a href="https://picasaweb.google.com/107363214762755220776/TiltShift201302?authuser=0&authkey=Gv1sRgCKOKvKK5sOXZyQE&feat=directlink" target="_blank">here</a>, or see the slideshow below:<br />
<embed flashvars="host=picasaweb.google.com&captions=1&noautoplay=1&hl=en_US&feat=flashalbum&RGB=0x000000&feed=https%3A%2F%2Fpicasaweb.google.com%2Fdata%2Ffeed%2Fapi%2Fuser%2F107363214762755220776%2Falbumid%2F5840571663858489249%3Falt%3Drss%26kind%3Dphoto%26authkey%3DGv1sRgCKOKvKK5sOXZyQE%26hl%3Den_US" height="400" pluginspage="http://www.macromedia.com/go/getflashplayer" src="https://picasaweb.google.com/s/c/bin/slideshow.swf" type="application/x-shockwave-flash" width="600"></embed>
</div>
</div>
drinkcathttp://www.blogger.com/profile/08991363247732795423noreply@blogger.com0tag:blogger.com,1999:blog-7165329846281791578.post-29272020535229995752013-02-07T19:00:00.000+08:002013-02-20T19:37:04.557+08:00Tilt adapter for Micro Four Third - Part 2 - Lens selection<div dir="ltr" style="text-align: left;" trbidi="on">
<i>This is the second part of the series on a tilt adapter for Micro Four Third system. Please read the <a href="http://drinkcat.blogspot.com/2013/02/tilt-adapter-for-micro-four-third-part1.html" target="_blank">introduction</a> first. The next article shows you how to build a <a href="http://drinkcat.blogspot.com/2013/02/tilt-adapter-for-micro-four-third-part3.html" target="_blank">simple adapter</a>.</i><br />
<br />
The first thing you need is to find a suitable lens. If you read the <a href="http://cow.mooh.org/projects/tiltshift/" target="_blank">plungercam</a> tutorial, you need to check 2 things: the flange focal distance, and the image sensor/film size. <br />
<h4 style="text-align: left;">
Flange focal distance </h4>
The <a href="http://en.wikipedia.org/wiki/Flange_focal_distance" target="_blank">flange focal distance</a> tells you the distance between the lens mount and the image sensor. For tilt-shift, you want to be able to move the lens around without hitting the camera, therefore, you need a lens with a flange focal distance larger than the one of the camera.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://upload.wikimedia.org/wikipedia/commons/thumb/c/c8/Flange_Focal_Length_(2_types_camera).PNG/481px-Flange_Focal_Length_(2_types_camera).PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="320" src="http://upload.wikimedia.org/wikipedia/commons/thumb/c/c8/Flange_Focal_Length_(2_types_camera).PNG/481px-Flange_Focal_Length_(2_types_camera).PNG" width="256" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Flange range on a DSLR (top), versus mirror-less camera (bottom).<br />
Drawn by
<a class="new" href="http://commons.wikimedia.org/w/index.php?title=User:Shigeru23&action=edit&redlink=1" title="User:Shigeru23 (page does not exist)">Shigeru23</a> on <a href="http://en.wikipedia.org/wiki/File:Flange_Focal_Length_%282_types_camera%29.PNG" target="_blank">Wikipedia</a> (<a href="http://creativecommons.org/licenses/by-sa/3.0/deed.en" target="_blank">CC BY-SA 3.0</a>).</td></tr>
</tbody></table>
<br /><a name='more'></a>
Luckily, the Micro Four Third system flange focal distance is very short (19.25mm), which means that most lenses design for common DSLR systems will work, for example: Nikon F-mount (46.50mm), Canon EF mount (44mm), or Olympus OM mount (46mm). (see the <a href="http://en.wikipedia.org/wiki/Flange_focal_distance" target="_blank">Wikipedia</a> page for a full list).<br />
<h4 style="text-align: left;">
Sensor size</h4>
<div style="text-align: left;">
The second thing to look for is the sensor size (or film size for an older system). You want the lens to be designed for a slightly bigger sensor area than the one of your camera, since you are not necessarily using the center of the projected image circle of the lens.</div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
Again, the Micro Four Third sensor is relatively small (crop factor "2" compared to a 35mm film), which means that most lenses designed for DSLR (APS size or 35mm full-frame) will work. </div>
<h4 style="text-align: left;">
Other considerations</h4>
<div style="text-align: left;">
Finally, you also want a lens with full manual control of the aperture: for example, Nikon G series or recent Canon lenses are not a great idea since they do not have an aperture ring.</div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
Also, I would recommend a prime lens (i.e. a lens with a fixed focal length). Those are cheaper, and faster: The larger aperture (lower f/ number) will help you to get the tilt effect more easily. <br />
<h4 style="text-align: left;">
Focal length</h4>
<div style="text-align: left;">
This is a drawback of having a small sensor: it will be hard to find compatible wide-angle lens. The widest focal length of the DMC-GX1 kit lens is 14mm. That same focal length would correspond to an ultrawide angle on a full frame sensor, which will be hard to find, and likely very expensive.</div>
</div>
<div style="text-align: left;">
<h4 style="text-align: left;">
My selection</h4>
</div>
<div style="text-align: left;">
In the end, I bought the following 2 lenses:<br />
<ul style="text-align: left;">
<li>Olympus OM 50mm f/1.8</li>
<li>Promaster 28mm f/2.8 (Olympus OM mount)</li>
</ul>
I could find both for less than 20 USD on eBay. I have the feeling (but I may be wrong) that the Olympus OM lenses are cheaper than their Nikon/Canon counterparts, since there is no modern camera taking in those lenses, while an old Nikon F-mount lens can still be mounted on any recent Nikon DSLR.<br />
<br />
I first bought the 50mm lens. This is an very nice lens, but with a narrow field of view (equivalent to 100mm on a 35mm film). I then bought the 28mm lens, which is the widest I could find for a reasonable price, and works much better for landscape photography, as can be seen in the images below.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1LXLTNZxMSW8IqFCdTPFv1EM_RmmgpeyOiF_21veyR7Uf8ThJJF4b3Xf59BCyheg4Vaaryk9883b5yTqHHdlkB9Amnw_bVno-vxD3U6P0lVfz4nmHVQRG3H5LB4jEr640_o3rDUljrixB/s1600/P1150803.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1LXLTNZxMSW8IqFCdTPFv1EM_RmmgpeyOiF_21veyR7Uf8ThJJF4b3Xf59BCyheg4Vaaryk9883b5yTqHHdlkB9Amnw_bVno-vxD3U6P0lVfz4nmHVQRG3H5LB4jEr640_o3rDUljrixB/s640/P1150803.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><br />
28mm lens, tilt ~16°, f/2.8, 1/4000s, ISO 160.<br />
Alterations in GIMP: contrast stretching and saturation.<br />
(click on picture
to zoom)</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZBUbBG1xP8T4iBf-_CSDA1Rb2v31hbg-nJgF-dNzw1mFdE4xCVUOiieegGk_EUwcIl65eboHY2ke-aBQv5axVb_s41AU-y0EKb0V9nmtE9hATNVs5x7_zyeGegpZeuQoOsi5yIqUOgA1v/s1600/P1150810.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZBUbBG1xP8T4iBf-_CSDA1Rb2v31hbg-nJgF-dNzw1mFdE4xCVUOiieegGk_EUwcIl65eboHY2ke-aBQv5axVb_s41AU-y0EKb0V9nmtE9hATNVs5x7_zyeGegpZeuQoOsi5yIqUOgA1v/s640/P1150810.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><br />
50mm lens, tilt ~16°, f/1.8, 1/3200s, ISO 160.<br />
Alterations in GIMP: contrast stretching and saturation.<br />
(click on picture
to zoom)</td></tr>
</tbody></table>
<br /></div>
</div>
drinkcathttp://www.blogger.com/profile/08991363247732795423noreply@blogger.com0tag:blogger.com,1999:blog-7165329846281791578.post-71633849322976497392013-02-04T19:00:00.000+08:002013-02-20T19:37:25.857+08:00Tilt adapter for Micro Four Third - Part 1 - Introduction<div dir="ltr" style="text-align: left;" trbidi="on">
<i>This post is an introduction to the topic. See the next article for some advise on <a href="http://drinkcat.blogspot.com/2013/02/tilt-adapter-for-micro-four-third-part2.html" target="_blank">lens selection</a>, and the following one for instructions to build a <a href="http://drinkcat.blogspot.com/2013/02/tilt-adapter-for-micro-four-third-part3.html" target="_blank">simple adapter</a>. </i><br />
<br />
Tilt-shift pictures are getting quite popular nowadays, especially the tilt effect that gives a miniature effect to pictures. This is especially beautiful in videos, an example is shown below.<br />
<br />
<div style="text-align: center;">
<iframe allowfullscreen="" frameborder="0" height="300" mozallowfullscreen="" src="http://player.vimeo.com/video/6243891" webkitallowfullscreen="" width="400"></iframe></div>
<br />
<a name='more'></a>Many cameras, including mine (Panasonic DMC-GX1), include a "fake miniature" effect, that digitally blurs the top and bottom of the image to simulate a tilt lens. But I don't like so much the idea of post-processing, so I decided to use a real tilt-shift adapter.<br />
<br />
The basic idea is to put an adapter between the lens and the camera body, that allows the lens to move around. By tilting the lens at some angle with respect to the camera sensor, you can simulate an exaggeratedly narrow depth of field, that makes large objects look like miniatures.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOO9YCfHvV7pQurfJJoK3ACGqYWsf3z4Gh6setCaaOatUGRqDNsYW4tVtsW3Nh9693mNWdXsWJE2P-AZXAXuXbSQ6FaY7ejyyDGoZVp5cKwm4RCBoWK9kjQuGVkHWqvQlp3i44QRiESOVv/s1600/P1150797_modified.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOO9YCfHvV7pQurfJJoK3ACGqYWsf3z4Gh6setCaaOatUGRqDNsYW4tVtsW3Nh9693mNWdXsWJE2P-AZXAXuXbSQ6FaY7ejyyDGoZVp5cKwm4RCBoWK9kjQuGVkHWqvQlp3i44QRiESOVv/s640/P1150797_modified.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Example of tilt picture. Taken from the 10th floor of a building, with
my self-made adapter.<br />
28mm lens, tilt ~16°, f/2.8, 1/1600s, ISO 160.<br />
Alterations in GIMP: contrast stretching and saturation.<br />
(click on picture
to zoom)</td></tr>
</tbody></table>
Commercial adapters can be fairly expensive, around 2000$ for <a href="http://www.bhphotovideo.com/c/product/606804-USA/Canon_3552B002_TS_E_24mm_f_3_5L_II.html" target="_blank">that one</a> (including the lens). Even for the Micro Four Third system, you could pay up to 500$ or so.<br />
<br />
<a href="http://cow.mooh.org/projects/tiltshift/" target="_blank">This guy</a> had a great idea of a self-made adapter, using a plunger, hence the name of his adapter: "plungercam". Please follow the link, that explains a lot about how tilt-shift works, and what kind of lenses would work.<br />
<br />
In these posts, I will just focus on the Micro Four Third system, and my version of the plungercam. The next article will focus on <a href="http://drinkcat.blogspot.com/2013/02/tilt-adapter-for-micro-four-third-part2.html" target="_blank">lens selection</a>, and the following one on a <a href="http://drinkcat.blogspot.com/2013/02/tilt-adapter-for-micro-four-third-part3.html" target="_blank">simple DIY adapter</a>.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDkkXi0vNz9-mpD6WnI-ZAYZoR22rcLrIE9kM4kTfgqbPEdkqleBA48_RRcUYr1B5WNTlyCCXiZfP1umo4Be-R8OU39LvmFke-9mSvEN4JGkC6MDDX7uQZFmyZzTzhuLr5qU90v6QVwqgN/s1600/DSCN6288.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDkkXi0vNz9-mpD6WnI-ZAYZoR22rcLrIE9kM4kTfgqbPEdkqleBA48_RRcUYr1B5WNTlyCCXiZfP1umo4Be-R8OU39LvmFke-9mSvEN4JGkC6MDDX7uQZFmyZzTzhuLr5qU90v6QVwqgN/s400/DSCN6288.JPG" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Self-made tilt adapter, mounted on my camera.<br />
The plastic piece is flexible, allowing for relatively free movement of the lens.</td></tr>
</tbody></table>
</div>
drinkcathttp://www.blogger.com/profile/08991363247732795423noreply@blogger.com0tag:blogger.com,1999:blog-7165329846281791578.post-40407179335059307562013-01-29T20:00:00.000+08:002013-02-19T22:25:56.647+08:00Pinwide "lens" - or real life Instagram<div dir="ltr" style="text-align: left;" trbidi="on">
I recently bought the <a href="http://wanderlustcameras.com/products/pinwide.html" target="_blank">pinwide</a> cap for my micro 4/3 camera (Panasonic DMC-GX1). Sure, you can also make a pinhole by making a hole in a camera camera cap, but this one is "optimised", with the pinhole receding inside the camera body to get an image as wide as possible.<br />
<br />
The adapter is made of good quality plastic (polycarbonate "<a href="http://en.wikipedia.org/wiki/Char_siu" target="_blank">char siew</a>" according to <a href="http://www.youtube.com/watch?v=RLgM0Pac6qA&list=PL98C6084687FC7A94&index=42" target="_blank">DigitalRevTV</a>), and comes in a nice little metal box.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFoBLut1-CubOD4DUjKixPVUwilwAKT57KmuV4-dnWPB_47iVZRaBwYU22psJuL3GBC07EoqBtuYtfrpnlyq22D27J4_cPA4HW_Nse1-kfqesijgItO-4vOJJAC3akewaydKYmHR0efA3I/s1600/P1150737_modified.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="220" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFoBLut1-CubOD4DUjKixPVUwilwAKT57KmuV4-dnWPB_47iVZRaBwYU22psJuL3GBC07EoqBtuYtfrpnlyq22D27J4_cPA4HW_Nse1-kfqesijgItO-4vOJJAC3akewaydKYmHR0efA3I/s400/P1150737_modified.JPG" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Pinwide in its box</td></tr>
</tbody></table><a name='more'></a>
I found mounting it on the camera is a little difficult, you need to align the "W" with the red dot on the lens mount, but even then, I feel like I need more force to screw it in compared to any other lens I own. I was also a bit scared that the receding part would hit the shutter mechanism, but thankfully, it doesn't...<br />
<br />
The center of the pinwide adapter is covered with a membrane, and the hole (about 100 microns diameter) is cut on that membrane. The membrane is hard to break by accident, as it is about 2mm inside the adapter.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuuzjXb6DnJOq53CS7FEwck3eiitLP_kF7lG20yuKPQrl9rsbEuCYGEOmEK96f4hCfR7JkYK0v5VuLwAFF-sWsAJdgJ3oawHkAd8EVWt8p8LQ5xh-ibpUPcHcdsyRB5mPCwwckSQYotqed/s1600/P1150741_corr_modified.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="252" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuuzjXb6DnJOq53CS7FEwck3eiitLP_kF7lG20yuKPQrl9rsbEuCYGEOmEK96f4hCfR7JkYK0v5VuLwAFF-sWsAJdgJ3oawHkAd8EVWt8p8LQ5xh-ibpUPcHcdsyRB5mPCwwckSQYotqed/s320/P1150741_corr_modified.JPG" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Pinhole and its membrane.</td></tr>
</tbody></table>
"Thanks" to its incredibly small aperture (f/96 in the center of the image to f/128 on the edge), you need long exposures, even in broad daylight. The following picture is taken on a very sunny day, but even at high ISO (1600), the camera needs 1/50s exposure time.<br />
<br />
What you get is this kind of "Instagram"-like pictures:<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgqxIComyJBooVaQvJ7YPy6Nd7_zm0GrsaC5zCK8GM9BwSVlcQ1RngfcIQuAL0E0tDMs68wD-Y_OmdX12Wf9muz4D_hjKXn1UeRwPMs2h8BOeoRqzadEdXrvoEBHRIPLK5JG8g-wOKFLKt/s1600/P1150728.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgqxIComyJBooVaQvJ7YPy6Nd7_zm0GrsaC5zCK8GM9BwSVlcQ1RngfcIQuAL0E0tDMs68wD-Y_OmdX12Wf9muz4D_hjKXn1UeRwPMs2h8BOeoRqzadEdXrvoEBHRIPLK5JG8g-wOKFLKt/s640/P1150728.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">ISO 1600, 1/50 exposure. Click for higher resolution.</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1dc-izB1p-XX197uCmer683t_oTAimtl50LB6gBXxX_n1NZbG75lsUKJkoxjZnnkzBK1PwgHJaDVPaLbabC0Zp67xL51iw__NPUy8iatRQiTknAYbT7n_71jyofwpwO_ldiQ5kOgZfzEX/s1600/P1150731.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1dc-izB1p-XX197uCmer683t_oTAimtl50LB6gBXxX_n1NZbG75lsUKJkoxjZnnkzBK1PwgHJaDVPaLbabC0Zp67xL51iw__NPUy8iatRQiTknAYbT7n_71jyofwpwO_ldiQ5kOgZfzEX/s400/P1150731.JPG" width="300" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">ISO 1600, 1/60s. The sun flares in an interesting manner. Click for higher resolution.</td></tr>
</tbody></table>
There is a lot of vignetting (dark edges), as expected from a pinhole.
Also, the image is far from sharp, as can be seen in the 100% crop,
partly due to high ISO, but mainly due to diffraction.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgt0Om5qNawzrIO9mASjn5U85WBmvCJg0ofVApScmt0GYRq4qyCk7LyuB8N7Ma400i2ilu04DLY401A9Pn5t1DDBafGQACXiF_ctbB2A4jqDQiHwGlsCTQpVj0mlsBiFGegmE_tu_zN__4T/s1600/P1150728_modified.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgt0Om5qNawzrIO9mASjn5U85WBmvCJg0ofVApScmt0GYRq4qyCk7LyuB8N7Ma400i2ilu04DLY401A9Pn5t1DDBafGQACXiF_ctbB2A4jqDQiHwGlsCTQpVj0mlsBiFGegmE_tu_zN__4T/s1600/P1150728_modified.JPG" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">100% crop near the center of the image.</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<br />
Finally, another interesting effect of the small aperture is that everything is in focus, from close to infinity. Actually, <u>absolutely</u> everything is in focus, even dust on the sensor itself shows in the images. You can see every single speckle of dust of the camera sensor, which cannot normally be seen with a normal lens, even at low aperture (e.g. f/22).<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh73Hi8k6y-DSDxnI2XYkwAUZYhQF4yd40HYpJdpgAVvMNztzuy22ihae-3-Zu9zIqqCLnc6T-0Svn0IbdclLxgX3sIB8w-WTThyUqFFGLs3KKGHICBsFWDGFEK9YHvlTEg6Fi90wsg_1Vy/s1600/P1150728_modified_dust_arrow.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="262" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh73Hi8k6y-DSDxnI2XYkwAUZYhQF4yd40HYpJdpgAVvMNztzuy22ihae-3-Zu9zIqqCLnc6T-0Svn0IbdclLxgX3sIB8w-WTThyUqFFGLs3KKGHICBsFWDGFEK9YHvlTEg6Fi90wsg_1Vy/s400/P1150728_modified_dust_arrow.JPG" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Dust on the sensor</td></tr>
</tbody></table>
In short, an interesting "lens" to add to my collection. Probably a bit expensive for a pinhole (39.99 USD), but it provides opportunities for some creative shots, and I still need to explore its full potential.</div>
drinkcathttp://www.blogger.com/profile/08991363247732795423noreply@blogger.com0tag:blogger.com,1999:blog-7165329846281791578.post-17855593560150493182013-01-18T20:34:00.000+08:002013-02-20T19:37:47.464+08:00Nikon Charger vs "Nikon" Charger<div dir="ltr" style="text-align: left;" trbidi="on">
On the topic of <a href="http://drinkcat.blogspot.com/2012/12/dell-charger-vs-dell-charger.html">charger vs charger</a>, and how they are not all born equal, here is another one.<br />
<br />
This one is a battery charger, for a Nikon Coolpix camera. The original one refused to charge, while in India. The Nikon centre over there opened it, and apparently fixed it. However, it still refused to charge the battery, so we bought another one (on <a href="http://www.ebay.com/itm/150853166862?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649" target="_blank">eBay</a>, again...).<br />
<br />
Let's compare the 2 chargers. From the outside, they look pretty similar:<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhab-lOONVr1rqV2jFHWRpGUvtTYttogys-myy7syZk5RlFdMAMqdF6qnAdzBBXqEhhyphenhyphenmnqS4VLV-ro0FECeoq-ZidYqVhx3afSRER7zB0nV4ZPsJAYRpFgPTzg4pdLXL-sn50uSUuhEohw/s1600/nikon12.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="268" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhab-lOONVr1rqV2jFHWRpGUvtTYttogys-myy7syZk5RlFdMAMqdF6qnAdzBBXqEhhyphenhyphenmnqS4VLV-ro0FECeoq-ZidYqVhx3afSRER7zB0nV4ZPsJAYRpFgPTzg4pdLXL-sn50uSUuhEohw/s640/nikon12.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Left: eBay charger. Right: original charger. (click to zoom)</td></tr>
</tbody></table><a name='more'></a>
Same shape, same markings on the front. Different labels on the back, but both of them look serious. Now the differences: yellow LED on the counterfeit charger, versus orange LED on the real one. This font of the logo is wrong, but it is not obvious to see without a magnifying lens (not as obvious as the <a href="http://drinkcat.blogspot.com/2012/12/dell-charger-vs-dell-charger.html" target="_blank">Dell</a> one):<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqzN8z08zTm_WapI1wILCj1rGArFmZ07WOCc-p5VIMuwPCaUaFt7JEeRHx8JEfDDwePnV4zWUQJlXH9ixZv_ad_tfNoaOea5YRX-JLJEeUMgBX9Go-zM6pY8kLMsE2uBphNkx_6cvz8z_d/s1600/nikon-logo.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqzN8z08zTm_WapI1wILCj1rGArFmZ07WOCc-p5VIMuwPCaUaFt7JEeRHx8JEfDDwePnV4zWUQJlXH9ixZv_ad_tfNoaOea5YRX-JLJEeUMgBX9Go-zM6pY8kLMsE2uBphNkx_6cvz8z_d/s1600/nikon-logo.JPG" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Top: eBay. Bottom: Original.</td></tr>
</tbody></table>
Also, the text in French has a few spelling mistakes, and words are not hyphenated properly (but this could happen even on an original product...).<br />
<br />
<a href="http://support.nikonusa.com/app/answers/detail/a_id/14297/%7E/counterfeit-nikon-accessories" target="_blank">This page</a> on Nikon's website gives a few indications of things to look at (LED color, font of the Nikon logo...): it seems I got a "standard" counterfeit charger.<br />
<br />
But the real difference is inside... The original charger says "Do not disassemble", and is glued together, but since the service in India opened it, I didn't feel too guilty... (careful of residual charges in the high voltage capacitors..) The eBay charger provides with a screw: easy to open.<br />
<br />
The difference is very obvious:<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUKo7ShIjO3bz37EVDag3PnRRTvGh2VpMHqCiXdy0g5WPDR5EaDGO4QIgGOPsHTfTJcH9HZ95k5TvGPPnupCcZQ8TTAtOZQtMq-DJdOAAAEcyxHqSvxWBxpD2eB7-721cq6LiiwMefIlOL/s1600/nikon12.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="266" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUKo7ShIjO3bz37EVDag3PnRRTvGh2VpMHqCiXdy0g5WPDR5EaDGO4QIgGOPsHTfTJcH9HZ95k5TvGPPnupCcZQ8TTAtOZQtMq-DJdOAAAEcyxHqSvxWBxpD2eB7-721cq6LiiwMefIlOL/s640/nikon12.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Back and front of the PCB. Left: eBay. Right: Original. (click to zoom)</td></tr>
</tbody></table>
<br />
The fake charger uses a small PCB, with a limited number of components. The battery contacts are badly glued, and broke after a few uses: you can see my attempt at glueing it back in place.<br />
<br />
The real one is much more complicated, with a proper separation between high and low voltage parts. It even features a Cypress <a href="http://www.cypress.com/?mpn=CY8C24223A-12PVXE" target="_blank">microcontroller</a>, that, alone, is almost as expensive as the eBay charger (3.20$ for the Cypress chip, 4.74$ for the charger).<br />
<br />
Both chargers seem to be able to do their job properly, but I'm pretty sure that the eBay charger has little protection against overcharging or other mishaps. So, in the worse case, keep an eye on it while it's charging (not too close, with your eye, just in case...), in the best case, don't use it! <br />
<br />
Well, <a href="http://drinkcat.blogspot.com/2012/12/dell-charger-vs-dell-charger.html" target="_blank">same morale of the story</a>: you get what you pay for. Don't be fooled by the fact the charger you're buying says "Nikon", "Dell", or any other brand.</div>
drinkcathttp://www.blogger.com/profile/08991363247732795423noreply@blogger.com0tag:blogger.com,1999:blog-7165329846281791578.post-8998811889464578512013-01-08T10:22:00.000+08:002013-02-19T20:23:26.441+08:00Picasa as (random) data storage<div dir="ltr" style="text-align: left;" trbidi="on">
People have been using Gmail storage space for backup purpose, <a href="http://sr71.net/projects/gmailfs/" target="_blank">GmailFS</a> is one of such projects. What I propose here is to use Google Picasa: Storage space is unlimited, as long as your image dimensions do not exceed 2048x2048 pixels. By encoding data to appear as a image, you could potentially get unlimited storage space.<br /><a name='more'></a>
<div class="hintbox">
<b>Disclaimer</b>: This may be a gray area in terms of Google terms of Service. I can't find anything that explicitly forbids doing what I describe here, but I would not be surprised if your data suddenly disappears, or if your account gets <a href="http://www.dslreports.com/forum/remark,16983539" target="_blank">suspended</a> (it happened for people using GmailFS), especially if you start uploading terabytes of data...<br />
Anyway, I would not use it for serious data backup, and I don't use it myself. I just thought the idea was fun.</div>
Alright. The first step is to install the 2 tools we will need:<br />
<ul style="text-align: left;">
<li>Google command line (<span style="font-family: "Courier New",Courier,monospace;">googlecl</span> package on Archlinux)</li>
<li>Imagemagick (<span style="font-family: "Courier New",Courier,monospace;">imagemagick</span> package)</li>
</ul>
Then, pick a file you want to upload. I created a simple text file. The text is only a few hundreds byte long, so I encoded a JPEG image in base64, and appended it to the text:<br />
<div class="code">
<span style="font-family: "Courier New", Courier, monospace;">Hello World!<br /><br />File below (a jpeg image), can be decoded with:<br />tail -n +10 myfile | base64 -d > img.jpg<br /><br />Random ideas of a drinking cat<br />-- http://drinkcat.blogspot.com/<br /><br />BEGIN<br />/9j/4AAQSkZJRgABAQAAAQABAAD/4QlERXhpZgAASUkqAAgAAAACADEBAgAHAAAAJgAAAGmHBAAB</span><br />
<span style="font-family: "Courier New", Courier, monospace;">[many lines of base64 encoded content]</span></div>
<div style="text-align: left;">
The total file length is 73305 bytes. This can easily fit in a 256x256 color image: each pixel takes 3 bytes, one for each of the 3 base colors (red, green, blue). 256 * 256 * 3 = 196608 bytes. But remember, you can store much more than that in one image: the maximum "free" image size is 2048x2048, that's 12 MiB. You just need to split your data in chunks of 12 MiB, and you can store as much data as you want.</div>
<br />
We are going to create a PNG file out of the data. We use PNG instead of JPEG, because PNG uses a lossless compression algorithm, while JPEG compression is lossy: it tries to minimize differences in image, according to what the human eye perceives. Good for pictures of real things, but not good when you're trying to recover the exact information you put in the image.<br />
<br />
We can use Imagemagick to create the PNG file:<br />
<div class="code">
<span style="font-family: "Courier New", Courier, monospace;">convert -size 256x256 -depth 8 RGB:myfile myfile.png</span></div>
However, this outputs:<span style="font-family: inherit;"></span>
<br />
<div class="code">
<span style="font-family: "Courier New", Courier, monospace;">convert: unexpected end-of-file `myfile': No such file or directory @ error/rgb.c/ReadRGBImage/231.</span></div>
This is because the text file is not long enough to cover the whole 256x256 image.<br />
<br />
The workaround is simple: let's create a blank file of the correct size, and overwrite the beginning of the file with our text file:<br />
<div class="code">
<span style="font-family: "Courier New",Courier,monospace;">dd if=/dev/zero of=pad bs=1 count=196608<br />dd if=myfile of=pad conv=notrunc</span></div>
The <span style="font-family: "Courier New",Courier,monospace;">notrunc</span> option makes sure the output file is not truncated before the content of <span style="font-family: "Courier New",Courier,monospace;">myfile</span> is written.<br />
<br />
Now we can convert the file:<br />
<div class="code">
<span style="font-family: "Courier New", Courier, monospace;">convert -size 256x256 -depth 8 RGB:myfile myfile.png</span></div>
And<span style="font-family: inherit;"> we get this (not-so-)beautiful image.</span><br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgiicqwWzYSxEr2rGqae1q11qr-D8jF9xgNNM_sIwVuHSHJ_VJuLav0pgpCMdXBo6n4wl8gH-cOpDx5xuhkcuTbdlEIFl28iqgz2ACy4qj19B98Ue3AE1Tsua9p4mfs2lxy4cXvnhCAqoPj/s1600/myfile.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgiicqwWzYSxEr2rGqae1q11qr-D8jF9xgNNM_sIwVuHSHJ_VJuLav0pgpCMdXBo6n4wl8gH-cOpDx5xuhkcuTbdlEIFl28iqgz2ACy4qj19B98Ue3AE1Tsua9p4mfs2lxy4cXvnhCAqoPj/s400/myfile.png" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The encoded image.</td></tr>
</tbody></table>
<span style="font-family: inherit;">You can see some black lines patterns in the image. This corresponds to the new lines in the base64 encoded image: every 77 characters, there is a line feed. The line feed has ASCII value 10, i.e. quite dark, while the rest are printable characters with values above 60 (darkish gray).</span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">Now we can easily recover the content. Download the image as <span style="font-family: "Courier New",Courier,monospace;">myfile2.png</span>, then run:</span>
<div class="code">
<span style="font-family: "Courier New",Courier,monospace;">convert myfile2.png RGB:pad</span><br />
<span style="font-family: "Courier New",Courier,monospace;">dd if=pad2 of=myfile2 bs=1 count=73305</span></div>
<span style="font-family: inherit;">And you can check that </span><span style="font-family: "Courier New",Courier,monospace;">myfile</span> and <span style="font-family: "Courier New",Courier,monospace;">myfile2</span> are identical.<br />
<br />
We could of course automate the process, but that's not the point here (feel free to do it if you want to take the risk of using Picasa as a sharing facility).<br />
<br />
<div style="text-align: left;">
A nicer, and more "subversive" way is <a href="http://en.wikipedia.org/wiki/Steganography" target="_blank">steganography</a>. Steganography embeds data in an otherwise normal looking image. But that will be for another post.</div>
</div>
drinkcathttp://www.blogger.com/profile/08991363247732795423noreply@blogger.com2