WickedLeak Wammy Desire

Just bought this budget tablet a couple of days back. The standard resolution tablet costs 6500.Add 450 for shipping to hyd. They did not give me the pen that I saw in some other places in the internet. Just got the two connectors – the microusb to USB (female) and the microusb to USB (male).

I had to do a factory reset to make the tablet work. From that time there is no software glitch that I could find. The factory reset was required as the software crashed repeatedly. I don’t think the hardware needs to blamed here, it was just that jelly bean had not been configured correctly.

The display is OK. If you apply the slightest pressure at the back, the finger presses are visible On the screen. However, the biggest inconvenience seems to be the battery. It takes a full 10 hrs to charge completely and it lasts for just over 3 hrs.

A pleasant surprise for me is that, tata photon + works with this device – just have to add an APN with #777. The main reason I bought this was for games and they work superbly with this device. Of course , given Its specs one expects such performance. Everything else is good enough for me.

I have looked at various places over the internet before buying this, so this small review might help somebody out there.

lxde wallpaper slideshow

I concoted this from exisiting code over the internet. This code displays a random image from a specified directory (all subdirectories included) as a wallpaper in lxde. This is working for me under arch linux.

#!/bin/bash
DIR="/put/your/directory/here"

# failsafe - fall back to current directory
[ "$DIR" == "" ] && DIR="."

# save and change IFS
OLDIFS=$IFS
IFS=$'\n'

# read all file name into an array
fileArray=($(find $DIR -name "*.jpg"))

# restore it
IFS=$OLDIFS

# get length of an array
tLen=${#fileArray[@]}

FLOOR=1
while [ 1 -eq 1 ]; do
number=$RANDOM
while [ "$number" -le $FLOOR ]; do
number=$RANDOM
done
let "number %= ${tLen}"  # Scales $number down within $RANGE.
pcmanfm --set-wallpaper "${fileArray[$number]}"  --wallpaper-mode=fit
sleep 10m
done 

Some interesting facts about india

0) Indians consider money to be the most important thing to possess. Honesty (especially) is the most dispensible here. Always try not to be truthful if you want a “happy” life (http://toostep.com/debate/are-indians-money-obsessed).

1) People dislike each other. Honestly, they dont hate each other very often. Only every now and then. This dislike is what most people in India live with daily. They have gotten accustomed to it and they no longer really find it disturbing.

2) India is one of the most corrupt countries in the world. I did not have to say that after point (0).

3) The reason why an Indian lives (can get through a typical Indian day) is because (mostly) he/she has found that some other (arbit) Indian has found the courage to do so. There is never really the question of “What I want?” and living according to that.

5) India has never been limited by resources, it is currently being severely crippled by the attitude of its people.

6) Hyderabad (the city I live in) is a total shit-hole, literally (well, OK, atleast during the rainy season when all the sewage is on the roads!).

7) Some people (especially the poor ones and some rich ones too) survive almost like pigs. One can say that these are some of the most deplorable states in which a human can live.

8) Malnutrition is comparable or worse than Sub-saharan africa. I think countries like Somalia have our rates (http://en.wikipedia.org/wiki/Malnutrition_in_India).

9) Driving: Get an expensive car. You get more respect on the road. If you have a smaller car then God be with you. Well, HE has to be there with you even if you have an costly car anyways. FACT: India has the highest number of road accidents in the world. Dont think it is because of the population: China has less (http://www.dw-world.de/dw/article/0,,5519345,00.html).

10) Very few people give a damn to whats going on around. Indians have the greatest sense of apathy in the world.

11) Indians should be the least creative in the world with a whopping 4 (or 5?) Nobel and 0 Fields medals. Yet, India invented zero and blah, blah. (Should learn something from rajini: past is past).

12) Yet, India has a great culture, tradition, India is great blah, blah. generally written by people who do not understand what they are saying. This is all one can say: India was great (a long time ago that too).

A small question

Let {X} be a set. Let {\mathcal{G}} be a non-empty collection of subsets of {X} such that {\mathcal{G}} is closed under finite intersections. Assume that there exists a sequence {X_h \in \mathcal{G}} such that {X = \cup_h X_h}. Let {\mathcal{M}} be the smallest collection of susbsets of {X} containing {\mathcal{G}} such that the following are true:

