Leave a reply

Focus Stacking images from a (4K) Video with Photoshop

Some Panasonic cameras offer a feature to stack a 4k video sequence to one image internally in order to enhance the Depth-of-Field, which is useful in macro shots. My Sony camera didn’t offer this feature. However, I found out that Photoshop CC offers a very clever function to get it done yourself in post-processing.

Capturing the video

When capturing the video, make sure you set a short shutter speed (e.g. 1/500 second) to prevent motion-blur in your individual frames. Then, record video and pull your focus from front to back (or just slightly shift the camera from front to back).
Use the highest resolution available. 4k videos will result in 8 Megapixel images, while 1080p footage just give you an 2 MP image. Keep in mind that some resolution might be lost through image alignment or later cropping!


  1. Open Photoshop, go to File -> Import -> Videoframes as Layers…
  2. Select your video file from the camera
  3. In the dialog, I recommend to set a skip amount for frames. I usually just use about every 5th or 10th frame for better (and faster) results. I recommend to keep the amount of images as low as possible for faster computation (less than 10 images are recommended)
  4. You should now see a list of layers from your video
  5. may delete the first and last frame(s) if they don’t line up correctly, check for frames which are almost identical and delete them in order to keep the amount of layers as low as possible
  6. (Optional but recommended, align the images) Select all Layers and go to Edit -> Automatically align layers… The Auto mode usually works good
  7. Select all layers, go to Edit -> Automatically blend layers… and choose the mode “Stack”. Hit okay
  8. Now, it will take quite a while

The results are quite good, even when you just handhold your camera. But keep in mind that this process take quite a while. For my sample, I aligned+stacked from a 3 second clip about 8 frames, which took about 10(!) minutes on a i7-5930K, which is quite fast hardware. The general problem is that Photoshop doesn’t make use of multiple cores when stacking layers, which is really a dissapointment. You also need a lot of RAM, in my test, Photoshop happily took up to 4 GB just for itself. So having a PC with at least 8 GB will help a lot.

Below you see one sample result:

You can see that the result is not perfect, you sometimes see some issues especially at the edge of the frame. However, for a quick handheld video shot, I think it’s quite good.

For the sake of comparison, here is how the same scene looks like with just one frame, you can see that most of the leave is out-of-focus because of the shallow depth-of-field (although I used quite a small aperture):


One of the biggest downside is probably the limited resolution of your video, even with 4k you’re still limited to 8 Megapixels. Also, since video is usually just 8 Bit compressed, you don’t have much post-processing latitude especially in terms of dynamic range. Shooting with a Log Profile can help, but then again you’re limited to 8 Bit (at least on consumer cameras) which can quickly lead to banding.
An alternative would be to fire a sequence of images, but this only works if you’re on a tripod or you have a camera with a very fast Framerate (e.g. the Sony A6000 series has up to 11 FPS in Continous Burst, and the Sony RX100 V has up to 24 FPS).
Last but not least, also keep in mind that most video codecs do interframe compression which means they looking for differences between frames and make use of visual limitations, which means you may see artifacts in a still grabed from a video that you wouldn’t notice when viewing it).

Still, it’s a great way to get fast results and it’s fun to play with

2 Replies

Flashing Arduino Leonardo Bootloader of Lattepanda

I recently run into trouble with a LattePanda. The Arduino Leonardo on it was not detected anymore by the system. I tried re-installs and driver fixes, but it didn’t help. I just saw the bootloader for a short amount of time, but then the Arduino was gone. Someone in the LattePanda Forum suggested to reburn the bootloader, and it helped! Here is how I’ve done it:
What you need:
– The LattePanda, obviously
– An other Arduino, I used an Arduino Uno
– Some wire connectory
1. Connect the second Arduino via USB with your LattePanda
2. Create the following cable connections between the second Arduino and the LattePanda (use the 6-Pin group on the LattePanda!)
LattePanda  Second Arduino
GND         GND
RESET       D10
MOSI D16    D11
D14 MSG     D12
D15 SCK     D13
3. Open Arduino and go to File -> Examples -> Arduino ISP
4. Go to Tools -> Board and select the Board type of your Second Arduino (in my case Arduino/Genuino Uno) and select the proper port
5. Upload Sketch
6. Go to Tools -> Board and now Select “Arduino Leonardo”
7. Go to Tools -> Burn bootloader
8. Lean back a minute or so
9. The Arduino of your LattePanda should reboot and now be working again.
Hope this was useful. You may also like the sources which I used for finding all the stuff:
https://arduino-hannover.de/2014/05/03/kochbuch-leonardo-bootloader-flashen/ (German)

