eXTReMe Tracker
Sep 192012
 
Simple image compression algorithm using plain FFT computation

FFT2 based image compression

Test code to generate a circular mask that removes the low frequency components from an image.

Step through radius to get the percentage compression.

IM=imread('images_01.jpg');IM=IM(:,:,2); %Select a channel
%
cx=size(IM,2)/2; cy=size(IM,1)/2;
ix=size(IM,2);iy=size(IM,1);r=833;
[x,y]=meshgrid(-(cx-1):(ix-cx),-(cy-1):(iy-cy));
c_mask=((x.^2+y.^2)>r^2);
%
filtIM = fft2(IM).*c_mask;
filtIM = ifft2(filtIM);
IM2=abs(double(IM)-abs(filtIM));
%
x=size(IM,1)*size(IM,2); y=size(find(c_mask==1)); y=y(1);
res=y/x*100;
%
figure(1); 
subplot(2,2,1); imshow(c_mask);
subplot(2,2,2); imagesc(IM2); axis image; axis off;
subplot(2,2,3); imshow(IM); title('Origianl image');
subplot(2,2,4); imagesc(abs(filtIM)); axis image; axis off;
title(sprintf('Percent original: %0.2f',res));
Sep 102012
 

Submitting processing job to a queue

jobs=$scratch/jobs
sub=/lustre/scratch/subjects
# mkdir $jobs
# cp -r $HOME/subjects $scratch/
function run-recon-all() {
cd $scratch
#create submit script for each patient in the subjects directory
do
unset SUBJECTS_DIR
SUBJECTS_DIR=$sub
export SUBJECTS_DIR
cat > $jobs/recon-all-$patient.sh <<EOF
#!/bin/bash
#$ -S /bin/bash
#$ -cwd
#$ -N recon-all-$patient
# Set the hard and soft run time limits
#$ -l h_rt=30:00:00,s_rt=29:55:00,vf=2.5G
# set up FreeSurfer environment variables
# mri_convert -oi -os $SUBJECTS_DIR/$patient $SUBJECTS_DIR/$patient.mgz
recon-all -s $patient -all
EOF
done
#submit job script for each patient in the jobs directory to the cluster
pushd $jobs
for script in `ls -1`
do
echo "submitting job $script"
qsub $script
done
popd
}
run-recon-all
Aug 082012
 

Here’s a nifty little script I found.

You need to run it within the directory containing the wma files:

#!/bin/bash

current_directory=$( pwd )

#remove spaces
for i in *.wma; do mv "$i" `echo $i | tr ' ' '_'`; done

#Rip with Mplayer / encode with LAME
for i in *.wma ; do mplayer -vo null -vc dummy -af resample=44100 -ao pcm -ao pcm:waveheader $i && lame -m s audiodump.wav -o $i; done

#convert file names
for i in *.wma; do mv "$i" "`basename "$i" .wma`.mp3"; done

rm audiodump.wav

If you aren’t happy with underscores and want your spaces back, run this on the command line:

for i in `ls *.mp3`; do p=`echo $i | tr '_'  ' '`; mv $i "$p"; done

They will be in the proper format now, and google music compatible.

Jul 202012
 

In the newer versions of Linux, an open source driver is usually installed by default to run the graphic cards. However this driver can sometimes be absolutely messy, and it is essential to remove the Nouveau driver and install the binary driver from Nvidia.

However, if after you reboot into the service mode from grub menu, and try to install the NVIDIA-Linux-x86_64-xxx.run driver in the init 3 level, the program will kick you out saying that the Nouveau driver is still in use.

The way to disable the Nouveau drivers from kernel is to boot in the service mode and run the following commands:

echo options nouveau modeset=0 | sudo tee -a /etc/modprobe.d/nouveau-kms.conf
 update-initramfs -u

Once its done reconfiguring the kernel, you will need to reboot, and again get to service mode.

After that, get into init 3 mode, and install the NVIDIA-Linux-x86-64.xxx.run script. The installation should be successful at this point.

May 292012
 

Replace your ~/.vnc/xstartup file with the following content:

#!/bin/sh
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
startxfce4
May 092012
 

If you are going for a complete reinstall of OS and you need to get a list of packages you have at present, so that you can reinstall them after you have installed Linux from scratch, run the following:

#!/bin/bash
sudo dpkg --get-selections | awk '{ ORS=" "; print $1; }' > packagelist.txt

This saves the everything to packagelist.txt. Mind blown!

 

Mar 052012
 

Here’s a quick chart I made for quick look-up for conversion between Celsius and Fahrenheit scale.

[°C] =  5/9 × ([°F] – 32)

A graphical lookup for conversion between Fahrenheit and Celsius

A graphical look-up for conversion between Fahrenheit and Celsius (click to view full size)

The bold marking are at multiples of 100 degree Celsius.

Mar 042012
 

As a prank project we installed a webcam at the front desk of the our office suite, and plugged it into a Linux machine. Then we had a decommissioned 14 inch monitor face the person who was just walking in so that he/she could see themselves in the monitor with absolute clarity. The text beneath said “Smile for the camera”.

This was an one line implementation with VLC. The terminal command for this would be:

vlc --sub-filter "marq{marquee=\$t \$\smile for the camera,color=16776960,position=8}" v4l2:////dev/video0

A false sense of security with some false video surveillance. Of course you can save the stream and turn it into real surveillance.

 

Dec 282011
 

To monitor the instantaneous network usage, execute the ifstat command in bash. You may need to acquire it from a repository if you don’t have it already.

sudo apt-get install ifstat

To display usage on eth0, with a 5 second delay, just once:

ifstat -i eth0 5 1

