Tuesday, May 22, 2012

DNA Reshuffled!



From the eyes of a Computer Engineer, I will try to put forth the genetics. 

1.) Lets say we need to fill a register of Genetic code (just like an IP address). For a different person, we need a different code. A code represents a unique person.
For now lets say that there are quadrillion/1000 Trillion different possibilities (considering the fact that current population is just 7billion)
So the no. of bits this register need to have is 50. So, to let you get the feel of this register being the genetic code, Lets say there may be 64 types of eyes, so 6 bits for eyes, 128 different colour of skin, so 7 bits for skin colour, 16000 different face cuts, so 14 bits for face cut and so on..
Now this might let you wonder that 50 bits are such a small register size, and this indeed means that possibility is way over a 1000 Trillion. So God can indeed make more than 10^15/7*10^9 times the population of earth without repeating a single character.

Below is a little illustration of how the IP addresses are allocated, if you know it you can skip it and start reading from  ***STAR***.

2.)The distribution of Ip address to companies done depending how large the chunk you want to give to a particular company. So, Lets say I have an address of 16bits (a total of 64K addresses) and we want to divide it to 32K+16K+8K+8K. So I will fix the first bit to say 0 and give it to company A. fix first 2 bits as 10 and give it to B. and fix first 3 bits as 110 and 111 and give them for use to C and D. Now, A B C D all have 15,14,13,13 bits resp. to vary and hence 32K, 16K, 8K, 8K addresses.

***STAR***

3.) Now lets assume division of Genetic code over 7 continents. Asia is most populated so we have lets say 10 bits fixed for all Asians. Lets say these fixed bits represent colour, nature and all those features that you think are common in all asians. Do the same thing for all the continents.
One can further divide these continents into countries. Lets say Indians and Chinese dont have similar eyes, similar voice etc, but are similar in colour etc.
So lets fix 10 bits between Chinese and Indians. So in total Indians and chinese are more similar than an Indian and American coz they have 20 bits in common rather than 10 bits.

4.) Now lets go up to the illustration of the company (2), Suppose the company initially bought more no. of IP addresses than it uses, then those extra bits are being wasted. And no one can use those IP addresses.
Similar is the case with genetic code, the continents whose population is less are not able to fill up that big gap of available genetic diversity.

5.) Now, the child bears the genetic code which is intermediate value of the genetic code of its parents. Because the child will either pick up the characteristic of its father or its mother, thus giving it an overall intermediate value.

6.) Now the Hypothesis is that if the Parents are genetically very diverse, say belonging to different continents, then only we can fill up those intermediate gaps inbetween. Because we are only using a very small fraction of the available genetic code. only 7 billion reside on earth when the possibility is as large as quadrillion, So it will be better for human race that all these 7 billion genetic codes that we are using right now are very sparse apart rather than being chunked up.

So inter racial marriages and children are the need of the hour!! go for it!!

Saturday, January 21, 2012

Shannon!

One can predict, predict and predict unless the residue becomes perfect noise and that is the limit of compression, the Shannon limit!!

Saturday, January 14, 2012

Denoise it!!


This algorithm may not be very competent but it still gave appreciable results as I made them on my own without any background on image processing. What I have done is, First found out the irregular value in 3X3 matrix, which could possibly be noise. By irregular value I mean, the value which is 20 (this factor can be varied to study its effect) units farther from its neighborhood. Then we substitute the mean of regular values in the matrix to the irregular value.

Below is the MATLAB code for the same and in the end the result. A 3 to 4dB gain in PSNR is observed. Cheers!!



a=imread('plane.jpg');
sze=1200;
a=a(1:sze,1:sze,:);
b=imnoise(a,'gaussian');
c=b;
d=a;


for rgb=1:3
  rgb                       % for R, G and B matrices
  for i=2:sze-1
    i;
    for j=2:sze-1
      z=0;
      arr=zeros(3,3,3);
      for l=1:3
        for n=1:3     % if statement for neighborhood
          pqr=0;      % limit
 if((c(i-2+l,j-2+n,rgb))-c(i,j,rgb)<20 && (c(i-2+l,j-2+n,rgb))-c(i,j,rgb)>-20)
        z=z+1;
        pqr=1;
        arr(l,n,rgb)=c(i-2+l,j-2+n,rgb);   
        end
      end
    end
    c(i,j,rgb)=round((9/z)*(mean(mean(arr(1:3,1:3,rgb)))));
    end
 end 
end
imwrite(b,'3noised.png');
imwrite(a,'3original.png');
imwrite(c,'3noise+myalgo.png');

