# negate
$ convert black-white.png -negate white-black.png
# rotate
$ convert upside-down.png -rotate 180 rightside-up.png
# resize
$ convert img.gif -resize 64x64 resized_img.gif
#convert to grayscale
$ convert -type Grayscale color.jpg gray.jpg
# find the differences between two images
$ composite img1.jpg img2.jpg -compose difference diff.jpg
# compare images using a metric (can be mse, psnr and more)
$ compare -verbose -metric mse 1.jpg 2.jpg difference.png
# compose two images together using a mask (stencil)
$ convert -size 512x256 tile:img.jpg tile:img2.jpg mask.jpg -composite result.jpg
Wednesday, June 5, 2013
Thursday, May 9, 2013
Keep command running after logging out
Use nohup to keep a command running after you exit the shell. Useful for running stuff on remote machines without having to be logged in.
- Login to a machine
- nohup command &
- Logout, command keeps running
Labels:
Linux
Tuesday, April 23, 2013
Multiple binaries in a single Eclipse CDT project
Sometimes it is convenient to have a single Eclipse project that produces multiple executables. An example is a set of tools that share some base code like a set of image manipulation tools that share some common image loading / saving code. In a situation like this, the source code has multiple source files that contain a main() function. The standard way to do this is to create a makefile eclipse project and edit the makefile so that you have a target for each executable:
binary_1: main_1.cpp shared_code.cpp
gcc -o $@ $^
binary_2: main_2.cpp shared_code.cpp
gcc -o $@ $^
If for some reason you want to use a managed eclipse project (where the makefile is automatically generated) do the following:
- Create a managed project (File > New C++ Project > Executable)
- Add the source code containing multiple main() functions
- Go to Project > Properties > C/C++ Build > Manage Configurations...
- Make a build configuration for each executable and name it appropriately (you can clone existing configurations like Debug and Release).
- From the project explorer, right click on each source file that contains a main() function > Resource Configurations > Exclude from Build and exclude all build configurations except the one that builds the executable with this main() function
- All other code is included in all build configurations by default. You may need to change this depending on your application.
- You can now build an executable for each main function by going to Project > Build Configurations > Set Active , Project > Build Project
- Build all binaries (as explained above)
- Go to Run > Debug Configurations.
- Create a configuration for each binary
- For each configuration set the correct Build Configuration and C/C++ Application (this is the binary).
- Use Search Project... to locate the binaries easily
Labels:
Eclipse
Thursday, April 11, 2013
Pipe to clipboard
Copy the output of a command into clipboard:
echo adafasdfa | xclip
Useful for pasting command line output into text editors, spreadsheets etc.
xclip -o | grep name
Useful for pasting large selections (etc from a browser). Equivalent to middle clicking the terminal (but less messy).
Labels:
Linux
Wednesday, April 10, 2013
Compile using pkg-config
pkg-config makes it easier to compile your source when you need to link libraries. For example, building a Qt application that has OpenGL support requires the following build command:
g++ source.cpp -DQT_SHARED -I/usr/include/qt4 -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4/QtGui -lQtOpenGL -lQtGui -lQtCore
With pkg-config that becomes:
g++ source.cpp `pkg-config --libs --cflags QtCore QtOpenGL `
Note the use of back-quotes `` to do in-line substitution.
pkg-config can be integrated into eclipse through a pluggin and is also supported by qmake. Just add the following to your .pro file:
CONFIG += link_pkgconfig
PKGCONFIG += name_of_library
Labels:
Linux
Monday, April 8, 2013
Make an image montage using ImageMagick
The following makes a 1x10 vertical montage of all .png images in the current folder. Before adding to the montage, images are cropped.
$ montage -geometry +0+0 -tile 1x10 -crop 170x70+115+125 *png montage.jpg
-geometry controls the border arround each sub-image in the montage. +0+0 means no border.
How to decode the crop string "170x70+115+125" :
170x70: new size of the cropped image
+115+125: Pixel (0,0) of the cropped image will be pixel (115,125) of the old one. Pixel (170,70) of the cropped image is pixel (170+115, 70+125) of the old one.
$ montage -geometry +0+0 -tile 1x10 -crop 170x70+115+125 *png montage.jpg
-geometry controls the border arround each sub-image in the montage. +0+0 means no border.
How to decode the crop string "170x70+115+125" :
170x70: new size of the cropped image
+115+125: Pixel (0,0) of the cropped image will be pixel (115,125) of the old one. Pixel (170,70) of the cropped image is pixel (170+115, 70+125) of the old one.
Labels:
Imagemagick
Convert HDR files to EXR and tonemap using pfstools
Convert all .hdr files to .exr using pfstools. This will replace the hdr extension to exr.
$ for img in *.hdr; do pfsin ${img} | pfsout ${img%%.hdr}.exr; done
Similarly, tonemap multiple HDR files using a variety of tonemapping operations:
$ for img in *.exr; do pfsin ${img} | pfstmo_mantiuk08|pfsout ${img%%.exr}.ppm; done
pfstmo_mantiuk08 is one of many available tonemap operations available in pfstools.
$ for img in *.hdr; do pfsin ${img} | pfsout ${img%%.hdr}.exr; done
Similarly, tonemap multiple HDR files using a variety of tonemapping operations:
$ for img in *.exr; do pfsin ${img} | pfstmo_mantiuk08|pfsout ${img%%.exr}.ppm; done
pfstmo_mantiuk08 is one of many available tonemap operations available in pfstools.
Labels:
HDR
Mounting remote folders using ssh and SAMBA
Two ways to mount your remote folders. Use sshfs over unreliable network. Get uid, gid by running id on linux.
mount -t cifs //samba_server/folder ~/yoho/ -o user=username,domain=COMPANY,uid=xxxx'
This will mount remote /folder to local folder ~/yoho.
sshfs -o workaround=rename -o reconnect -o idmap=user -o uid=xxxx -o gid=xxxx -o allow_other username@computer_with_ssh_access.company.com: ~/yuhu/
This will mount the home folder of user username at local folder ~/yuhu.
Labels:
Linux
Record webcam video
vlc v4l2:// :v4l2-dev=/dev/video0 :v4l2-width=320 :v4l2-height=240 --sout '#transcode{vcodec=mp4v,vb=3072,scale=1,acodec=mpga,ab=192,channels=2}:duplicate{dst=display,dst=std{access=file,mux=mp4,dst="/tmp/test.mpg"}}'
Webcam is typically /dev/video0 in linux
Webcam is typically /dev/video0 in linux
Grab video frames using VLC
The following grabs every fifth frame starting from second 0:20 and ending on 0:30 (10 seconds). Frames are saved in ./out/ . The number of frames captured depends on the number of frames per second of the video.
vlc video.avi --video-filter=scene --vout=dummy --start-time=20 --stop-time=30 --scene-ratio=5 --scene-prefix=frame --scene-path=./out vlc://quit
vlc video.avi --video-filter=scene --vout=dummy --start-time=20 --stop-time=30 --scene-ratio=5 --scene-prefix=frame --scene-path=./out vlc://quit
How to install pfstools Matlab support (HDR, EXR)
Pfstools is a set of command line programs for reading, writing and manipulating high-dynamic range (HDR) images and video frames. This is how to install for Matlab:
- Get pfstools http://pfstools.sourceforge.net/
- ../configure --prefix=$HOME/local --with-mex=/path/to/matlab/bin/mex (this installs in home folder)
- make
- make install
- From Matlab, File, Set Path, set it to $HOME/local//share/pfstools/pfstools_matlab/
Use --prefix=/path/ to istall to custom path. By default it installs to /usr/local/
Note: Most linux distros have a pfstools package. if you don't need Matlab support install that instead.
Note: Most linux distros have a pfstools package. if you don't need Matlab support install that instead.
Subscribe to:
Posts (Atom)