Tips & Tricks

Tips from Kevin Smith

linux tips

how to attach and detach a terminal

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

>> screen

By pressing CTRL-A you can send commands to screen. Some common useful commands include:

? help

d detach (or ^D)

b break (or ^B)

c create

n next (or ^N)

p previous (or ^P)

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

>> screen -r

how to reset and view your 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

how to trim borders from an image

Imagemagick can remove 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.

how to convert a .eps file to .pdf or .png

Imagemagick can easily convert an encapsulated postscript file 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>

how to encode a video from image frames

Use mencoder to create an AVI file from a series of images which is easily viewable on all platforms without forcing people to download annoying codecs. Make certain the images are named sequentially. The simple way to encode a movie from JPG files at 25 frames per second:

>> mencoder "mf://*.jpg" -mf fps=25 -o output.avi -ovc lavc

-lacvopts vcodec=msmpeg4v2

To make a higher quality video with 2-pass encoding from PNG files, first figure out your optimal bitrate, BITRATE = (50*25*width*height)/256. Now, type 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

how to extract video frames from a movie file

Use mplayer to extract the frames from a movie file (types: png, jpg, pnm):

>> mplayer -vo <filetype> output.avi

matlab tips

how to get rid of the gray border from a figure

To make a Matlab axis expand to fill an entire figure window 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');

how to 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