Leave a reply

Using post requests in WordPress

I recently created a simple form in PHP which acts as kind of contact form in order to send mails after a successfull request.
I run into trouble when submitting the form: I always got redirected to a 404 site, although the url itself was correct.

The sample looks like this:


// send mail


<form action=”” method=”post”>
<p><label>Name: </label><input name=”name” type=”text” /></p>
<p><label>E-Mail: </label><input name=”mail” type=”email” /></p>
<input type=”submit” name=”send” value=”Contact”</form>

I found out that the reason was that the field name “name” is reserved by wordpress. After renaming it to e.g. “name2” the 404 error was gone.

Leave a reply

Importing large SQL exports into mySQL

This solution is for a problem I run across while trying to import a sql-export file which was about 2 GB in size. phpMyAdmin usually fails when the filesizes get to big, and using the HTTP POST method is not a good idea for such huge amounts of data anyway. So I decided to go along with php.

  1. Create a folder on your webspace
  2. Upload the sql file to your webspace (e.g. via FTP)
  3. Create a php in the same folder
  4. Put the following content into it:

// Name of the file
$filename = ‘export.sql’;
// MySQL host
$mysql_host = ‘your.host.com’;
// MySQL username
$mysql_username = ‘db_user’;
// MySQL password
$mysql_password = ‘db_pass’;
// Database name
$mysql_database = ‘db_name’;

mysql_connect($mysql_host, $mysql_username, $mysql_password) or die(‘Error connecting to MySQL server: ‘ . mysql_error());
// Select database
mysql_select_db($mysql_database) or die(‘Error selecting MySQL database: ‘ . mysql_error());

// Temporary variable, used to store current query
$templine = ”;
// Get file handle
$file = fopen($filename,”r”);
// Loop through each line
while ($file && !feof($file))
// Skip it if it’s a comment
if (substr($line, 0, 2) == ‘–‘ || $line == ”)

// Add this line to the current segment
$templine .= $line;
// If it has a semicolon at the end, it’s the end of the query
if (substr(trim($line), -1, 1) == ‘;’)
// Perform the query
mysql_query($templine) or print(‘Error performing query \'<strong>’ . $templine . ‘\’: ‘ . mysql_error() . ‘<br /><br />’);
// Reset temp variable to empty
echo “added entry\n”;
$templine = ”;
echo “Tables imported successfully”;

Note that the file will loop through each line. Using file() or file_get_contents() will fail because you will get an out-of-memory error. Besides this seems to be slow, it’s still performing quite well even for large files.

Leave a reply

Delete old attachments from OSTicket

A problem I recently encountered was that the OSTicket mySQL Database get’s huge (more than 1 Gigabyte) if you receive a lot of mails with big attachments.

I decided to delete older attachment-data. Below is a php script you can put on your server inside a folder like “delete_attachment”. This folder must be at the location of your OSTicket installation.

include_once dirname(__FILE__).”/../main.inc.php”;
$res = db_query (‘DELETE FROM ost_file_chunk WHERE file_id IN

If you don’t want to create a php script, you can also run a sql query via phpMyAdmin:

DELETE FROM ost_file_chunk WHERE file_id IN (SELECT id FROM ost_file WHERE created < DATE_SUB(NOW(), INTERVAL 60 DAY)

Replace 60 with whatever number of days you want to keep attachments.