為什么這個RGB轉YUV的程式運行后顯示的不對呢?誰幫我看看哪里錯了?
/**************************************************************************/
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <math.h>
#include <string.h>
/* definition */
#define HIGH 255
#define LOW 0
#define LEVEL 256
#define SIZEX 176 // column image size
#define SIZEY 220 // row image size
#define SUC sizeof(unsigned char)
#define READ 0
#define WRITE 1
void GetFilename(char *name, char *message);
FILE *FileOpen(char *filename, int opmode);
void ReadImageData( FILE *file_p );
void WriteImageData(FILE *file_p);
void Calculate(int q[]);
void Histogram(long hist[]);
void Equalization(long hist[],int q[]);
unsigned char image_in[SIZEY*SIZEX*3];
unsigned char image_out[SIZEY*SIZEX*3];
float Y[SIZEX*SIZEY], U[SIZEX*SIZEY], V[SIZEX*SIZEY];
float Y_out[SIZEX*SIZEY];//Histogram Equalization等 Y藹
/******************************/
/* MAIN FUNCTION */
/******************************/
int main()
{
FILE *in,*out;
char source[20],destin[20];
char *mes1 = "Input Data File Name ===>\t";
char *mes2 = "Output Data File Name ===>\t";
int i;
long hist[LEVEL] = {0,};
int q[LEVEL] = {0,};
unsigned char Red[SIZEX*SIZEY]={0,};
unsigned char Green[SIZEX*SIZEY]={0,};
unsigned char Blue[SIZEX*SIZEY]={0,};
GetFilename(source,mes1);
GetFilename(destin,mes2);
in = FileOpen(source,READ);
out = FileOpen(destin,WRITE);
ReadImageData(in);
for(i=0; i < SIZEX*SIZEY; i++){
//R, G, B
Red[i] = image_in[i*3];
Green[i] = image_in[i*3+1];
Blue[i] = image_in[i*3+2];
//RGB to YUV conversion
Y[i] = 0.3*Red[i] + 0.59*Green[i] + 0.11*Blue[i];
U[i] = (Blue[i]-Y[i]) * 0.493;
V[i] = (Red[i]-Y[i]) * 0.877;
}
for(i=0; i < SIZEX*SIZEY; i++)
{ // YUV to RGB conversion
Red[i] = Y_out[i] + 0.956*U[i] + 0.621*V[i];
Green[i] = Y_out[i] + 0.272*U[i] + 0.647*V[i];
Blue[i] = Y_out[i] + 1.1061*U[i] + 1.703*V[i];
}
for(i=0; i < SIZEY*SIZEX; i++)
{ //R, G, B 技盲澄闌 搬欽
image_out[i*3] = Red[i];
image_out[i*3+1] = Green[i];
image_out[i*3+2] = Blue[i];
}
WriteImageData(out);
fcloseall();
}
void GetFilename(char *name, char *message)
{
printf("%s", message); scanf("%s", name);
}
FILE *FileOpen(char *filename, int opmode)
{
FILE *file_p;
char *op = "";
if(opmode == WRITE) /* if you want to write */
op = "w+b";
else if(opmode == READ) /* if you want to read */
op = "r+b";
/* the part to get the input data file name */
if((file_p = fopen(filename, op)) == NULL) { /* if the file can't be opened */
printf(" File Open Error !!! \n");
exit(-1);
}
return file_p; /* return the file pointer */
}
void ReadImageData( FILE *file_p )
{
int Y_Count = 0;
unsigned char temp=0;
for(Y_Count = 0; Y_Count < SIZEX*SIZEY*3 ; Y_Count++)
{
fscanf(file_p, "%c", &temp);
image_in[Y_Count] = temp;
}
}
void WriteImageData(FILE *file_p)
{
int Y_Count;
for(Y_Count = 0; Y_Count < SIZEX*SIZEY*3; Y_Count++)
{
fprintf(file_p, "%c", image_out[Y_Count]);
}
}
uj5u.com熱心網友回復:
哪里不對,出啥錯誤?uj5u.com熱心網友回復:
Y_out沒賦值吧?轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/121003.html
標籤:基礎類
上一篇:求大神解決關于一個小數點的問題
下一篇:檔案滑動視窗協議傳輸c++
