Linux Tips

Attach/detach a screen terminal

Screen is a window manager that allows you to manage a session on a remote machine. You can disconnect and reconnect from the terminal. First, start screen from the command line:

$ screen

Press CTRL-A followed by your desired command. Some common useful commands include. Here is a more extensive list:

? help
d detach (or ^D)
b break (or ^B)
c create
n next (or ^N)
p previous (or ^P)
" select a window from list
: goto screen command prompt

To connect to a previously disconnected session, reattach the screen:

$ screen -ls
$ screen -r

Reset network configuration

The command ifconfig allows you to view and configure your network interfaces. To view all of your network interfaces type:

$ ifconfig -a

To view the settings of the first network adapter:

$ ifconfig eth0

To reset your network interface for eth0:

$ ifconfig eth0 down
$ ifconfig eth0 up

Trimming borders from an image

The software Imagemagick is useful for removing the edges from an image that are the same as the corner pixels:

$ convert <filename> -trim +repage filename

Use the -fuzz option to remove edges that are nearly the same as the corner pixels.

Converting a .eps file to another format (.pdf or .png)

The software Imagemagick converts encapsulated postscript files to PNG or PDF format. The density of the PNG can be specified in dots per inch.

$ convert <eps_filename> <pdf_filname>
$ convert -density 200 <eps_filename> <png_filenm>

Encoding a video from sequential images

Use mencoder to create an AVI file from a series of images which is easily viewable on most platforms without additional codecs. Make certain the images are named sequentially. A simple (lower quality) encoding of a movie from JPG files at 25 frames per second:

$ mencoder "mf://*.jpg" -mf fps=25 -o output.avi -ovc lavc -lacvopts vcodec=msmpeg4v2

A higher quality video with 2-pass encoding from PNG files can be created by first determining the optimal bitrate: BITRATE = (50*25*W*H)/256. W and H are the image width and height. Encode the video in two passes with the follwing commands:

$ mencoder -ovc lavc -lavcopts vcodec=msmpeg4v2:vpass=1: "vbitrate=BITRATE:mbd=2:keyint=132:vqblur=1.0:cmp=2: subcmp=2:dia=2:mv0:last_pred=3" -mf type=png:fps=25 -nosound -o /dev/null mf://*.png'

$ mencoder -ovc lavc -lavcopts vcodec=msmpeg4v2:vpass=2: "vbitrate=BITRATE:mbd=2:keyint=132:vqblur=1.0:cmp=2: subcmp=2:dia=2:mv0:last_pred=3" -mf type=png:fps=25 -nosound -o output.avi mf://*.png

Extract video frames from a movie file

The software mplayer can extract frames from a movie and write them as image files:

$ mplayer -vo <filetype> output.avi Where valid filetypes include: png, jpg, pnm.

Matlab Tips

Removing the gray border from a figure

To make a Matlab axis expand to fill an entire figure so the gray border is removed:

>> set(gca, 'Position', [0 0 1 1]);

For an image, you can call imshow with the following option:

>> imshow(<image>, 'Border', 'tight');

Alternatively, change the color of the border to white

>> set(gcf, 'Color', [1 1 1]);

Print/export a figure to an image file

When printing a Matlab figure to an image file, you may specify the file type, the resolution (in dots per inch) and the renderer to be used (-painters is a vectorial renderer, -opengl is an opengl renderer, and -zbuffer is a bitmap renderer). Use opengl or zbuffer to preserve transparency. To print a file to a PNG with 150 dpi, use the following command:

>> print -dpng -zbuffer -r150 <filename>

Change -dpng according to the filetype you wish to export to:

-deps EPS file
-dpng PNG file
-djpeg JPG file
-dtiff TIFF file
-dbitmap Windows Bitmap

For further information on printing and exporting see the Mathworks resource.

kevin smith

Kevin Smith
Assistant Professor
School of Computer Science and Communication

Email: ksmith (at)

Science for Life Laboratory
KTH Royal Institute of Technology
School of Computer Science and Communication
Box 1031
SE-17121 Solna

Phone:+46 8 790 64 37

Valid HTML 4.01 Strict