Category Archives: Programming

Forming a 2D window from a 1D Function

I came to this question because of the Kaiser window used for my BM3D implementation. I used Matlab to generate the Kaiser window I want for my C code so I don’t bother to write that function in my project. However, Matlab only has 1D version of the window functions. The following demonstrates two ways to generate the 2D window from its 1D function.


There are basically two ways of forming a 2D window from a 1D function. The
first is the outer product formulation; the second is the rotational
formulation. To create a outer product window (which your kaiser examples
look like they are trying to do), you can use

w1D = hamming(16); % Some 1D window
w2D = w1D(:) * w1D(:).’; % Outer product

To use a rotational formulation (which generally gives more circular
contours), you can use

L = 16;
w1D = hamming(L); % Some 1D window
M = (L-1)/2;
xx = linspace(-M,M,L);
[x,y] = meshgrid(xx);
r = sqrt( x.^2 + y.^2 );
w2D = zeros(L);
w2D(r<=M) = interp1(xx,w1D,r(r<=M));

Using opencv from python on windows

The official OpenCV2.2 installer does not install the Python bindings into your Python directory. There should be a Python2.7 directory inside your OpenCV 2.2.0 installation directory. Copy the whole Lib folder from OpenCV\Python2.7\ to C:\Python27\. Then set the windows environmental variable PATH to include your OpenCV\bin directory together with C:\Python.

Alternatively use the opencv-python installers at

Topcoder Algorithm Tutorials

Topcoder has many excellent tuorials for algorithms that we meet everyday, for example, dijkstra and maxflow, which all were written by topcoder members. Usually, at the end of each tutorial, the author would often explain some applications for this specific kind of algorithm, and most of the applications are from the topcoder’s competition problems. It’s a nice place to start with if you want to improve your programming skills.

difference between stack & heap (general, for a newbie)

Sean Cook wrote:
> Andrey (and others),
> What I should’ve asked is "what is the scope of data when allocated
> from the heap, and what is the scope of data when allocated from the
> stack (where “heap” and “stack” are not standards, but are merely
> common terms.)
Now we are getting somewhere
The scope of memory allocated on the ‘stack’ is the scope
of the enclosing block. They get destroyed when the enclosing
block is finished. Thats why they are called ‘auto’ objects.
int i;
} // block ends, i gets destroyed
The scope of memory allocated on the ‘heap’ is different. Objects
get allocated with new (or malloc) and get destroyed when a corresponding
delete (or free) is executed. Blocks do no longer influence the scope of
these objects.
int* pJ;
int* pI = new int [20];
// Note that 2 things are happening here:
// 1.) An int array is allocated on the free store (aka heap).
// This array will be there until a corresponding delete [] is
// executed
// 2.) A variable pI is created. Since pI was not dynamically created
// with new or malloc, it is an auto object (created on the stack)
// Thus the enclosing block determines its lifetime
pJ = pI;
} // block ends. pI gets destroyed, but not so the int array. It
// will stay there in memory until a delete is done.
delete [] pJ; // now the memory in the free store (aka heap) gets
// released.
> And also, is there a performance difference, in general, of objects
> allocated on the stack versus those allocated on the heap, or is this
> a completely meaningless question?
Free store allocation usually takes more time

Karl Heinz Buchegger


看了一天的KDE+QT还是找不到北,虽然也尝试了一个例子,Qt designer 和 KDevelop也都还很好用,但还是觉得比较难上手,进展比较慢。中午终于第2次放弃了Qt,下午开始看FLTK。希望以后的程序都用fltk来写,下面是FLTK的简单配置。

1. C/C++
    a. code generation, change runtime library to Multi-threaded DLL
    b. Command Line. /Ic:\fltk-1.1.4
    c. precompiled header, turn off.
2. Linker
    a. Command Line. c:\fltk-1.1.4\lib\fltk.lib wsock32.lib comctl32.lib

很不错的FLTK tutorial;
FLTK Video Tutorials—-
Beginner FLTK Tutorial —

#include <FL/fl.h>
#include <FL/fl_window.h>

int main()
 Fl_Window win(720, 486);;
 return Fl::run();