Sunday, 27 December 2009

Wand-mode - image viewer

Wand-mode is the special mode to view and edit images under SXEmacs. Wand-mode is based on ImageMagick API therefore it can perform action usually done by programs such as convert(1), display(1) etc. Wand-mode supports all the formats handled by ImageMagick; there are over 100 formats including PDF, EPS, etc.

Getting started with Wand-mode

Using M-x Wand-display RET /path/to/image.jpg RET we will get something like:

Wand-display sample

To get file info we press i:

Wand-display identify

Now let us enhance this image a little. We want to remove noise and decrease contrast a little. Use o despeckle RET and then o contrast RET decrease RET. Don't worry, completion will work everywhere. We'll get the result:

Wand-display edit

Viewing image directories

Wand-mode has simple yet very handy navigation possibilities to view images. Open any file with Wand-display, if there any other image files (supported by ImageMagick) in the directory, then you can open them using next keys:

  • Space - Next image
  • BackSpace - Previous image
  • M-< - Very first image in the directory (in alphabet order)
  • M-> - Last image in the directory

Pages navigation

When viewing multi-page images such as PDF, EPS, MPEG, etc you can navigate across the pages with next keystrokes:

  • PgDown - Next page
  • PgUp - Previous page
  • Home - Jump to the first page
  • End - Last page
  • g or M-g - Select the page. You can either pass page number via universal argument (C-u) or type it interactively.

Of course Wand-mode is not xpdf or gv, however it is pretty handle to skim over the document or for picking and saving particular page from book or video file.

If you set Wand-mode-show-fileinfo variable to non-nil value, then information about current page and total number of pages will be displayed.

Also note that any operation you apply, applies only to current page and not to whole bunch of pages in the image.

Wand-mode Menu

Wand-mode has nice menu (resembling display(1) menu) to work with images:

Wand-display menu

You can reach menu either from menubar (if enabled), or using right button on your mouse. All commands available through the keyboard are available via menu and vice versa.

Customizing Wand-mode

Wand-mode has few parameters to change it's behavior. Use M-x customize-group RET Wand-mode RET to change them. Here is a little description of most want-to-customize parameters:

  • Wand-mode-zoom-factor - Number (default: 2)

    As you can notice from it's name, this is the coefficient for + (zoom-in) and - (zoom-out) commands.

  • Wand-mode-show-fileinfo - Boolean (default: t)

    When non-nil, then display some information about the file, for more info, as was already noticed above, use i command.

  • Wand-mode-show-operations - Boolean (default: t)

    When non-nil, then display image operations stack. You can use undo/redo commands even if Wand-mode-show-operations is nil.

  • Wand-mode-auto-fit - Boolean (default: t)

    When non-nil, then scale image to fit it into SXEmacs window.

  • Wand-mode-auto-rotate - Boolean (default: t)

    When non-nil, then rotate image in case it has orientation info inside (modern photo cameras can detect own space orientation and store this info inside photos). If rotation was done, then rotation operation will be placed into image operations stack. Very handy.

Changing image and saving

Use next keys to operate on images:

  • l - Rotate by 90° counterclockwise (like to the left)
  • r - Rotate by 90° clockwise (like to the right)
  • + - Zoom in the image according to Wand-mode-zoom-factor
  • - - Zoom out the image according to Wand-mode-zoom-factor
  • o - General operational key. Inquiries for the operation to do and for its parameters. Supports completion.

You can apply operations one by other, like we already did. All operations are stored in image operations stack, so you can undo/redo any using standard C-/ (or C-_) and C-x C-/ keys. Also you can re-apply last operation with C-. (or C-x M-:) key. To abolish all operations just reload image with C-r.

Now when new image is read, we can save it to the disk. There are two commands to do it:


ATTENTION: Saving to non-graphical formats such as HTML, TXT, etc, may lead to core dump. This is ImageMagick bug, but unfortunately ImageMagick developers not quite sociable guys, so only god knows when this will be fixed.

  • C-x C-w - You'll be asked about file format to use and filename.
  • C-x C-s - Simple way to save. You'll be queried for filename only. And file format will be automatically defined according to the extension of the filename you provided.

Operating on image region

Wand-display region

Using left mouse you can select image region, for example Sarah's hand. If Wand-mode-show-fileinfo is set to non-nil, then region's geometry (coordinates and size) will be displayed, sometimes this useful. When region is active then operations that can be applied to region, such as contrast, despeckle, etc will be applied to region only. There are few commands that are applicable only to regions:

  • c - crop the region and cut everything else
  • o chop RET - chop the region and assemble everything else together
  • Red eye reduction

After applying operation to region, region deactivates. To activate last region use C-M-z command.

Red eye reduction

Most important thing in the red eye reduction is correctly selected region. Best way to select region so all red part is in the centre of the region and there is a little free space from red part to the edges of the region. Here is an example of well formed region:

Wand-display red eye good region

And here is not so well selected region, however red eye reduction algorithm will handle it in this case, but in more complicated cases it might produce some artifacts:

Wand-display red eye bad region

After selecting the region simple press . or choose menu item Wand→Region→Remove red eye.

Red eye reduction algorithm used in Wand-mode is straightforward and can't compete with algorithms implemented in professional red eye reduction tools, however it demonstrates pretty good and usable results. Here is the comparison:

Wand-display red eyes sxemacs vs prof

Operations table

To finalize the article, here is brief overview of operations you can do on images using Wand-mode. Notice that operations which does not changes image size can be applied to region without problems:

Width: 400
Height: 200
Degrees: 120°
Add Noise
Noise type: Poisson
Edge detect
Radius: 1.0
Radius: 1.0
Sigma: 2.0
Gaussian Blur
Radius: 1.0
Sigma: 2.0
Radial Blur
Radius: 3.0
Reduce Noise
Radius: 1.0
Sigma: 2.0
Radius: 1.0
Type: increase
Type: decrease
Radius: 1.0
Sigma: 2.0
Radius: 0.4
Radius: -0.4
Oil Paint
Radius: 2.0
Sepia Tone
Threshold: 85%
Threshold: 50%
Angle: 90°
Black/White: 10
Amplitude: 2
Wave length: 10

No comments:

Post a Comment