Home > Back-end >  RGB to yuv
RGB to yuv

Time:10-07

Why did the RGB to YUV program after the operation showed wrong? Who help me to see what was wrong?

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "stdafx. H"
#include
#include
#include
#include
#include

Definition/* */
# define HIGH 255
# define LOW 0
# define LEVEL 256
176//# define SIZEX column image size
220//# define SIZEY row image size
# define SUC sizeof (unsigned char)
# define READ 0
# define the WRITE 1


Void GetFilename (char * name, char * message);
The FILE * FileOpen (char * filename, int opmode);
Void ReadImageData (FILE * file_p);
Void WriteImageData (FILE * file_p);
Void Calculate (int q []);
Void the Histogram (long hist []);
Void Equalization (long hist [], int q []);

Unsigned char image_in [SIZEX SIZEY * * 3];
Unsigned char image_out [SIZEX SIZEY * * 3];
The float [SIZEX SIZEY], Y U [SIZEX SIZEY], V [SIZEX SIZEY *];
Float Y_out [SIZEX SIZEY *];//the Histogram Equalization, Y ailing


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* the MAIN FUNCTION */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Int main ()
{
In the FILE * and * out;

Char source [20], destin [20].
Char * mes1="Input Data File Name===& gt; \ t ";
Char * mes2="Output Data File Name===& gt; \ 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 & lt; * 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
[I] Y=0.3 + 0.59 * * Red [I], [I] + 0.11 * Blue [I];
U [I]=(Blue [I] - [I] Y) * 0.493;
V [I]=(Red [I] - [I] Y) * 0.877;

}

for(i=0; I & lt; * SIZEX SIZEY. I++)
{//YUV to RGB conversion
Red [I]=Y_out [I] + 0.956 + 0.621 * * U [I] V [I];
Green=Y_out [I] [I] + 0.272 + 0.647 * * U [I] V [I];
Blue [I]=Y_out [I] + 1.1061 + 1.703 * * U [I] V [I];
}

for(i=0; I & lt; SIZEX SIZEY *; I++)
{//R, G, B blind the clear aperture moving qin
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); The scanf (" % s ", name);
}

The FILE * FileOpen (char * filename, int opmode)
{
The 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 the opened */
Printf (" the 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 & lt; SIZEX SIZEY * * 3; Y_Count + +)
{
The fscanf (file_p, "% c", & amp; Temp);
Image_in [Y_Count]=temp;
}

}

Void WriteImageData (FILE * file_p)
{
Int Y_Count;

For (Y_Count=0; Y_Count & lt; SIZEX SIZEY * * 3; Y_Count + +)
{
Fprintf (file_p, "% c", image_out [Y_Count]);
}
}



CodePudding user response:

What is wrong, the mistake?

CodePudding user response:

Don't Y_out assignment?
  • Related