Sunday, December 02, 2007

Python Imaging Library - not working with 16 bit images

Python Imaging Library works well with 8-bit images, however it has problem with 16-bit images. As an example I wrote a script that flops tiff images horizontally. One image is 8-bit and the second image is 16-bit:

#!/usr/bin/env python
Convert tif images from Ludvig 2008.

This scripts take all tifs in input dir, and changes
tif files into tiff. Additionali it takes
right knee x-rays and flips them horizontally,
to have all x-ray in the same format.

#from myUtil import *
import re
import os
import Image
import Tkinter, tkFileDialog, os.path
from scipy import *

def flip_horizontally(inDir,inFile,outFile=None):
im =
out = im.transpose(Image.FLIP_LEFT_RIGHT)
if outFile is None: outFile=inFile

def main():
print inDir
for f in files:
if f.find('tiff')==-1: continue
if f.find('test')==-1: continue
print f

def myGetDir(indir='./',putTitle='Select dir'):
"""Get one dir name"""
root = Tkinter.Tk()
if len(dirr)==0: exit(1)
return dirr+'/'

if __name__ == '__main__':

The result of the above code is:

It is clearly seen that flopping 16-bit image gives wrong results.

Friday, November 16, 2007

Matlab: Easter egg - spy

In Matlab, spy(S) function plots the sparsity pattern of the matrix S. But if you run spy without any arguments you get:
Interesting, isn't it:-)

Monday, August 27, 2007

Monday, July 23, 2007

PSNR (Peak Signal-to-Noise Ratio)

Compressing an image is significantly different than compressing raw binary data. Of course, general purpose compression programs can be used to compress images, but the result is less than optimal. This is because images have certain statistical properties which can be exploited by encoders specifically designed for them. Also, some of the finer details in the image can be sacrificed for the sake of saving a little more bandwidth or storage space. This also means that lossy compression techniques can be used in this area.

Lossless compression involves with compressing data which, when decompressed, will be an exact replica of the original data. This is the case when binary data such as executables, documents etc. are compressed. They need to be exactly reproduced when decompressed. On the other hand, images (and music too) need not be reproduced 'exactly'. An approximation of the original image is enough for most purposes, as long as the error between the original and the compressed image is tolerable.

Error Metrics

Two of the error metrics used to compare the various image compression techniques are the Mean Square Error (MSE) and the Peak Signal to Noise Ratio (PSNR). The MSE is the cumulative squared error between the compressed and the original image, whereas PSNR is a measure of the peak error. The mathematical formulas for the two are


PSNR = 20 * log10 (255 / sqrt(MSE))

where I(x,y) is the original image, I'(x,y) is the approximated version (which is actually the decompressed image) and M,N are the dimensions of the images. A lower value for MSE means lesser error, and as seen from the inverse relation between the MSE and PSNR, this translates to a high value of PSNR. Logically, a higher value of PSNR is good because it means that the ratio of Signal to Noise is higher. Here, the 'signal' is the original image, and the 'noise' is the error in reconstruction. So, if you find a compression scheme having a lower MSE (and a high PSNR), you can recognize that it is a better one.

Monday, June 25, 2007

Matlab: Mandelbrot set

Recently I read article on Free Software Magazine titled Generating cool fractals. I was very pleased to find source code for generation of Mandelbrot set.
function mandelFrac
% MATLAB and Octave code to generate
%a Mandelbrot fractal

% Number of points in side of image and
% number of iterations in the Mandelbrot
% fractal calculation
% Generating z = 0 (real and
% imaginary part)
% Generating the constant k (real and
% imaginary part)

% Iterating
for j=1:niter
% Calculating q = z*z + k in complex space
% q is a temporary variable to store the result
% Assigning the q values to z constraining between
% -5 and 5 to avoid numerical divergences
qgtfive= find(qRe > 5.);

% Lines below this one are commented out when making
% the benchmark.

% Generating plot
% Generating the image to plot
ima=log( sqrt(zRe.*zRe+zIm.*zIm) + 1);
% Plotting the image

Sunday, June 24, 2007

Lenne picture

The original photo of famous Lenna picture which is found in many papers and books conserning image processing:-)

Sunday, June 17, 2007

Ruby: Tk, select directory

