#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(int(value)%255,int(value)%255,int(value)%255)); 
     }
}
 void haar(int imgdata[][8],int wt,int ht,int numlevel)
    {
        int htrnsr[ht][wt], htrnsc[ht][wt], htindex;
        for(int level=1;level<=numlevel ;level++)
        {
            for(int i=0;i<ht;i++)
            {
                htindex=0;
                for(int j=0;j<wt;j+=2)
                {
                    htrnsr[i][htindex]=(imgdata[i][j]+imgdata[i][j+1])/2;
                    htrnsr[i][htindex+wt/2]=imgdata[i][j]-imgdata[i][j+1];
                    htindex++;
                }
            }
            for(int i=0;i<wt;i++)
            {
                htindex=0;
                for(int j=0;j<ht;j+=2)
                {
                    htrnsc[htindex][i]=(htrnsr[j][i]+htrnsr[j+1][i])/2;
                    htrnsc[htindex+ht/2][i]=htrnsr[j][i]-htrnsr[j+1][i];
                    htindex++;
                }
            }
            for(int i=0;i<ht;i++)
                for(int j=0;j<wt;j++)
                    imgdata[i][j]=htrnsc[i][j];
            wt=wt>>1;            ht=ht>>1;
        }
    initwindow(160,160,"HWT");         cout<<"\n";
    cout<<"\n HWT IMAGE DATA \n";      
    for(int i=0;i<8;i++)
    {
        for(int j=0;j<8;j++)
        {
            paint(i,j,imgdata[i][j]);            cout<<imgdata[i][j]<<"\t";
        }
        cout<<"\n";
    }
    }
int main()
{
    initwindow(160,160,"INPUT");
    int 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]);            cout<<P[i][j]<<"\t";
        }
        cout<<"\n";
    }    
    haar(P,8,8,1);    
    while( !kbhit() ); 
    closegraph( );
    getch();
    return 0;
}
No comments:
Post a Comment