將一張大小為512*512的RAW檔裡的RGB值及YUV值抽取出來各成為一張圖片
其中RAW檔裡資料的排列方式為藍、綠、紅、藍、綠、紅....
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<cmath>
其中RAW檔裡資料的排列方式為藍、綠、紅、藍、綠、紅....
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<cmath>
int main()
{
int i;
FILE *orimage=fopen("desert.raw", "rb"); //輸入檔為一張RAW檔
unsigned char buffer[786432]; //512*512*3
{
int i;
FILE *orimage=fopen("desert.raw", "rb"); //輸入檔為一張RAW檔
unsigned char buffer[786432]; //512*512*3
FILE *blue=fopen("desertRed.raw", "wb");
FILE *green=fopen("desertGreen.raw", "wb");
FILE *red=fopen("desertBlue.raw", "wb");
FILE *y=fopen("deserty.raw","wb");
FILE *u=fopen("desertu.raw","wb");
FILE *v=fopen("desertv.raw","wb");
for( i=0; i<786432; i++)
{
buffer[i] = getc(orimage); //依次讀一個 byte , 三個一組 , 依序存入紅綠藍 三檔案裡
if( (i%3) == 0)
putc(buffer[i],blue);
if( (i%3) == 1)
putc(buffer[i],green);
if( (i%3) == 2)
{
putc(buffer[i],red);
putc( (buffer[i-2]*0.114 + buffer[i-1]*0.587 + buffer[i]*0.299),y); //進行YUV矩陣換算
putc( fabs(buffer[i-2]*0.437 + buffer[i-1]*(-0.289) + buffer[i]*(-0.148)),u);
putc( fabs(buffer[i-2]*(-0.100) + buffer[i-1]*(-0.515) + buffer[i]*0.615),v);
}
}
system("pause");
return 0;
}
FILE *green=fopen("desertGreen.raw", "wb");
FILE *red=fopen("desertBlue.raw", "wb");
FILE *y=fopen("deserty.raw","wb");
FILE *u=fopen("desertu.raw","wb");
FILE *v=fopen("desertv.raw","wb");
for( i=0; i<786432; i++)
{
buffer[i] = getc(orimage); //依次讀一個 byte , 三個一組 , 依序存入紅綠藍 三檔案裡
if( (i%3) == 0)
putc(buffer[i],blue);
if( (i%3) == 1)
putc(buffer[i],green);
if( (i%3) == 2)
{
putc(buffer[i],red);
putc( (buffer[i-2]*0.114 + buffer[i-1]*0.587 + buffer[i]*0.299),y); //進行YUV矩陣換算
putc( fabs(buffer[i-2]*0.437 + buffer[i-1]*(-0.289) + buffer[i]*(-0.148)),u);
putc( fabs(buffer[i-2]*(-0.100) + buffer[i-1]*(-0.515) + buffer[i]*0.615),v);
}
}
system("pause");
return 0;
}
沒有留言:
張貼留言