If {E_h \in \mathcal{M}} {\forall h \in \mathbb{N}} and {E_h} {\uparrow} {E} then {E \in \mathcal{M}}
If {E}, {F}, {E \cup F \in \mathcal {M}} then {E \cap F \in \mathcal {M}}
If {E \in \mathcal {M}} then {E^c \in \mathcal{M}}

Does {X \in \mathcal{M}} ?

DFT revisited

I was reading a book on image processing by Bernd Jahne and found what he wrote about the Discrete Fourier transform very interesting. The DFT can be computed as {\hat{f} = A f} ({A} has been defined in a previous blog ), so it seems like a linear transformation. A new interpretation is that the rows of {\hat{A}} (or the columns) ({\hat{A}} has been defined in a previous blog ) can be thought of as spanning the vector space of all N-tuples of complex numbers denoted by {\mathbb{C}^N}. First of all, it can be checked that N-tuples of complex numbers form a vector space. On this vector space, an inner product can be defined as follows :

\displaystyle <v,w> = \sum_{k = 0}^{N-1} v_k {\bar{w}_k}

With this definition of inner product on the vector space, one can easily show that, {<\frac{1}{\sqrt{N}}u_i,\frac{1}{\sqrt{N}}u_j> = \delta  (i-j)} where {u_k} is a row (or column) of  {\hat{A}} .

Therefore, if {C \in \mathbb{C}^N} then {C =  \sum_{k = 0}^{N-1} \alpha_k (\frac{1}{\sqrt{N}}u_k)} where {\alpha_k =  <C,\frac{1}{\sqrt{N}}u_k>}. Clearly the {\frac{1}{\sqrt{N}}u_k} span {\mathbb{C}^N}. It can also be checked that {\alpha_k} for {k \in  \{0,1,..,N-1\}} is the 1D Fourier transform. Hence the DFT of a vector {f} is just a projection of {f} on the rows of {\hat{A}}.

In two dimensions, we consider the set of all {M\times  N} complex matrices. This is again a vector space over the field of complex numbers. The basis “vectors” now are the matrices {(B_{u,v})_{m,n} = D_{m,n} =\frac{1}{\sqrt{MN}} exp(\frac{-2\pi  imu}{M}) * exp(\frac{-2\pi inv}{N})} for all {u  \in \{0,1,...,M-1\}, v \in \{0,1,...,N-1\}}. The inner product for two complex matrices is defined as :

\displaystyle <A,B> = \sum_{m=0}^{M-1}\sum_{n=0}^{N-1} A_{m,n} {\bar{B}_{m,n}}

Any complex matrix can then be written as a linear combination of the Basis matrices {B_{u,v}}. {C =  \sum_{u=0}^{M-1}\sum_{v=0}^{N-1} \alpha_{u,v} B_{u,v}}. Then it can be shown that {\alpha_{u,v}} is the 2D Fourier transform for {u \in \{0,1,..,M-1\}, v \in  \{0,1,...,N-1\}}. So, we are projecting {C} onto the Basis vectors {B_{u,v}}. By this reasoning it can be shown that the 2D Fourier transform for a matrix {C} can be written as {A_M C A_N}, where {A_M} is the {M\times M} DFT matrix and {A_N} is the {N \times N} DFT matrix.

NOTE: I was only mentioning {\hat{A}} as I was lazy to write the basis vectors. Hope this did not confuse.

Hakell and Image processing

I love to do image processing and Haskell and wanted to put these two things together in an “effective” way.

Why do I want to program in Haskell? The answer is simple: I love the declarative style of functional programming. I can directly write my formulas into code. I waste less time doing rote jobs and think at a higher level, so it is good for my grey cells as well.

Also, I hate the fact that I have to manage the memory by myself in C / C++. My biggest problem with C is that, I am never at peace with my code. There might be a memory leak somewhere, a global variable might not have been updated and all that crap. My mind twists and turns in trying to reason about code. I just wanted a language where I would write code and just forget about it and it works just fine :)

The problem with doing image processing in C is that, using the default Haskell data types (lists, functions) makes the program too slow. One has to expect such speed hits as this is a very high level programming language. However, there are a few array libraries that speed up the code. The sped up code might not compete with C but it is reasonably fast.