Just quick code for selecting input/output directory#!/usr/bin/env ruby
require 'tk'
puts bdir

Below an example that takes a directory and lists all txt files that contain string '_data' in their name. Than contents of each such file is copied to one output file ('allData.txt'):#!/usr/bin/env ruby
require 'tk'


fout= open('allData.txt', 'w')

Dir.foreach(bdir) { |x|
next if x !~ /_data/
fpath=bdir+'/'+x {|l| fout << l}

Thursday, June 14, 2007

Excel: Visual Basic; mean value

Simple code in Microsoft VBA as a function in Excel. This function takes a range (x) and calculates mean value of the number lower than 0.
Function mymeanLr(x)
n = x.Count
ReDim xx(n + 1)
Dim ind As Integer
ind = 0
For i = 1 To n
If x(i) < 0 Then
xx(i - 1) = x(i)
ind = ind + 1
End If
Next i
mymeanLr = WorksheetFunction.Average(xx)
End Function

Monday, June 11, 2007

bash: use sed and awk to calculate an awarage value in the file

FD=`cat $1 | sed -e 's/^[0-9.]*//g' -e 's/^\t//g' -e 's/^M$//g' \
| awk '{for (i=1; i<=NF; i++) s=s+$i}; END{print s/9/12}'`
echo $1 $FD

The script calculates avarage of values in a txt without values from the first column.
Example txt file:0 2.7792 2.7876 2.8023 2.8248 2.8413 2.8551 2.8679 2.8593 2.8537
18.281 2.7619 2.7723 2.7864 2.7888 2.8105 2.8314 2.8697 2.8695 2.8615
26.719 2.749 2.7464 2.7622 2.7811 2.8145 2.8276 2.8359 2.8438 2.8482
45 2.7596 2.7601 2.7614 2.779 2.803 2.803 2.8207 2.8391 2.8374
63.281 2.778 2.7809 2.8013 2.8071 2.8408 2.8423 2.8478 2.8514 2.826
71.719 2.7871 2.7927 2.8171 2.819 2.8366 2.8581 2.876 2.8826 2.8648
90 2.8007 2.8038 2.8219 2.8371 2.851 2.8628 2.8683 2.879 2.8719
108.28 2.781 2.7835 2.7901 2.7982 2.8214 2.8314 2.8488 2.852 2.8416
116.72 2.7731 2.7749 2.7784 2.7852 2.8077 2.8155 2.8226 2.8274 2.832
135 2.7744 2.7826 2.7854 2.7998 2.8153 2.8154 2.8358 2.8627 2.8775
153.28 2.7866 2.8011 2.8079 2.8253 2.8517 2.862 2.8727 2.8728 2.8644
161.72 2.7906 2.8071 2.8278 2.8424 2.8674 2.8679 2.8709 2.8716 2.8635

Saturday, June 09, 2007

Ruby: reading Microsoft/OpenOffice spreadsheets

Reading of Excel files (*.xls) can be done using roo package for Ruby.One function that I write for myself was function that reads Excel file (fragment seen on the below picture) to a Hash table, where first column (image file name) is a key. Moreover, a key is only base name of the file,i.e., no extension. The line #(1) is very interesting, as I found out that roo reads x-rays in a way that each character is separated by '0'. Thus, to get correct String, it is necessary to remove zeros from the string. This is I think due to encoding shame. Excel uses Unicode 16, instead of ASCI; hence, each character is represented by two bites: firt byte is a character, and the second byte is '0'. Hence, to read the file name to ASCI, it is necessary to skip ever second byte. It must be done, because otherwise gsub does not want to work.

def readExcelToHash f
oo =
oo.default_sheet = 1
0.upto(oo.last_row) { |line|
next if r[0].to_s.length==0
rs= r[0].to_s
rs.each_byte{|x| a+= x.chr if x!=0} #(1)
next if rs =~ /^#/

As far as creating spreadsheets is concerned, roo does not provide this functionality.

Monday, June 04, 2007

Noise and blur effect on the image

Adding noise to an image adds hight frequency components to it. High frequency components are those that are responsible for image sharpness, i.e., pixel to pixel distances. In other words, the smallest components of the image like edges. On the other hand, blur removes high frequency components from the image. Bellow, the picture presents image (left column) and its Fourier transforms (right column).

Above Fourier transforms were calculated using free ImageJ software.

Saturday, June 02, 2007

Ruby: Plotting with gnuplot in Mac X

To plot in Ruby, one can use rgplot interface to gnuplot. To install it, just download gnuplot-gem and install bysudo gem install ./gnuplot-2.2.gem
If you have gnuplot already installed it is good, if not install it bysudo port install gnuplot.
Assuming that everything went well, one can now plot and save figures using Ruby.
Simple example of Ruby code that plots simple data and saves (do not display) it to png file.
#!/usr/bin/env ruby
require 'rubygems'
require 'gnuplot'

xData=[1, 2, 3, 4,5]
yData=[2, 3 ,4, 2,3]

#xData=(0..10).collect { |v| v.to_f }
#yData= xData.collect { |v| v ** 2 } do |gp| gp ) do |plot|
plot.output outFname
plot.terminal 'png'
plot.title "Array Plot Example"
plot.ylabel "y"
plot.xlabel "x"

x= xData
y= yData << [x, y] ) do |ds|
ds.with = "linespoints"


This is especially useful when one want to plot a lot of figures contained in a data file. Of corese, this is the simples example, and more complicated things require to do some experimenting before desired plots are obtained. Nonetheless, this is good start.

To plot two data on one graph and to save it as png one can do as below:

#!/usr/bin/env ruby
require 'rubygems'
require 'gnuplot'
xData=[1, 2, 3, 4,5]
yData=[2, 3 ,4, 2,3]
yData2=[1, 2 ,3, 3,4] do |gp| gp ) do |plot|
plot.output outFname
plot.terminal 'png'
plot.title "Array Plot Example"
plot.ylabel "y"
plot.xlabel "x"

