[TIL]230314 - 영상처리 2주차: 영상 파일 형식(2) Raw data 실습

Jimin·2023년 3월 14일
0
post-thumbnail

  • file header가 없기 때문에 file size(height, width) 직접 설정하고 컬러 채널, 파일 구조도 함께 설정해줘야 함

Black-White

void rawBw()
{	// Image Set
	for (int i = 0; i < H; i++)
		for (int j = 0; j < W; j++)
			bwImg[i][j] = (BYTE)(255.*i / (H - 1));

	// Image Write
	FILE *out = fopen("bwImg.raw", "wb");
	fwrite(bwImg, sizeof(char), H*W, out);//or fputc/putc with for loop
	fclose(out);
}

Interleaved color

void rawColor()
{	// Image Set
	for (int i = 0; i < H; i++)
		for (int j = 0; j < W; j++){
			if (j < W / 3)
				colorImgI[i][j][0] = 255;
			else if (j>(W * 2) / 3)
				colorImgI[i][j][2] = 255;
			else
 				colorImgI[i][j][1] = 255;
			}
	// Image Write
	FILE *out = fopen("colorImg.raw", "wb");
	fwrite(colorImgI, sizeof(char), H*W * 3, out);
	fclose(out);
}

planar color

void rawColorP()
{	// Image Set
	for (int i = 0; i < H; i++)
	for (int j = 0; j < W; j++){
		if (j < W / 3)
			colorImgP[0][i][j] = 255;
		else if (j>(W * 2) / 3)
			colorImgP[2][i][j] = 255;
		else
			colorImgP[1][i][j] = 255;
	}
	// Image Write
	FILE *out = fopen("colorImgP.raw", "wb");
	fwrite(colorImgP, sizeof(char), H*W * 3, out);
	fclose(out);
}

빨간색만 보이게 하는 방법

  • Green, Blue를 0으로 설정
	for (int i = 0; i < H; i++)
		for (int j = 0; j < W; j++){
			if (j < W / 3)
				colorImgI[i][j][0] = 255;
//			else if (j>(W * 2) / 3)
//				colorImgI[i][j][2] = 255;
//			else
// 				colorImgI[i][j][1] = 255;
			}

Pxm 파일 형식

  1. PPM file format
  • PPM(Portable Pix Map)파일 형식은 uncompressed(비압축)/interleaved 방식의 24-bit true color를 지원하는 가장 단순한 이미지 표현 방식임
  • 2개의 부분(file header/file body)로 구성됨

  • 파일 헤더는 항상 text(ASCII) 형식이며, magic no.가 P3이면 text(ASCII) 형식의 파일 본체를 의미함
  • P6은 파일 본체를 Binary 형식을 사용하므로 전체 파일 용량이 작아서 많이 활용됨

0개의 댓글