๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿค– Computer Vision

์˜์ƒ์ฒ˜๋ฆฌ - ์ƒ˜ํ”Œ๋ง๊ณผ ์–‘์žํ™” / ํžˆ์Šคํ† ๊ทธ๋žจ์˜ ์ •๊ทœํ™” ํ‰ํ™œํ™” ์—ญํˆฌ์˜

์˜์ƒ์ฒ˜๋ฆฌ 

  • ์ฃผ์–ด์ง„ ๋ชฉ์ ์„ ๋‹ฌ์„ฑํ•˜๊ธฐ ์œ„ํ•ด ์›๋ž˜ ์˜์ƒ์„ ์ƒˆ๋กœ์šด ์˜์ƒ์œผ๋กœ ๋ณ€ํ™˜
  • ์ปดํ“จํ„ฐ ๋น„์ „์˜ ์ „์ฒ˜๋ฆฌ ๊ณผ์ •

 

์ƒ˜ํ”Œ๋ง๊ณผ ์–‘์žํ™”

  • 2์ฐจ์› ์˜์ƒ ๊ณต๊ฐ„์„ MxN์œผ๋กœ ์ƒ˜ํ”Œ๋ง (MxN์„ ํ•ด์ƒ๋„๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค)
  • ๋ช…์•”์„ L๋‹จ๊ณ„๋กœ ์–‘์žํ™” (L์„ ๋ช…์•” ๋‹จ๊ณ„๋ผ๊ณ  ํ•œ๋‹ค. ์ฆ‰, ๋ช…์•”์€ 0๋ถ€ํ„ฐ L-1์— ๋ถ„ํฌ๋˜์–ด ์žˆ๋‹ค. )

์œ„์˜ ์‚ฌ์ง„์€ M์ด 12, N์ด 12, ๊ทธ๋ฆฌ๊ณ  ๋ช…์•” ๋‹จ๊ณ„ L์€ 10์ธ ๊ฒฝ์šฐ์ด๋‹ค. 

(c) ๋””์ง€ํ„ธ ์˜์ƒ์„ ๋ณด๋ฉด, ๋ช…์•”์ด 0๋ถ€ํ„ฐ 9๊นŒ์ง€ ๋ถ„ํฌ๋˜์–ด ์žˆ๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค. ๋ช…์•”์ด ๊ฐ€์žฅ ๋†’์€ ๋ถ€๋ถ„์€ 9์ด๊ณ  ํฐ ๋ฐฐ๊ฒฝ์€ 0์ด๋‹ค. 

 

์˜์ƒ ์ขŒํ‘œ๊ณ„ 

  • ํ™”์†Œ ์œ„์น˜๋Š” x = (j, i) ๋˜๋Š” x = (y, x)๋กœ ํ‘œ๊ธฐํ•œ๋‹ค. 
  • ์˜์ƒ์€ f(x) ๋˜๋Š” f(j, i), 0<=j<=M-1, 0<=i<=N-1๋กœ ํ‘œ๊ธฐํ•œ๋‹ค.
  • ์ปฌ๋Ÿฌ ์˜์ƒ์€ fr(x), fg(x), fb(x)์˜ ์„ธ ์ฑ„๋„๋กœ ๊ตฌ์„ฑํ•œ๋‹ค. 

 

ํžˆ์Šคํ† ๊ทธ๋žจ

  • [0, L-1] ์‚ฌ์ด์˜ ๋ช…์•”๊ฐ’ ๊ฐ๊ฐ์ด ์˜์ƒ์— ๋ช‡ ๋ฒˆ ๋‚˜ํƒ€๋‚˜๋Š”์ง€ ํ‘œ์‹œํ•œ๋‹ค. 
  • ํžˆ์Šคํ† ๊ทธ๋žจ h์™€ ์ •๊ทœํ™” ํžˆ์Šคํ† ๊ทธ๋žจ์„ ๊ตฌํ•˜๋Š” ๊ณต์‹๊ณผ ์•Œ๊ณ ๋ฆฌ์ฆ˜

 

 

๋ช…์•” ์˜์ƒ์—์„œ ํžˆ์Šคํ† ๊ทธ๋žจ ๊ณ„์‚ฐํ•˜๋Š” ๋ฐฉ๋ฒ• 

 

 

 

ํžˆ์Šคํ† ๊ทธ๋žจ๊ณผ ์ •๊ทœํ™” ํžˆ์Šคํ† ๊ทธ๋žจ ๊ตฌํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜๊ณผ ์ฝ”๋“œ 

//ํžˆ์Šคํ† ๊ทธ๋žจ ์ดˆ๊ธฐํ™”
for (l = 0 to L-1)
	h(l) = 0;
    
    
