The BOTTOM LINE Quote Of The Day

The BOTTOM LINE Quote Of The Day

Don't Ever Tell GOD How BIG Your Problems are.
Just Tell Your Problems How BIG your GOD is ;)

Tuesday, May 8, 2012

DCT Image Compression


#include <iostream>
#include <math.h>
#include <conio.h>
#include <stdio.h>
#include <graphics.h>
#define PI 3.14


using namespace std;


void paint(int a,int b,int value)
{
     for(int i=0;i<20;i++)
     {
             for(int j=0;j<20;j++)
               putpixel(20*a+i,20*b+j,COLOR(value%255,value%255,value%255));
     }
}
  
int main()
{
    initwindow(160,160,"INPUT IMAGE");
    
    float P[8][8]={ 12,25,21,26,20,21,24,23,
                    63,59,55,90,109,85,69,72,
                    42,49,48,143,144,144,46,43,
                    13,58,71,122,154,106,90,69,
                    67,61,68,164,166,68,68,60,
                    79,35,60,70,77,68,58,75,
                    85,81,84,89,85,81,85,83,
                    87,79,69,68,65,76,78,94};


    float F[8][8];
   
    cout<<"\n INPUT IMAGE DATA \n");
    for(int i=0;i<8;i++)
    {
        for(int j=0;j<8;j++)
        {
            paint(i,j,P[i][j]);
            P[i][j]-=128;
            cout<<P[i][j]<<"\t";
        }
        cout<<"\n";
    }
    cout<<"\n\n NORMALIZED IMAGE DATA \n");
    initwindow(160,160,"NORMALIZED IMAGE");
    for(int i=0;i<8;i++)
        for(int j=0;j<8;j++)
            paint1(i,j,P[i][j]);
    cout<<"\n\n DCT IMAGE DATA \n");
    initwindow(160,160,"DCT IMAGE");
    for(int i=0;i<8;i++)
    {
        for(int j=0;j<8;j++)
        {
            float temp=0;
            float alpha1,alpha2;
            for(int k=0;k<8;k++)
                for(int l=0;l<8;l++)
                    temp+=P[k][l]*cos((PI/8)*(k+0.5)*i)*cos((PI/8)*(l+0.5)*j);




            if(i==0)
                alpha1=0.707;
            else
                alpha1=1.0;
            if(j==0)
                alpha2=0.707;
            else
                alpha2=1.0;
            F[i][j]=0.25*alpha1*alpha2*temp;
            cout<<int(F[i][j])<<"\t";
            paint(i,j,F[i][j]);
        }
        cout<<"\n";
    }    
    while( !kbhit() ); 
    closegraph( );
    return( 0 );
}

No comments:

Post a Comment