error_diff = c - b;          
decibels=20*log10(255/(sqrt(mean(mean(error_diff.^2)))));
disp(sprintf('PSNR after reduction= +%5.2f dB',decibels)
error_diff = b - a;
decibels=20*log10(255/(sqrt(mean(mean(error_diff.^2)))));
disp(sprintf('PSNR of noised image = +%5.2f dB',decibels))
original Image
Noised Image
Noised image, denoised!


Quater image denoised


removed noise!!

Thursday, January 5, 2012

The Colours!!

See the world around us! Its beautiful, isn't it? Why?
I guess beauty is defined as correct composition of shapes and colors that somehow appears nice to our mind, even if you cant perceive it. Now just look around you and observe the no. of colors you might see. For example I can see my roommate in green jacket, the color of wall of my hostel room - Yellow, the table - Brown, my pillow cover - Blue. I mean we are just covered with millions of colors.
And the strangest thing majority of elements which, surprisingly comprises of more than 99% of Universe, more than 90% of earth's crust, the s and p block elements are either colorless or white. The f block is too radio active to be around us.
So it is d block elements that surround us and adds colors to our life. The surroundings of yours wouldn't be as colorful as they are without the presence of these d block elements. These small percentage mass of earth's crust has somehow become so important that the earth; leave earth, even our imaginations, our dreams wouldn't be as beautiful as they are, so colorful, so beautiful and so happening.  We must respect nature for all it has given to us and keep our search on, to unveil the secrets.

Saturday, July 2, 2011

Dropping the stone!!

Its a rainy season in India, and standing by my balcony, I saw the beautiful patterns made by falling droplets on the pond..
10 minutes on matlab landed me to this image!!
Now the waves are sinusoidal so I started with sine wave multiplied with log so that the amplitude decreases with distance!!

a=imread('lena.jpg');
for i=1:1028
      for j=1:1028
             d=1000*sqrt((i-125)^2+(j-355)^2);
             a(i,j)=(log10(d)-6)*sin(d/5000)*21+128;
      end
end
imshow(a);

The centre taken is (125,355)
I am reading lena.jpg. You can read any image file you want.. 
The only use of reading this is to make an array in jpg format.  

You can change the parameters and scaling factors to  see very interesting results!! 

It looks like Newton's Rings', Isn't it?? 

 

Saturday, May 14, 2011

Swinging the pendulum!!!

Watching the dell dock's swinging application challenged me as I saw matlab's icon swinging like pendulum.
I decided to make an object swing like simple pendulum on matlab.

Sounds easy, isn't it??? That's what I thought before starting to work..
But the pursuit took me from coordinate geometry to physics to differential equations and back to matlab...

First what I did was, used pythagoras theorem to compute the row coordinate while varying the column coordinate LINEARLY, and colored the neighborhood of equation describing the line segment joining the fixed point and computed coordinates. I thought it would work perfectly fine, But it looked strange, nowhere near the motion of a pendulum.

Here is that code.... check this out!!!



clear;
a=zeros(150,400,3);
len=100;
t=0;
p=-len;
cir=zeros(150,400,3);
mov=zeros(150,400,3,2*len+1);
for i=200-len:200+len-2
    a=cir;
    p=p+1;          
% linear increment of column coordinate.
    j=round(sqrt((len*len)-(p*p)));    
% pythagoras theorem.
    cir(j:j+1,i:i+1,2)=123;
   
for r=2:j
       
for s=200-len:200+len
           
if((s-200)*j-r*(i-200)<100 && (s-200)*j-r*(i-200)>-100) 
               a(r-1:r+1,s-1:s+1,3)=255;  
% coloring neighborhood 
               a(r-1,s-1,2)=123;    
      % of line segment
               t=t+1;
           
end
        end
    end

    mov(1:101,1:400,1:3,i-200+len+1)=a(1:101,1:400,1:3);
 
end
mov1=immovie(mov);
implay(mov1,20);
clear



Now the aim was to match the motion with the motion of pendulum.
The challenge lied in incrementing time linearly and varying the column coordinate with respect to time in accordance with the force equations of a pendulum.

Here is the solution--- 
 

 Free body diagram of the problem--


           
           
 where-

             'L' is length of the thread.
             'Φ' is angle subtended by thread.
             'm' is the mass of the pendulum.
             'T' is the tension in the string.
             'g' is the acceleration due to gravity.

             'x' is the column coordinate.
             'y' is the row coordinate.

Variables of concern--    


           

 it represent displacement, velocity and acceleration in x and y directions resp.

Solving the force equation from the free body diagram. 


where
             'ay' is acceleration downwards
             'ax' is acceleration toward right.  
 
Substituting the values and solving, we get solution(the first equation in image) via Lagrange's equation.


Finding the constants of the differential equation by putting the initial conditions of velocity and displacement. 

clear;
a=zeros(150,400,3);
len=100;
t=0;
cir=zeros(150,400,3);
mov=zeros(150,400,3,2*len+1);
i=0;
j=round(sqrt((len*len)-(i*i)));
q=zeros(1,200);

while i<=len-2
    i=round(len*sin(-1.4303*sin(t/68+(11/7))))
    t=t+1;
    a=cir;

    j=round(sqrt((len*len)-(i*i)));
    cir(j:j+1,i+200:i+201,2)=123;
   
for(r=2:j)
       
for s=200-len:200+len
           
if((s-200)*j-r*(i)<75 && (s-200)*j-r*(i)>-75)
              a(r-1:r+1,s-1:s+1,3)=255;
              a(r-1,s-1,2)=123;
   
        end
        end
    end

    mov(1:101,1:400,1:3,t)=a(1:101,1:400,1:3);

end
mov1=immovie(mov);
implay(mov1,50);