Showing posts with label how-to. Show all posts
Showing posts with label how-to. Show all posts

Tuesday, 14 April 2009

Advanced Tone-mapping with GIMP

Most compact photo-cameras cannot handle contrast scenes properly. Here a plugin for GIMP (GNU Image Manipulation Program - a popular open-source alternative for PhotoShop, available for Windows, Linux and Mac OS), called Advanced Tone Mapping comes to the rescue. The script processes a single image, unlike High Dynamic Range technique, which requires at least two shots, increasing its local contrast and reducing total one. In a plain language it makes dark parts of the image lighter and bright parts darker. Obviously, the picture should not be overexposed, because nothing can get any information from the white sky, as it is completely lost.

Let start with the example.



I took this photo at South Head, the Kaipara Harbour entrance, not far from Auckland, New Zealand. In order to preserve the sky I set up exposure compensation to -2/3, so the whole picture became too dark. The sand is dark indeed, as it contains black volcanic ash, but pieces of broken sandstone on the foreground should be same colour like the background cliff.

One disadvantage of the script is that it takes a while to process a picture and there is no preview available, so nobody can tell you what values should be set as the parameters (four ones in total). Thus the idea of the explained technique is to over-process the picture, then to reduce the effect to get the desired result. So I opened the picture in GIMP, clicked Filters - Enchance - Advanced Tone Mapping and set the parameters as follows:
  • Gauss. Blur: 10% - the default value
  • Opacity of blurred layer - 100 or near
  • Opacity of merged layer - 100 or near
  • Copies of merged layer - 3
The result is shown below.



I definitely got what I wanted, but the result is far from ideal. The colours are un-real, and halos are strong and clearly visible. This new image appeared as a second layer above the original image, and this is very handy, as what I have to do now is just to change some parameters of this new layer.

So I switched to the Channels, Paths, Undo, Layers - ... dialog and selected Layers tab. The new layer is called tmapd: with some numbers, it should be already selected. I changed the layer mode to Value (the last in the list) and adjusted its opacity until I considered the result as satisfactory; the final opacity value for this image was about 60%. This is the interactive process and the changes are reflected on the image (almost :) immediately.



As you can see the clouds became more impressive, the background is now brighter; there is still some halo above the forest, but it is not so obvious.

This technique increases the noise level, especially in brighter parts of the image. This is because they contain less information, higher local contrast means small variations of brightness becomes more visible; it usually affects the blue sky. One can try to improve this by applying another plugin - GREYCstoration to the resulting and flattened image.

Tuesday, 24 March 2009

EEE PC as Photo Frame - Slideshow selection dialogue

After your slide show is up and running you may want to add some improvements - the ability to create as many slideshows as you like and choose one as you clicked on the icon.



To make this possible our slideshow script should be able to:
  1. find slideshows located under some base folder
  2. display the list where we can choose one from
  3. pass our choice to the viewer program (qiv)
The resulting script is shown below:

