영상처리에서 dct알고리즘 구현할 때 실행에러가 나네요..;;
가온누리
dct알고리즘에서 왜 결과가 안나올까요?질문 요약 :빌드는 되는데 실행에서 에러가 나네요. 왜 그렇죠?질문 내용 : dct알고리즘 실행하는 중 에러발생합니다.
빌드나 컴파일시에 오류나는 건 아니구요.
영상의 raw파일을 하나 생성하는데, 문제가 있는거 같아요. 코드 첨부하겠습니다.
========================================================================
#include stdio.h
#include stdlib.h
#include memory.h
#include math.h
typedef unsigned char BYTE;
#define WIDTH 256 //width size of input image
#define HEIGHT 256 //height size of input image
#define pi 3.141592
#define N 8 //blocksize
//Define Local Funtion
//Define Global Variables
void main()
{
//Local variables
FILE* fpRead = NULL;
FILE* fpWrite = NULL;
int iH = 0, iW = 0;
float temp=0;
float B[N][N] = {(0,0,0,0,0,0,0,0),
(0,0,0,0,0,0,0,0),
(0,0,0,0,0,0,0,0),
(0,0,0,0,0,0,0,0),
(0,0,0,0,0,0,0,0),
(0,0,0,0,0,0,0,0),
(0,0,0,0,0,0,0,0),
(0,0,0,0,0,0,0,0)};
BYTE* p1DInput = NULL; // 1-dimension input buffer array
BYTE* p1DOutput = NULL; // 1-dimension output buffer array
BYTE* p1DOutput_B1 = NULL; // 1-dimension output buffer array
BYTE** p2DInput = NULL; // 2-dimension input buffer array
BYTE** p2DOutput = NULL; // 2-dimension output buffer array
BYTE** p2DOutput_B1 = NULL; // 2-dimension output buffer array
//Memory Allocation for Image Buffer
p1DInput = (BYTE *)calloc(WIDTH*HEIGHT, sizeof(BYTE));
p1DOutput = (BYTE *)calloc(WIDTH*HEIGHT, sizeof(BYTE));
p1DOutput_B1 = (BYTE *)calloc(WIDTH*HEIGHT, sizeof(BYTE));
p2DInput = (BYTE **)calloc(HEIGHT,sizeof(BYTE*));
p2DOutput = (BYTE **)calloc(HEIGHT,sizeof(BYTE*));
p2DOutput_B1 = (BYTE **)calloc(HEIGHT,sizeof(BYTE*));for(iH = 0; iH HEIGHT; iH++)
{
p2DInput[iH] = &(p1DInput[iH*WIDTH]);
p2DOutput[iH] = &(p1DOutput[iH*WIDTH]);
p2DOutput_B1[iH] = &(p1DOutput_B1[iH*WIDTH]);
}
//File Open for Image Reading and Writing
fpRead = fopen(Peppers.raw,r+b);
if(fpRead == NULL)
{
printf(Read file open error!\n);
return;
}
fpWrite = fopen(Peppers_DCT.raw,w+b);
if(fpWrite == NULL)
{
printf(Write file open error!\n);
return;
}
//Read the Input Image
fread(p1DInput, sizeof(BYTE), WIDTH*HEIGHT, fpRead);
/////////////////////////////////////////////////////////////////
///Image Processing
/////////////////////////////////////////////////////////////////// horizontal & vertical process
for(iH = 0; iH HEIGHT; iH = iH+8)
{
for(iW = 0; iW WIDTH; iW = iW+8)
{
int u = 0, v = 0;
int j = 0, k = 0, l=0;
float cstc=0;
// 첫번째블럭부터 B 매트릭스 생성
for(u = 0; uN; u++)
{
for(j=0; jN; j++)
{
//앞의상수 규정
if(u==0)
{
cstc=sqrt(1/N);
}else {
cstc=sqrt(2/N);
}
B[u][j] = cstc*cos((2*(j+iW)+1)*u*pi/(2*N));
}
}
for(u=0; uN; u++) {
for(j=0; jN; j++) {
for(l=0; lN; l++) {
temp += p2DInput[iH+j][iW+l]*B[u][l];
}
p2DOutput[iH+u][iW+j]= temp;
}
}
for(u=0; uN; u++) {
for(j=0; jN; j++) {
for(l=0; lN; l++) {
temp += p2DOutput[iH+l][iW+j]*B[l][u];
}
p2DOutput_B1[iH+u][iW+j]= temp;
p2DOutput_B1[iH+u][iW+j]=fabs(p2DOutput_B1[iH+u][iW+j]);
p;if(p2DOutput_B1[iH+u][iW+j]255){
p2DOutput_B1[iH+u][iW+j]=255;
}
}
}
}
}
/////////////////////////////////////////////////////////////////
//Write the Output Image
fwrite(p1DOutput_B1, sizeof(BYTE), WIDTH*HEIGHT, fpWrite);
//Close the File Pointers
fclose(fpRead);
fclose(fpWrite);
//Free the Dinamic Memory Space
free(p1DInput);
free(p2DInput);
free(p1DOutput);
free(p2DOutput);
free(p1DOutput_B1);
free(p2DOutput_B1);
}