x= xData
y= yData =[ [x, y] ) do |ds|
ds.with = "linespoints"
end, [xData, yData2] ) do |ds|
ds.with = "linespoints"



Results is (graph.png):

Wednesday, May 30, 2007

Ruby: Separete OA and Control data

Separete OA and Control date from txt files.

#!/usr/bin/env ruby
sfh ='~/myruby/lud/pairs.txt','r')
sfh.each_line {|line| nameA.push line.chomp; }


fbase=ARGV[0] if ARGV.length>0'.txt','r').each_line {|l|
dataF[fname.chomp]= l.chomp;

nameA.each {|l|
if oaData!=nil
dataOA.push oaData
puts oa.chomp
if oaC!=nil
dataC.push oaC

puts dataOA.length, dataC.length

open(fbase+'_OA.txt', 'w') do |f|
dataOA.each { |i| f << i <<"\n" }

open(fbase+'_Control.txt', 'w') do |f|
dataC.each { |i| f << i << "\n" }

Example usage:
divOAvsControl.rb Sta_fs.txt
divOAvsControl.rb Str_fs.txt
divOAvsControl.rb Std_fs.txt

Source in: ~/myruby/lud/.

Tuesday, May 29, 2007

rar: compress and divide large file to bunch of small ones

rar a -s -v30000 -m5 test.rar test/*where 30000 means 30MB.
Uncompress:rar x dvd1.part001.rar

Thursday, May 17, 2007

VirtualBox, Intel Mac X, Ubuntu (Ubuntu Server Edition)

Having Mac X at work is really nice thing. However sometimes one would like to use something else like Linux or Windows or whatever. I'm one of those guys that needs usually more than one operating systems, just to test something, or just because there is some feature that is present in e.g. Linux which is not available in Mac X. I decided to try VirtualBox beta for Intel Mac X, and to install Ubuntu. My choice of Ubuntu was driven only because where I work, Ubuntu is Ubuntu available at local ftp i.e. do not need to download it form the Internet.

Even thought VirtualBox for Intel Mac X is in beta stage, the installation was smooth, installation of Ubuntu also. Ubuntu on VirtualBox had out-of-the box internet and network working. In other words, there was no problems in installing, running, and using virtual Ubuntu.

The only problem there was/is with shearing folders. This is not VitualBox fold (I thinks so), but Ubuntu's mounting schema. What I mean is, that after mounting share folder, only root can write to it. Unfortunately it is not possible to set up umask=000 (everyone can read/write).

Below some screens of Mac and Ubuntu.

Share folders:mount -t vboxsf [-o OPTIONS] sharename mountpoint

As a matter of fact, I would prefer to have Windows XP on Virtual Box, but to install it, first I have to talk with our IT manager, because he has Windows installation cd-rom.

What about Ubuntu Server Edition? I wander if it was possible to install Ubuntu Server Edition on VirtualBox on Mac X, and use it just like server i.e. to set up an internet website on a virtual server. To check it, and to check Ubuntu Server Edition I decided to install this os on VirtualBox and try to set up a working, virtual LAMP server.
Unfortunately the answer to the above question is: Installation of Ubuntu Server Edition failed. In fact installation went fine, but first booting just after the installation resulted in:

I decided to check something else also. I was wandering if I can copy virtual Ubuntu created in Mac X to Windows XP and run in successfully there.

Wednesday, May 16, 2007

Mac X: Project-R

The problem with Intel Mac is that there are no software for it. Since maybe two months there is Matlab, thanks God, but I still miss SPSS, or any other statistical software different than Excel!. I have just receive an email about something called project R. I was interested by the mail; hence, I found out that it is a statistical program. I hope that it is what I was looking for, or at least will be easy to learn, on the condition that it will be nice. At the moment I'm waiting, because installation through DarwinPorts takes ages, thus I have time to write something (in fact, I have not time, but checking this new soft is just excuse from work). As soon as the installation succeed I will check it, whether it was worth installing or not.

Installation has just succeeded, although it was very, very long. Just to check it, I used an example (creation of box plots) available in a official manual:
A <- scan()
79.98 80.04 80.02 80.04 80.03 80.03 80.04 79.97
80.05 80.03 80.02 80.00 80.02

B <- scan()
80.02 79.94 79.98 79.97 79.97 80.03 79.95 79.97

boxplot(A, B)

One can see that it was very easy, and this fast test is quite encouraging to spend some more time with this R.

95% confidence interval in R:
>X1 <- scan()
1: 205 179 185 210 128 145 177 117 221 159
2: 205 128 165 180 198 158 132 283 269 204
> a <- mean(X1)
> s <- sd(X1)
> n <- length(X1)
> errZ <- qnorm(0.975)*s/sqrt(n)
> errT <- qt(0.975,df=n-1)*s/sqrt(n)
>left <- a-errT
>right <- a+errT

Saturday, May 12, 2007

Latex: font sizes


or to change font in larger text part:\begin{small}
something something ...

Double spacing\usepackage{setspace}
or arbitrary spacing e.g.:\setstretch{2.5}
Two column article:\documentclass[twocolumn,11pt]{article}
In a text, to switch from one to two column use \onecolumn and \twocolumn.
in two-column documents, \begin{figure*} \end{figure*} provides a floating page-wide figure (and \begin{table*} \end{table*} a page-wide table). The "*"ed float environments can only appear at the top of a page, or on a whole page - h or b float placement directives are simply ignored.

Monday, May 07, 2007

Latex: too many unprocessed floats

If you have it, it means that you have put to many figures or tables one next to each other, and Latex cannot locate them all. The quick solution to this is to add:\clearpage or \cleardoublepage command between your float objects. I does not give blank page in our documents, it just give one more page for latex to put your objects on it.

Sunday, May 06, 2007

100% CPU usage by spoolsv.exe in Win XP

Spoolsv.exe is a windows server application to manage printing queue. My friend had problem in his laptop becuase this application was using 100 % CPU; hence, computer was very slow. If you kill it, it will start again in a few minutes.
The problem was caused by the fact, that there were few files in a queue to print, but no printer. Hence, he went to C:\windows\system32\spool\PRINTER and deleted everything what was there. Sometimes you must first kill spoolsv.exe in task manager prior to removing files. This helped.

Sunday, April 29, 2007

Coefficient of variation

The coefficient of variation is a dimensionless number that allows comparison of the variation of populations that have significantly different mean values. It is defined as:cv=std(X)/mean(X);
For example if:
X= [1.7 1.6 2.8 5.6 1.3 2.2 1.3 1.1 3.2 1.5 5.2 4.6 5.8 3.0];
then cv=0.5846.

P-value and t-critical values in Matlab and Octave

If one use to calculate t-critical and P-values using t statistis, those functins in Matlab/Octave do it:
t_critical= tinv(1-alpha/2,n-2);

where alpha is confidence level (e.g. alpha=0.05 for 95% confidence level);

where t is our calculated value of t statistics.

With regard to Octave, it depends which version you use. You may find that instead of tint and tcdf there are t_int and t_cdf functions.

Friday, April 27, 2007

Latex: Miktex (Windows) and TexShop (Mac X) and tetex (Linux)

Latex is great tool for writing scientific texts. You just write and do not worry about sorting references, formatting them, changing numeration when you add or remove figures, create subfigures, subtables, etc. It is just nice and I am big fun of it, even thought creating tables is not so convenient. Nevertheless, I have had lately one big problem with Latex, or rather I should say problems between Windows’ and Mac X’s Latex software.

At work I use Mac X 10.4 and I have TexShop to write in Latex. On Windows there is Miktex. Separately both tools are just fine. However, when I tried to edit tex file in Miktex file which initially was written in TexShop I found big problems. First of all, basic Miktex installation do not include subfig package. Which is very, very bed due to the fact that my PC box do not have internet connection. But after connecting to the internet and installing subfig and many other missing packages it did not help much. I still have huge problems with compiling tex files that were written in TexShop.

I know that Latex should be multiplatform but in my case it is not. As far as I can say TexShop in Mac X and MikTex in Windows are totally different, and one cannot use both. Maybe if I spend more time, I could solve all the problems and run my file on Windows, but in fact I do not have time and energy to do it. Even though I’m computer geek, believe me or not I have more important thing to do than to investigate what is happening with MikTex. I need to write, and not to waste time make MikTex working with my files from Mac XĂ…DMaybe if I install full MikTex, rather than basic, but this is not possible because full MikTex is just too big to download from the internet. One other fast possible solution is maybe to use Cygwin and to use some linux based latex software to write latex. This I can check quite quickly, but first I need to install Cygwin.

As a result I am considering working with OpenOffice or even Microsoft office, because they just work. Not perfectly but at least I can write. To be honest I’m I would prefer to work in Latex, and maybe I will do all the writing on Mac X, because Latex is much better for me than MS Office or OpenOffice.

By the way, I think that TexShop for Mac X is much better and easier to use than MikText. I wander how it looks like in Linux. I have Ubuntu on my other PC box, and maybe I will install some Latex environment there just to see if I experience the same problems or everything will work.

I also wander if only I have such problems between latex in Mac X and Windows XP, or it is rather common?

I have just tested latex on Ubuntu with tetex and auctex. Anfortunately the same proplems as before. I can not compile Latex files for Mac X - too many errors.

Latex is totally incompatible between different operating systems if one tries to write a little more complicated (subtables, subfigures, two column) article !!!

Wednesday, April 18, 2007

Matlab 2007a for Intel Mac. Finally!

Finally, after more than one year of waiting for Matlab with support of Intel Macs there it is - Matlab 2007a ( It supports also Windows Vista, and 64-bit Sun Solaris SPARC platforms. I was happy like little child to have it installed and to use it. Unfortunately it did not work from the beginning. When I try to run Matlab from console, I got:
Failed to start the Desktop:
Failure loading desktop class

In my case to make it work properly I had to update Java in my system to the latest versions available through Software Update. After doing this, Matlab environment started without any problems.

One of many new things about this edition of Matlab, is the fact that multithreading is available of core functions of Matlab. By default this option is disabled, hence one must enable it in the preference window. Unfortunately again, still you cannot write any program with multiple threads. Multithreading is only used by the core, standard Matlab functions.

Quickly I decided to test this multithreading. To test it I used quite intensive image processing algorithm analyzing images. I analyzed 34 images twice. Once with enabled and once with disabled multithreading option. I analyzed results using paired t-test to check if there is any significant (with confidence 95%) change in the execution time. Unfortunately, according to t-test, there was no significant change (P>0.05).

Moreover, new with this version of Matlab is the fact that one can run parallel algorithms in four MATLAB sessions on single desktop with Distributed Computing Toolbox.
Unfortunately, I do not have this Toolbox, and cannot check if this form of parallel execution significantly improve speed (assuming one have program that uses it).

I think that the best way for me to use two cores in my Intel Mac, is just to start to separate Matlabs. In my case it is very useful, because I work with image processing, and often I have many images to process. Thanks to two cores one Matlab can process first half of the number of images, and the second one, the second half. Consequently, I can process all images two times faster.

Finally, as usual with matlab version there are minor problems with backward comparability. Hence to run some programs on this newest version I had to make some minor changes in few algorithms. Moreover, at the moment there is problem with compiling ANCI C mex files. It is due to that I do not have latest version of Xcode. However, I believe that once I download it (over 800MB) and install, it will work.

And really final thought. Still no hash tables!

Sunday, April 15, 2007

Matlab and hash tables

Unfortunately, Matlab does not have hash table functionality by itself. However, Matlab is based on Java, and provides programing interface to java classes. Consequently, it is possible to use Hash tables from Java!. It can be convenient and fast. You can store normal scalars, strings, matrices, etc in Java containers without much effort.
Below little example just to start with. It shows Hashtable, where we put few values, and afterwards we create iterator and iterate over Hashtable.

function testJavaHash
import java.util.*;
ja_h = Hashtable;

c=[1 2; 3 4];

%add something to hash

%create iterator;
keys = ArrayList(ja_h.keySet( ));
iterator = keys.iterator();

%iterate over all keys
while iterator.hasNext();

Unfortunately, it is not as nice as it looks like. For example it is not possible to use matrices as keys in hash tables. For instance:
ja_h.put([1 2],2);
ja_h.get([1 2])
ans =

As it can be seen, ja_h.get returns nothing.
What I do do overcome this, I just convert matrix into string with num2str and back str2num. Not the best possible solution but it works for me in few limited situations:
ja_h.put(num2str([1 2]),2);
ja_h.get(num2str([1 2]))
ans =

However this solution does not work for e.g. 2x2 matrices ja_h.put(num2str([1 2; 3 4]),2);
ja_h.get(num2str([1 2; 3 4]))
ans =

Similar problems are with mhashtable package available from Matlab Central File Exchange. I do not know why it is so difficult for Matlab engineers to create native Matlab support for Hash tables?

Wednesday, April 11, 2007

Warning: Problems in UIW_SetUpGLPrinting

This error I had in Matlab. In fact it is only warning, but when you save image using e.g. print function your figure is just black. I had it working on Windows XP. The solution was to install Nvidia drivers to my GeForce FX 5200. Afterwards, saving images worked like it should.

Monday, April 09, 2007

Inter-observer, Intra-observer, observer bias variability

Those terms are commonly used in image processing e.g. comparing reproductivity of given segmentation method. Their meaning is as fallow:

Inter-observer - one observer scores the same phenomena several times at different times. For example: few times the same radiologist selects region of interest (ROI) on the same X-ray. The question is, how similar those selections separated in time are to each other i.e. can the radiologists manually select exactly the same ROI in terms of position, shape, size?

Intra-observer - few observers score the same phenomena. For instance: few radiologists select manually ROI on the same X-ray. What is the agreement in selected ROI by different radiologists.

Observer bias - each observer can interpret the same phenomena differently. For example, if selecting ROI, radiologist can include into ROI distorted parts of an X-ray image (e.g. by noise), because for him those distortions are small. At the same time, the other radiologists can avoid those parts of X-ray, cause for him those distortions are to serious to ignore.

Sunday, March 25, 2007

Matlab and huge matrix execution time

Recently I was working with huge, really huge 3D matrixes in Matlab for example take matrix A=ones(64,64,50100). It is huge matrix of double values. Unfortunately operations on such a matrix are very time consuming.

For example performing summation of all values along the third dimension sum(A,3)
takes 235 seconds on Ultra Sparc Sun-Fire-440. That is why sometimes it maybe beneficial to create single or unsigned integer 32bit (uint32) matrix instead of doubles e.g: A=uint32(ones(64,64,50100)). In this case performing sum over third dimension takes 211 seconds. When using single instead of double, the time is 204 sec. The difference is not so big, however when using uint8 the time is only 60s. Unfortunately using uint8 when one wants to sum up matrix with over 50000 numbers has no sense unless it is heavily sparse matrix - uint8 holds numbers not bigger than 256.

In conclusion, I think it is better to avoid such matrixes.

Wednesday, March 21, 2007

Directional evaluation of fractal dimension using Power Spectrum Method

Power spectrum algorithm, based on J. Russ book [1] divided 2D power spectrum of an imput image into 'slices' which represent directions and frequencies as show below:
For example one can divide power spectrum i to 24 radial slices i.e. one slice is 15 degrees (24*15=360) and slice is divided to 30 frequencies (30 rings). The greater radius of the ring, the bigger frequency.
Apart from directional fractal dimension evaluation, algorithm performs overall fractal dimension analysis by 'averaging by circles'. In this case power spectrum is divided to 60 (2*30) rings:

In addition, vertical and horizontal direction are not considered in the computation as to avoid border effects.

[1]John C. Russ, Fractal Surfaces, 1994

Sunday, February 11, 2007

SPSS+Python: First script

The below scripts reads Excel file. Than the python program pairs variables, that will be compared using paired t-test.
/SHEET=name 'Lat'


import spss
from spss import Submit

ScalesC=['V'+str(i+1) for i in range(1,10)]
ScalesOA=['V'+str(i+11) for i in range(1,10)]

for v in zip(ScalesC,ScalesOA):

Friday, February 09, 2007

Samsung Digimax S500 and Sony Cyper-shot 6.0

Another Korean junk that I have bought. I will never again buy anything that comes from Korea. Before I had problems with DVD player from LG, and now, after taking only few pictures
with Samsung digital camera it stop working.
Now when I want to take a picture, camera just switches off, and that's it. Sometimes I can make one picture, but second one is not possible. This happens only when flash is used, so I reckon that flash lite causes some electric overload, and camera switches off.

Why today only junk is created? And it is not only Korean. My friend bought Sony Cyber-shot 6.0M and after one month it was broken. The lens was stacked in its shield.

Sony is from Japan, Samsung and LG (my former post about LG DNX-190 UH DVD player) are from Korea, so what they have in common? They are made in China.

Wednesday, January 31, 2007

Windows XP overwrites linux boot menu

This happened to me today, when I installed new Windows XP on a PC with pre-installed Ubuntu. Fortunately, fast I used Super Grub Disk witch can easily repair what Windows XP destroyed. Restroing former boot menu, was just a matter of few seconds.

Wednesday, January 17, 2007

Interesting USB drive

Yesterday, I got nice present from my girfriend - a USB key. It is quite interesting model,
because it was given for free as a promotion for a chewing gum :-). This USB drive looks like
box of gum; hence, at first I thought that I was given a gum. I was quite surprise to find
USB storage instead gum. This USB drive, is quite small as for today standards ( only 64MB),
but is something. For example I can use it to carry DSL (Damn Small Linux) distribution. For
now I'm planing to use it normally, because it is nice and many people are surprise when
I show it to them.

Monday, January 15, 2007

Ruby: bash image processing

As working mainly with images and image processing, sometimes I have to do one or two simple operations on many files at once like resizing, converting RGB two Gray, changing format of images, mirroring, blurring, etc. To this time I was always using Matlab to do it, because I could not find any free software on Mac X that can do such simple operations. Nonetheless, there are some issues with Matlab that annoy me, specifically: there is no native Matlab for Intel Mac X 10.4. Matlab works on Mac X 10.4 only by emulation mode, which is extremely slow and most importantly crashes very often. I had to find some more reliable solution, and I find it in Ruby.

Ruby, has very good image processing package called RMagick (interface between the Ruby programming language and the ImageMagick and GraphicsMagick image processing libraries). Installation is quite trivial. Explanation how to install RMagick on Mac X is here. I fallowed those instructions and had no problem.

require 'rubygems'
require 'RMagick'

class ConvertFiles

def initialize inDir='inputDir/', outDir='out/'
raise 'No INPUT dir' if !File.exist? inDir
@inDir = inDir
@outDir = outDir
@files =

def readFiles
Dir.glob(@inDir+'*.tiff').each { |l|
@files.push File.basename(l)

def createOutDir
Dir.mkdir(@outDir) if !File.exist? @outDir

def singleImgProcess img
return img.scale!(0.50)

def bashProcess
@files.each { |fn|
puts @inDir+fn
img = singleImgProcess img


Example usage is also quite simple:

c =
Moreover, if I need some other operation or operations, I can just create new class, inheriting from the above one e.g.:

class Enlarge < ConvertFiles
def singleImgProcess img
return img.scale!(1.50)

e =

Or if I want to add some text to all images, I just can do:

class AddText < ConvertFiles

def setText t
@txt = t

def singleImgProcess img
@txt='Default' if @txt.nil?
text =
text.annotate(img, 0, 0, 0, 60, @txt) {
self.gravity = Magick::SouthGravity
self.pointsize = 48
return img
a.setText 'My pictures'

This simple code, shows how powerful and convenient Ruby can be.

Sunday, January 14, 2007

DVD player: LG DNX-190 UH

I have just bought DVD Player - LG DNX-190 UH:
Unfortunately, to make it work was quite a big problem. My TV has only S-Video socket for video input, so I thought that when I connect my new DVD and TV using S-Video cable, it would work without any problems. Of course, it did not. There was no picture! I had sound working, but I did not see anything. Studying a manual, I discoverd that in order to use S-Video connection, you have to go to Setup menu in DVD, and change it there. This is just great!!!. How can I manipulate Setup options if I do not have any picture?!!!. Impressed by this genius solution from Korean engineers I get quite angry. Of course before that, I had gotten angry, because my dvd box did not include S-Video cable, but fortunately, I had my own.

The only thing I could do, was to take this rubbish dvd player, go to my friend, connect it using Video cable, change the S-Video option in Setup menu in his place, return home, and connect to my TV. After that I finally could see something on my DVD.

For now, I have not seen any movie, so I do not know if this dvd player can play movies correctly. I have just start one or two movies to see if they work. They worked. I have not had time to investigate how useful and convenient this dvd player is, and if he plays everything correctly.

One positive thing about it for now, is the fact that in shop I was given a sheet of paper witch 'cheats', how to make this dvd palyer multi-region. I have not tried it, so I cannot say if it works, and even if, I do not have any dvd movie from another dvd region.

Finally I had some time to look closer to this DVD. After few minutes, I decided to return this rubbish DVD player. This junk was playing DVDs with some 'cracks' in a picture which sometimes was 'jumping'. It was not very often, and as a matter of fact, you could watch movies, but those occasional 'jumps' were annoying. Not thinking much, I return this junk, and I had it replaced. Fortunately, the shop did not make any problems with exchange, just 'no question asked'.

Tuesday, January 09, 2007

Mac X: Making backup of your dvd movie

Sometimes people buy dvd movies, for AU$30-40 and of course they would like to make a copy of it, because it wouldn't be nice to destroy original disks.

Windows users don't have problems with that, because there exists great free tool to do it called DVD Shirnk. I used it to make backup of my collection of Star Wars movies, and it is really worth of recommending.

But what about Mac X users? At the moment I want to backup one freshly bought movie, and unfortunately on Mac X this task is not so trivial. First of all, there is no free tool (at least I could not find any) to do this. Of course there are many commercial software that can be helpful, but I do not what to spend money, on software that is used really rarely.

Therefore, what I do is, I use two tools to make backups. First, I use free MacTheRipper (A DVD extractor) to dump movie to hard drive. It must be noted, that MacTheRipper do not compress (shrink) movies; thus, if your move is bigger that 4.37GB, you have to use another tool, to shirk it, after it was copied to hard drive.

To shrink movie, you can use: Popcorn, DVD2OneX, DVDRemaster or Toast Titanium. Luckily for me, I owe the last program. Therefore, I can burn shirked movie to DVD5.

Nevertheless, this workaround solution is not as good as the one using DVD Shrink on Windows. First and foremost, you cannot choose what parts of DVD you want to extract like which languages, sound, subtitles, extra features etc. MacTheRipper gives you opportunity mainly to dump main movie only, all full dvd. You cannot select that you want e.g. English subtitles only or/and Polish ones.

But, for now I do not see any great alternative for me in the task of backuping dvd movies on Mac X.