for (j = 0 to M-1)
	for (i = 0 to N-1)	//f์˜ ํ™”์†Œ (j, i)๊ฐ๊ฐ์— ๋Œ€ํ•ด
    	h(f(j, i))++;	//๋ช…์•”๊ฐ’์— ํ—ค๋‹นํ•˜๋Š” ํžˆ์Šคํ† ๊ทธ๋žจ ์นธ์„ 1๋งŒํผ ์ฆ๊ฐ€
        
//ํžˆ์Šคํ† ๊ทธ๋žจ ์ •๊ทœํ™”
for (l = 0 to L-1)
	h'(l) = h(l) / (M*N);

 

#include <stdio.h>

#include <windows.h>



#pragma warning(disable:4996)

//์˜์ƒ์˜ ํžˆ์Šคํ† ๊ทธ๋žจ์„ ๊ตฌํ•˜๋Š” ํ•จ์ˆ˜
void IppHistogram(IppByteImage& img, float histo[256])
{
    int size = img.GetSize();
    BYTE* p = img.GetPixels();

    // ํžˆ์Šคํ† ๊ทธ๋žจ ๊ณ„์‚ฐ
    int cnt[256];
    memset(cnt, 0, sizeof(int) * 256);
    for (int i = 0; i < size; i++)
        cnt[p[i]]++;

    // ํžˆ์Šคํ† ๊ทธ๋žจ ์ •๊ทœํ™”(histogram normalization)
    for (int i = 0; i < 256; i++)
    {
        histo[i] = static_cast<float>(cnt[i]) / size;	//histo[i] = histo[i] / (256*256)
    }
}


int main() {

	FILE *fp;
	unsigned char Readbuf[256][256];
	unsigned char Writebuf[256][256];

//์˜์ƒ ์ฝ๊ธฐ //1826
	fp = fopen("lena_graycsale.bmp", "rb");	

	for (int i = 0; i < 256; i++)
		fread(Readbuf[i], 1, 256, fp);

	fclose(fp);


//์˜์ƒ ํŽธ์ง‘
	for (int i = 0; i < 256; i++)
		for (int j = 0; j < 256; j++)
			Writebuf[j][i] = Readbuf[j][i];


//ํžˆ์Šคํ† ๊ทธ๋žจ ์ •๊ทœํ™”
	for (int i = 0; i < 256; i++)
		for(int j = 0; j < 256; j++)
			histo[i][j] = histo[i][j] / (256 * 256)

//์˜์ƒ ์ €์žฅ
	fp= fopen("lena(BMP).raw", "wb");

	for (int i = 0; i < 256; i++)
		fwrite(Writebuf[i], 1, 256, fp);

	fclose(fp);


	return 0;
}

 

 

 

ํžˆ์Šคํ† ๊ทธ๋žจ ํ‰ํ™œํ™”

  • ํžˆ์Šคํ† ๊ทธ๋žจ์„ ํ‰ํ‰ํ•˜๊ฒŒ ๋งŒ๋“ค์–ด ์ฃผ๋Š” ์—ฐ์‚ฐ์ด๋‹ค.
  • ๋ช…์•”์˜ ๋™์  ๋ฒ”์œ„๋ฅผ ํ™•์žฅํ•˜์—ฌ ์˜์ƒ์˜ ํ’ˆ์งˆ์„ ํ–ฅ์ƒ์‹œ์ผœ์ค€๋‹ค. 
  • ๋ˆ„์  ํžˆ์Šคํ† ๊ทธ๋žจ์„ ๋งคํ•‘ ํ•จ์ˆ˜๋กœ ์‚ฌ์šฉํ•œ๋‹ค. 
  • ์˜์ƒ์„ ํ‰ํ™œํ™”ํ•˜๋ฉด ๋น„๊ต์ ์œผ๋กœ ๋™์  ๋ฒ”์œ„๊ฐ€ ๋„“์–ด์ง€๋Š” ํŠน์ง•์ด ์žˆ๋‹ค. 

 

 

ํžˆ์Šคํ† ๊ทธ๋žจ ํ‰ํ™œํ™” ์˜ˆ์ œ ๋ฌธ์ œ

 

ํ‰ํ™œํ™”๋ฅผ ํ•˜๋ฉด ๋™์  ๋ฒ”์œ„๊ฐ€ ๋„“์–ด์ง€๋ฏ€๋กœ ํ‰ํ™œํ™”๋Š” ๋ฌด์กฐ๊ฑด ์ข‹์€๊ฐ€? -> ์•„๋‹ˆ๋‹ค.  