You can change the number of seconds, and the number of times you want the output displayed. If you don’t specify the count, it will go on forever until you ctrl-c out of it.

So here is a script that displays the download rates in MB/s and upload rates in KB/s every 5 seconds until you hit ctrl-c.

while :
do
# Press ctrl-c to exit
x=`ifstat -i eth0 5 1 | tail -1 | tr '\t' ' '`;  #tail -1 takes the DL and UL speeds in KB/S
x1=`echo $x | cut -d ' ' -f1`; x2=`echo $x | cut -d ' ' -f2`;
x1=$(echo "scale=3; $x1/1024" | bc); # Convert DL rate to MB/S
printf "D: %0.3f MB/s\t U: %0.3f KB/s\n" "$x1" "$x2"
done
Dec 272011
 

One mild inconvenience while using Linux Mint is the default Google search in Firefox search bar. The plain ol’ google search is reformatted, and wrapped within a Linux Mint flavoured wrapper. Its not the end of the world – you can always go to google.com and then search the same word or phrase. However, many people have gotten into the habit of performing their search using the search bar on top left corner within Firefox. Getting a Linux Mint wrapper around just doesn’t look right.

Someone figured out that the google.xml file used in the search plugin was modified in the Mint distribution to create give the modified results. In order to get the original google results, just type in the following command lines:

cd /usr/share/linuxmint/common/artwork/firefox/
sudo wget http://mxr.mozilla.org/firefox/source/browser/locales/en-US/searchplugins/google.xml?raw=1 -O google.xml.fixed
sudo mv google.xml google.xml.orig
sudo mv google.xml.fixed google.xml
sudo cp google.xml /usr/lib/firefox-addons/searchplugins/en-US/google.xml

Restarting Firefox (maybe a few times) is required to get the google results in the plain old familiar format.

The above code was obtained from: Change Back Google Search in Linux Mint

Dec 062011
 

The newer releases of Ubuntu and Linux Mint have started getting stuck during LiveCD installation or after distribution/kernel upgrade.  Usually the point where it gets stagnant is when it reaches this line:

kernel_thread_helper+0x7/0x10

Nothing happens past that point. A solution or a workaround to this is to insert the nolapic acpi=off switch in the grub boot line. There are 3 ways to do this:

1: If you are starting a fresh install from a CD and the installation pauses at the kernel_thread_helper line, you need to restart your computer.

When you boot from your installation CD, choose F6 before you continue trying out the LiveCD. This give you boot option at the bottom of your screen.

At the very end of the line add nolapic acpi=off and hit enter to continue booting from LiveCD. In most cases this should work.

2. The same problem may arise when you do a distribution upgrade or even a kernel upgrade. In that case you need to change your grub.cfg file. Follow these steps:

sudo nano /boot/grub/grub.cfg

Enter your sudo password and it will bring you to your grub menu configuration.

Look for the section that read similar to this:

menuentry 'Ubuntu, with Linux 2.6.38-11-generic' --class ubuntu --class gnu-linux --class gnu --class os {
 recordfail
 set gfxpayload=$linux_gfx_mode
 insmod part_msdos
 insmod ext2
 set root='(hd0,msdos6)'
 search --no-floppy --fs-uuid --set=root 337e2841-fc82-61b3-84be-5a9c71ae43b8
  linux   /boot/vmlinuz-2.6.38-11-generic root=UUID=337e2841-fc82-61b3-84be-5a9c71ae43b8 ro quiet splash vt.handoff=7
 initrd  /boot/initrd.img-2.6.38-11-generic
 }

You want to change the line that I have identified above to read:

linux   /boot/vmlinuz-2.6.38-11-generic root=UUID=337e2841-fc82-61b3-84be-5a9c71ae43b8 ro quiet splash vt.handoff=7 nolapic acpi=off

After adding these switches to the boot menu option, press ctrl-X, then save and exit.

This is for a permanent change if you can boot using an older kernel.

3: If you cannot login to an older kernel or recovery mode because of the kernel_thread_helper error,  you have to press “e” (without the quotation marks)  to edit the boot options when you get the grub menu.

For the kernel you want to use, edit the end of the line that reads

linux   /boot/vmlinuz-2.6.38-11-generic root=UUID=337e2841-fc82-61b3-84be-5a9c71ae43b8 ro quiet splash vt.handoff=7

to

linux   /boot/vmlinuz-2.6.38-11-generic root=UUID=337e2841-fc82-61b3-84be-5a9c71ae43b8 ro quiet splash vt.handoff=7 nolapic acpi=off

Press Enter and you should be able to boot.

Nov 162011
 

On most Linux/Unix based systems, you can save your Matlab figure as a postscript instead of saving it as a png or jpg. One advantage of saving figures in this manner is that you can save multiple images as separate pages on that .ps document, whereas with png/jpg you have to save each image as a separate file.

To print the current image to postscript, all you need to run is:

print(‘-dpsc2′,’filename’);

To have multiple images appended within the postscript document, you need to use the -append switch.

print(‘-dpsc2′, ‘-append’, ‘filename’);

Your output postscript will have the name filename.ps

To convert the postscripts to pdf format, just run the ps2pdf command in the terminal window:

ps2fpdf filename.ps

The output of this would be filename.pdf

And you’re done.

Nov 102011
 

In order to install l1-SPIRiT Compressed Sensing Parallel MRI, we need to have a couple of programs installed – fftw3, lbz2.  Usually you encounter the following error while running build routine in Matlab.

/usr/bin/ld: cannot find -lbz2
collect2: ld returned 1 exit status

sudo apt-get install libbz2-dev

After installing libbz2-dev this error is corrected.