I have used the hmatrix library for representing an image. What I like about this library is that there are a whole lot of lapack algos that can be implemented on them. This library allows one to write purely functional code. Just write the image as a 2D function( func (i,j) ) and use buildMatrix, voila! you have a new image.

Hmatrix was just perfect for the array library. I still had lot of problems with interfacing with my web camera. I understand that there is a HOpencv library which can do that but after glancing through the doumentation I felt that the API requires me to stay inside the IO monad. Which means the same stateful programming that I much abhor. Added to that it did not compile on my system and I had to find another way to grab images.

There seem to be nice examples on internet for grabbing images from web cameras (using v4l2 in linux) and I modified a C source and wrote FFI bindings to it. I am truly elated to find that the FFI bindings to v4l2 based image grabbing and the hmatrix work seamlessly :) .

If any of you require the bindings reply and I will try to post them.

Convolution

Convolution is mathematically well understood, both in the continuous and discrete domains. There is a simple formula to comupte it. However, I recently needed to implement this in code and found that it was not all too easy. In this post, I tried to come up with a formula that can be used for programming convolution. In later posts about this, I will also try to analyze the computational complexity and spruce it up with some real working convolution code.

Firstly, what is discrete convolution? There is a straight-forward formula :

\displaystyle  h[n] \equiv (f*g)[n] = \sum_{k=-\infty}^{k =\infty} f[k]g[n-k]

For generality we will assume that {f} and {g} are discrete functions (i.e. functions from the Integers to the Reals). For example, {f} might be such that it is defined from {fl} to {fh} and it is zero outside. This is the most general representation for the signal. Similarly, let {g} be defined on {[gl,gh]} and zero outside. When we are asked to convolve these two signals, it is apparent that {fl,gl,fh,gh} would play some role in the computation. However, MATLAB for example, does not care about these values. So, it is slightly confusing how convolution is carried out. Let us examine.

In the definition of convolution, what are the values of {n} that are interesting? Before thinking about that, it is better to understand what values of {k} are important for our considerations. Fix any {n} and note that

  • { fl \leq k \leq fh}, because outside of this range, {f[k]} is zero and hence does not add to the convolution
  • Similarly, {gl \leq n - k \leq gh} which implies that {n - gh \leq k \leq n - gl}

Clearly, if {[fl,fh] \cap [n-gh, n-gl] = \phi}, the convolution is zero and we do not have to care about such an {n}. Otherwise, one can immediately see that the interesting values of {k} are :

\displaystyle [fl,fh] \cap [n-gh, n-gl] = \max (fl, n- gh) \leq k \leq \min (fh, n - gl)

Let us rewrite the formula again (for those {n} such that {[fl,fh] \cap [n-gh, n-gl] \neq \phi}):

\displaystyle  h[n] \equiv (f*g)[n] = \sum_{k= \max (fl, n- gh)}^{\min (fh, n - gl)} f[k]g[n-k]

Now, what are the values for {n} for which {[fl,fh] \cap [n-gh, n-gl] \neq \phi}? Consider, {  n = fl + gl}, then

\displaystyle  \begin{array}{rcl}  [fl,fh] \cap [fl+gl-gh, gl+gl-gl]  &=& \max (fl, fl+gl- gh) \leq k \leq \min (fh, fl+gl - gl) \\ 		 		 &=& fl \leq k \leq fl \\ 				 &=& fl \end{array}

When {n < fl + gl}, {\min (fh, n - gl)  < fl} and hence the convolution is zero. The upper limit on {n} can similarly be found to be {n = fh + gh}. Therefore, the full definition of convolution useful for computer implementation is:

\displaystyle  h[n] \equiv (f*g)[n] = \sum_{k= \max (fl, n- gh)}^{\min  (fh, n - gl)} f[k]g[n-k] ~~\forall n \in [fl+gl,fh+gh]

Upon further thought, it can be easily seen that {fl,fh,gl,gh} are not important for the core convolution. If the signal {(f, [fl,fh])} is replaced by {(a, [0, fh-fl])} and {(g,  [gl,gh])} is replaced by {(b, [0,  gh-gl])} there would no difference in the computation of the main convolution function. Only the range of {n} for which the convolution is defined change. This is the primary reason why MATLAB does not care about these things.

Follow

Get every new post delivered to your Inbox.