์œ„์˜ ๊ทธ๋ฆผ์ฒ˜๋Ÿผ ํžˆ์Šคํ† ๊ทธ๋žจ ํ‰ํ™œํ™”๋ฅผ ์ ์šฉํ–ˆ์„ ๋•Œ ์‹œ๊ฐ์ ์œผ๋กœ ๋Š๋‚Œ์ด ๋‚˜๋น ์ง„ ๊ฒฝ์šฐ๋„ ์žˆ๋‹ค. 

์˜์ƒ์ฒ˜๋ฆฌ ์—ฐ์‚ฐ์€ ๋ถ„๋ณ„๋ ฅ์„ ๊ฐ€์ง€๊ณ  ํ™œ์šฉ ์—ฌ๋ถ€๋ฅผ ์ž˜ ๊ฒฐ์ •ํ•ด์•ผ ํ•œ๋‹ค. 

 

 

 

ํžˆ์Šคํ† ๊ทธ๋žจ ์—ญํˆฌ์˜

  • ํžˆ์Šคํ† ๊ทธ๋žจ์„ ๋งคํ•‘ ํ•จ์ˆ˜๋กœ ์‚ฌ์šฉํ•˜์—ฌ, ํ™”์†Œ ๊ฐ’์„ ์‹ ๋ขฐ๋„ ๊ฐ’์œผ๋กœ ๋ณ€ํ™˜
  • ์˜์ƒ์˜ ๊ฐ ํ”ฝ์…€์ด ์ฃผ์–ด์ง„ ํžˆ์Šคํ† ๊ทธ๋žจ ๋ชจ๋ธ์— ์–ผ๋งˆ๋‚˜ ์ผ์น˜ํ•˜๋Š”์ง€๋ฅผ ๊ฒ€์‚ฌํ•˜๋Š” ๋ฐฉ๋ฒ•
  • ์ž„์˜์˜ ์ƒ‰์ƒ ์˜์—ญ์„ ๊ฒ€์ถœํ•  ๋•Œ ํšจ๊ณผ์ ์ด๋‹ค.

 

 

ํžˆ์Šคํ† ๊ทธ๋žจ ์—ญํˆฌ์˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜

์—ญํˆฌ์˜ ๊ณต์‹

H์™€ S์ฑ„๋„ ์˜์ƒ์— ์ •๊ทœํ™” ๊ณต์‹์„ ์ ์šฉํ•ด์„œ ์ •๊ทœ ํžˆ์Šคํ† ๊ทธ๋žจ์„ ๋งŒ๋“ ๋‹ค. 
์—ญํˆฌ์˜ ๊ณต์‹์„ ์ ์šฉํ•œ๋‹ค. 
for (j = 0 to M-1)
	for (i = 0 to N-1)
    	o(j, i) = h'r(quantize(gH(j, i), quantize(gS(j, i)));	//์—ญํˆฌ์˜

 

 

ํžˆ์Šคํ† ๊ทธ๋žจ ์—ญํˆฌ์˜ ๊ฒฐ๊ณผ

  • ์–ผ๊ตด ์˜์—ญ์€ ๋†’์€ ์‹ ๋ขฐ๋„ ๊ฐ’, ์† ์˜์—ญ๋„ ๋†’์€ ์‹ ๋ขฐ๋„ ๊ฐ’์„ ๊ฐ€์ง„๋‹ค. 
  • ํ•œ๊ณ„ : ๋น„์Šทํ•œ ์ƒ‰ ๋ถ„ํฌ๋ฅผ ๊ฐ€์ง€๋Š” ๋‹ค๋ฅธ ๋ฌผ์ฒด๋ฅผ ๊ตฌ๋ณ„ํ•˜์ง€ ๋ชปํ•œ๋‹ค. ๊ฒ€์ถœ ๋Œ€์ƒ์ด ๊ฒจ๋กœ ์ƒ‰ ๋ถ„ํฌ๋ฅผ ๊ฐ–๋Š” ๊ฒฝ์šฐ์—๋Š” ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•  ๊ฐ€๋Šฅ์„ฑ์ด ๋†’๋‹ค. 
  • ์žฅ์  : ๋ฐฐ๊ฒฝ์„ ์กฐ์ •ํ•  ์ˆ˜ ์žˆ๋Š” ์ƒํ™ฉ์— ์ ํ•ฉํ•˜๋‹ค. ์ด๋™๊ณผ ํšŒ์ „์— ๋ถˆ๋ณ€ํ•˜๋ฉฐ ๊ฐ€๋ฆผ์— ๊ฐ•์ธํ•˜๋‹ค. 

 

728x90