#!/bin/sh
ssPath="/home/user/MMC-SD/partition1/DCIM/"
cd $ssPath
ssList=$(ls -dx *)
ssFolder=$(zenity --list --title="Choose Slideshow" --column="Folder" $ssList)
if [ -n "$ssFolder" ] ; then
xset s off -dpms
# mpg321 --random --quiet /home/user/MMC-SD/partition1/MISC/audio/*.mp3 &
qiv -sfmir -d 8 $ssPath$ssFolder/*
# killall mpg321
xset s on +dpms
fi
As you may have noticed I commented the commands related to background music.

To implement new features, mentioned above, I introduced three variables:
  • ssPath - my base folder, each its sub-folder is a slideshow (you must change its value to your actual location)
  • ssList - the list of all found slideshows
  • ssFolder - what I chose from ssList
Look at the picture below.



It shows a file manager, which displays my directory tree. The address bar shows my base folder - "/home/user/MMC-SD/partition1/DCIM/", this value is directly assigned to ssPath.
ssPath="/home/user/MMC-SD/partition1/DCIM/"
The folder DCIM contains only sub-folders, every one of them is a separate slideshow. The command
ls -dx *
lists them in a single row, and this is assigned to ssList:
ssList=$(ls -dx *)

Then I use the command zenity which displays a nice dialog, as shown on the first picture. The result (my choice) is assigned to ssFolder:
ssFolder=$(zenity --list --title="Choose Slideshow" --column="Folder" $ssList)
Zenity was installed on my computer by default, so I think it should be same on yours.

The next step is to make sure ssFolder is not empty, so the rest of the script is executed if the below command returned TRUE:
if [ -n "$ssFolder" ] ; then
The rest is pretty much similar to what I explained in the previous post. The only difference is this command:
qiv -sfmir -d 8 $ssPath$ssFolder/*
qiv should play all files in my selected folder ($ssFolder), attached to the full path (the base folder ssPath). You should avoid having non-image files in that folder, or you may try -n option, which tells qiv to filter files by their magic numbers instead of extensions.

Enjoy!

Friday, 20 February 2009

EEE PC as Photo Frame - adding music

It would be nice to add some background music while watching a slideshow (see my previous post about making a slideshow script). After playing with that script I ended up with the following version:
#!/bin/sh

xset s off -dpms
mpg321 --random --quiet /path/to/music/files/*.mp3 &
qiv -sfmir -d 8 /path/to/picture/files/*.JPG
killall mpg321
xset s on +dpms
You should obviously replace "/path/to/music/files/" and "/path/to/picture/files/" to your actual locations.

Below is the short explanation of the changes.
I noticed that after 20 minutes the screen went blank, although screen-saver feature was disabled. The command
xset q
revealed, that DPMS (Display Power Management Signaling) feature was enabled, so I changed the first command in the script as follows:
xset s off -dpms
to switch DPMS totally off. The last command re-enables this feature.

Using my Package Finder tool I found that my EEE PC had pre-installed command-line audio player, called mpg321. It appeared that this program was quite suitable for our purposes.
mpg321 --random --quiet /path/to/music/files/*.mp3 &
The above command launches mpg321 player and tells it to play all mp3 files in the given folder in random order; the --quiet option supresses unnecessary text output. The "&" at the end tells the OS not to wait for the player finished its work, but go to the next line of the script.

When we terminated qiv, playing the slideshow, we also have to stop music. The command
killall mpg321
does the trick.

That's all.

Sunday, 15 February 2009

Asus EEE PC 701 as Digital Photo Frame



Its quite easy to turn your EEE PC into digital photo frame. To make this possible one needs two things.
Firstly a program, which would present the photos in a full-screen slideshow mode.
Secondly the screen saver (or rather power saver) feature should be temporarily disabled, to avoid getting black screen after 5 mins of inactivity. Obviously the laptop must be powered from the mains.

After some googling I found the program, which I think fits quite well for slideshow. It's called qiv, Quick Image Viewer. Because EEE PC has a lot of software pre-installed, it worth to see, if this program is already on your computer or not.

1. Open the terminal (Ctrl+Alt+T) and type:
qiv --help
If you see a lot of output with explanations of possible options and available keys, you can skip the next step, otherwise you have to install it.

2. Type in the terminal:
sudo apt-get install qiv
The above command (apt-get) installs the mentioned package (qiv) into your computer, and requires administrative rights to perform this task (sudo).
If the above does not work, see this tutorial about Adding Additional Software Repositories
.
Unfortunately I am not sure what repository qiv came from.
Note: If you are in doubt what any terminal command is intended to, say "sudo" as above, type "man sudo", which will show manual pages for the given command; to scroll down use Space key, to terminate the manual press Ctrl+Z. Other possible ways are to type the command with -h or --help options, or find its description in the Internet with Google.

3. Put the pictures, you want to present, in a single folder. You may also wish to scale them down, to save some disk space. In my case the photos were exported (with scaling down to 800 pixels) from Picasa to
/home/user/MMC-SD/partition1/DCIM/Starred-Photos/
As you may guess the above string points to the folder, located on the 1GB SD card, which was earlier used with my digital camera. Now this card is an extra storage for EEE PC.

4. Again, in the terminal type the following (change my folder to the path to your picture location, and keep in mind that Linux commands are case-sensitive):
qiv -sfmir -d 8 /home/user/MMC-SD/partition1/DCIM/Starred-Photos/*.JPG
and see, what is going on. Ideally you should get your slideshow working. To terminate it, press ESC . If the above command does not work, first type "qiv --help", to be sure qiv is really installed, then check carefully your path to pictures.
Brief explanation the above command:
  • qiv - calls Quick Image Viewer
  • -sfmir - is actually five options; -s is for slideshow; -f is for full-screen mode; -m is for preserving images aspect ratio and zooming; -i is to disable status bar, and -r is for random order
  • -d 8 - means 8 secs delay between images; you may want to change this value
While watching the slideshow, you can use the following keys:
  • space - to get the next picture
  • esc - to terminate the slideshow
  • s - to pause/continue slideshow.
If you do nothing, the screen should go black after 5 minutes, and this is the next problem to solve.

There is no running screen-saver on EEE PC by default, but there are some low-level power saving options. One of them is an option in xorg.conf file, which tells to set the screen black, if there were no keyboard/mouse activity for 5 mins. To avoid this type the following command:
xset s off
and check you can watch your slideshow endlessly. If all the above works, we should now put it all together.

5. Open a text editor, to do it type in the terminal:
kate
6. Enter the following set of commands:
#!/bin/sh
xset s off
qiv -sfmir -d 8 /path/to/your/pictires/*.JPG
xset s on
In the above sample change the third line with your command from step 4. First line says it is the script, second switches blank screen off, third is actually your slideshow and last restores power saving settings.

7. Click File -> Save As.. and save this file as "slideshow.sh" (without quotes).

8. Close the text editor

9. Type in the terminal:
sudo chmod +x slideshow.sh

The above command makes your "slideshow.sh" file executable.

10. Type:
./slideshow.sh

and check that everything works.

11. Type:
sudo mv slideshow.sh /usr/local/bin/
This command moves your file from your home folder to a system folder for executable files, (not supplied by the OS vendor).

12. Type:
cd /usr/local/bin

This will change your current active folder and then type:
sudo chmod +x slideshow.sh
to make the file executable again.

13. Using Launcher Tools create a new launcher in your favourite folder, like shown in the picture:



That's all!

Enjoy, but avoid using it when the computer is on battery.

TODO: Add some music.

Saturday, 31 January 2009

Asus EEE PC as E-Book reader (option 2)

Browsing through the menu in Full Desktop Mode I noticed the presence of the installed E-Book reader application at
Launch -> Xandros -> Office -> E-book reader

The application called itself FBReader and proved to be quite useful for HTML and plain texts. Surely to get the most of it the program needs to be a little bit customized.



First, add it to the list of programs, available in Easy Mode. To do this I used the tool called Launcher Tools, so the procedure was straight-forward and a new launcher "Book Reader" appeared in my Favorites tab.

The following few simple steps will allow you to make reading books more comfortable.
  1. Launch FBReader and click Preferences button

  2. Switch to Scrolling tab, select Options for Large Scrolling and choose Scrolling Mode = No Overlapping
  3. Switch to Margins tab and set your preferred margins, my choice was:
    • Left and Right margins = 8
    • Top margin = 0
    • Bottom margin = 4

  4. And now the most important thing: switch to Keys tab
  5. Click on Action for Key field, press RightArrow key, located on the right bottom edge of the keyboard, and select Large Scroll Forward action for it
  6. Click on Action for Key field again, press LeftArrow key and choose Large Scroll Backward action, like this:

Click OK or Apply.
That's all.

After the above has done, you can simply scroll pages down and up with RightArrow and LeftArrow keys respectively. You can obviously set some other options, like fonts (Styles tab) and text alignment (Format tab).

Unfortunately, FBReader does not work well for me. The reason is that I read texts in Russian sometimes, which are formatted incorrectly by FBReader - it squeezes some spaces between words to none, so option 1 (see my previous post) is still useful for me. Hopefully once I will find the way to fix this.

Tuesday, 22 July 2008

Playing with HDRI

High Dynamic Range Images (HDRI - Wikipedia article) became very popular recently, and I also experimented with this technique. I don't personally like unrealistic pictures you can often see in the Internet, if you search for "HDR" or "HDRI", so I usually try to preserve natural look.

To make a HDR image one has to make at least two shots of the same scene with different exposure. Many cameras have "auto-bracketing" mode, what makes this part of work quite simple. My camera (Panasonic Lumix DMC-FZ5 - DPreview) can take three shots with maximum -1EV and +1EV exposure range from the base settings. Below is the cuts from three original photos I made with such auto-bracketing. The scene is Anchor Bay at Tawharanui Regional Park, some 80 km north from Auckland, New Zealand.



ISO: 80
Shutter speed: 1/500, 1/250, 1/125
Aperture: f/4.0
Focal length: 6.0 mm (36 mm for 35 mm film)
Metering mode: Matrix
Tripod and polarizing filter.

Polarizing filter reduced reflections from water surfaces and brightness of the sky.

I cut off a small piece from original photos, which includes both very bright (clouds) and darkest parts (black rocks) of the scene. The source files were in JPEG format, as this is the only format my camera allows for auto-bracketing mode.

I loaded all three files into Qtpfsgui (http://qtpfsgui.sourceforge.net/) and created a HDR image using default program settings. Saved the result as Tawharanui.hdr and clicked Tonemap the HDR. This is the most creative and time-consuming part of work with Qtpfsgui, and the goal is to get TWO tone-mapped LDR (8 bits per channel) images: one is as good as possible and another is produced by the Fattal algorithm to improve the first (thanks to Angela Lobefaro for her post to this blog). Qtpfsgui provides 8 different algorithms for tone-mapping; I found Drago, Durand and both Reinhard are mostly suitable for first, realistic looking image, while Fattal or Mantiuk are better for "impressionist" image, aimed to pop-up first one.

In this particular case the first image was made by Reinhard'05 with the following parameters:
pregamma: 1
brightness: -10
chromatic adaptation: 1.26
light adaptation: 0.5



The second image was by Fattal with:
pregamma: 1
alpha: 0.1
beta: 0.8
saturation:1
noise reduction: 0.04
These parameters are actually default ones, except noise reduction; this was carefully adjusted to keep as many details as possible.



Obviously, both images must have the same size and should be saved on the hard drive.

Then I launched GIMP (GNU Image Manipulation Program - http://www.gimp.org/) and opened both of the images here. First steps are simple: make the "Fattal" image active, Select All (Ctrl+A) and Copy (Ctrl+C). Then switch to another image and Paste (Ctrl+V); then go to Layer -> New Layer (Shift+Ctrl+N). Now go to Channels, Paths, Undo, Layers dialog and click on layers tab (Ctrl+L). You will see two layers; Pasted Layer which holds "Fattal" image, is active and actually hides another layer (Background with "Reinhard" image) beneath. Change its Mode to Overlay and shift Opacity down to 70...30 until you think your picture is good enough. That's all.

This is not the best way, because depending on your pictures you can get better results, playing with these settings - try other layer modes like Hard Light, Soft Light, Darken or Lighten Only, Burn or Value with different Opacity settings. You can also adjust your images before blending layers.

For my picture I performed the following actions:
1. Made Background layer invisible (clicked on the eye icon on the Layers dialog)
2. Went to Colors -> Levels and moved the central slider to 0.75; this made my "impressionist" layer darker and "richer"
3. Turned back on visibility of the Background layer, still keeping Pasted Layer as selected (active)
4. Changed layer mode to Value and adjusted opacity to about 0.50
5. Cropped
6. Saved As...