YUV 4:2:0(IMC3)图像处理 [英] YUV 4:2:0 (IMC3)image processing
问题描述
亲爱的先生, Dear sir, 这篇关于YUV 4:2:0(IMC3)图像处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
我有一个图像处理代码,我需要改变颜色,如饱和度,亮度或其他东西。所以你能告诉我在哪里我可以更改代码以及我需要更改代码的内容。
谢谢。
< pre lang =C ++> #include < < span class =code-leadattribute> stdio.h >
#include < stdlib.h < span class =code-keyword>>
#define WIDTH 176
#define HEIGHT 144
void NearestNeighbor( unsigned char * in , unsigned char * out, unsigned int width, unsigned int height);
void 处理( unsigned char , unsigned char * out , unsigned int width, unsigned int height);
unsigned char * yIn,* cbIn,* crIn;
unsigned char * yOut,* cbOut,* crOut;
int main( void )
{
FILE * fin,* fout;
unsigned char * inbuf,* outbuf;
unsigned int NoOfFrames,filesize,frame,Framesize;
if ((fin = fopen( C:\\miss-america_qcif.yuv, rb))== NULL){
printf( 错误:打开YUV文件... \ N跨度>);
返回 - 1 ;
}
if ((fout = fopen( Output.yuv, wb))== NULL ){
printf( 错误:打开输出YUV文件... \ n );
返回 - 1 ;
}
Framesize =(WIDTH * HEIGHT)*( 3 / 2 < /跨度>);
inbuf =( unsigned char *)malloc(的sizeof 跨度>(框架尺寸));
outbuf =( unsigned char *)malloc( sizeof (( 2 * WIDTH)*( 2 * HEIGHT)* 3 / 2 ));
if (inbuf == NULL){
printf( 错误:输入缓冲区的内存分配。\ n);
返回 - 1 ;
}
if (outbuf == NULL){
printf( 错误:输出缓冲区的内存分配。\ n);
返回 - 1 ;
}
yIn = inbuf;
cbIn = yIn +(WIDTH * HEIGHT);
crIn = cbIn +((WIDTH>> 1 )*(HEIGHT>> 1 < /跨度>));
yOut = outbuf;
cbOut = yOut + WIDTH * HEIGHT * 4 ;
crOut = cbOut + WIDTH * HEIGHT;
// 查找帧数
fseek(fin , 0 ,SEEK_END);
filesize = ftell(fin);
printf( filesize数量=%d \ n,filesize);
倒带(fin);
NoOfFrames = filesize / Framesize;
printf( 帧数=%d \ n,NoOfFrames);
/ * ************ ************************************************** *********
*阅读一帧&高档框架*
*对文件中的所有帧重复上述过程*
************************* *************** /
for (frame = 0 ; frame< NoOfFrames; frame ++){
fread(inbuf, sizeof ( unsigned char ),Framesize,fin);
NearestNeighbor(inbuf,outbuf,( unsigned int )WIDTH,( unsigned int )HEIGHT);
fwrite(outbuf, sizeof ( unsigned char ),Framesize * 4 ,fout);
printf( 已处理帧%d。\ n,帧);
}
fclose(fin);
fclose(fout);
return 0 ;
}
void NearestNeighbor( unsigned char * , unsigned char * out, unsigned int width, unsigned int height)
{
unsigned char * inY,* inCb,* inCr,* outY,* outCb,* outCr;
// 输入和输出的计算输出YCbCr位置
inY = in ;
inCb = inY + WIDTH * HEIGHT;
inCr = inCb +(WIDTH>> 1 )*(HEIGHT>> 1 跨度>);
outY = out;
outCb = outY + 4 * WIDTH * HEIGHT;
outCr = outCb + WIDTH * HEIGHT;
// 处理亮度(Y)
流程( inY,outY,width,height);
// 处理色度(CbCr)
流程(inCb,outCb, width>> 1 ,height>> 1 );
处理(inCr,outCr,宽度>> 1 ,height>> 1 );
return ;
}
void 流程( unsigned char * , unsigned char * out, unsigned int width, unsigned int height)
{
unsigned int row,col;
for (row = 0 ; row< height; row ++){
for (col = 0 ; col< width; col ++){
* out ++ = * in ;
*(out + 2 * width)= * in ;
*(out + 2 * width - 1 )= * 中跨度>;
* out ++ = * in ++;
}
out + = 2 * width;
}
return ;
}
我的尝试:
我只显示未完成的图像处理嗨吉里,
它不是由我而是我理解代码。问你们有人改变图像的颜色,就像CCSv6.2使用DSP KIT DM6437而不是问你的决定。
谢谢你。
I have a code for image processing,i need to change COLOR like saturation,brightness,or something else.so can you tell me where i can change the code and what i need to change my code.
thank you.
#include<stdio.h>
#include<stdlib.h>
#define WIDTH 176
#define HEIGHT 144
void NearestNeighbor(unsigned char *in, unsigned char *out, unsigned int width, unsigned int height);
void Process(unsigned char *in, unsigned char *out, unsigned int width, unsigned int height);
unsigned char *yIn, *cbIn, *crIn;
unsigned char *yOut, *cbOut, *crOut;
int main(void)
{
FILE *fin, *fout;
unsigned char *inbuf, *outbuf;
unsigned int NoOfFrames, filesize, frame, Framesize;
if ((fin = fopen("C:\\miss-america_qcif.yuv", "rb")) == NULL) {
printf ("Error: Opening YUV file...\n");
return -1;
}
if ((fout = fopen("Output.yuv", "wb")) == NULL) {
printf ("Error: Opening output YUV file...\n");
return -1;
}
Framesize =( WIDTH * HEIGHT) * (3 / 2);
inbuf = (unsigned char*) malloc(sizeof(Framesize));
outbuf = (unsigned char*) malloc(sizeof((2 * WIDTH) * (2 * HEIGHT) * 3 / 2));
if (inbuf == NULL) {
printf ("Error: Memory allocation of Input buffer.\n");
return -1;
}
if (outbuf == NULL) {
printf ("Error: Memory allocation of Output buffer.\n");
return -1;
}
yIn = inbuf;
cbIn = yIn + (WIDTH * HEIGHT);
crIn = cbIn + ((WIDTH >> 1) * (HEIGHT >> 1));
yOut = outbuf;
cbOut = yOut + WIDTH * HEIGHT * 4;
crOut = cbOut + WIDTH * HEIGHT;
// Finding the Number of Frames
fseek(fin, 0, SEEK_END);
filesize = ftell(fin);
printf ("Number of filesize = %d\n", filesize);
rewind(fin);
NoOfFrames = filesize / Framesize;
printf ("Number of Frames = %d\n", NoOfFrames);
/************************************************************************
* Read one frame & upscale the frame *
* Repeat the above process for all the frames in the file *
************************************************************************/
for (frame = 0; frame < NoOfFrames; frame++) {
fread(inbuf, sizeof(unsigned char), Framesize, fin);
NearestNeighbor(inbuf, outbuf, (unsigned int) WIDTH, (unsigned int) HEIGHT);
fwrite(outbuf, sizeof(unsigned char), Framesize * 4, fout);
printf ("Processed Frame %d.\n", frame);
}
fclose(fin);
fclose(fout);
return 0;
}
void NearestNeighbor(unsigned char *in, unsigned char *out, unsigned int width, unsigned int height)
{
unsigned char *inY, *inCb, *inCr, *outY, *outCb, *outCr;
// Calculation of Input & Output YCbCr positions
inY = in;
inCb = inY + WIDTH * HEIGHT;
inCr = inCb + (WIDTH >> 1) * (HEIGHT >> 1);
outY = out;
outCb = outY + 4 * WIDTH * HEIGHT;
outCr = outCb + WIDTH * HEIGHT;
// Processing the Luminance(Y)
Process(inY, outY, width, height);
// Process the Chrominance(CbCr)
Process(inCb, outCb, width >> 1, height >> 1);
Process(inCr, outCr, width >> 1, height >> 1);
return;
}
void Process(unsigned char *in, unsigned char *out, unsigned int width, unsigned int height)
{
unsigned int row, col;
for (row = 0; row < height; row++) {
for (col = 0; col < width; col++) {
*out++ = *in;
*(out + 2 * width) = *in;
*(out + 2 * width - 1) = *in;
*out++ = *in++;
}
out += 2 * width;
}
return;
}
What I have tried:
I diplayed only the image not done nay processingHi Giri,
Its not by me but i understood the code.Am asking to you people to change the color of the image as am CCSv6.2 WITH DSP KIT DM6437 and not asking your decisions.
thank you.