이진 영상 B[i,j]에 대해서, B[i,j] = 1 if F[i,j]<=70 0 otherwise
1. B[i,j]=1인 영역의 중심좌표를 구하시오.
2. B[i,j]=1인 영역의 방향(orientation)을 구하시오.
3. B[i,j]=1인 영역의 Elongation(장축길이/단축길이)을 구하시오
< 원본 영상 >
< 처리 결과 >
- 주요 소스 코드
pgm파일 읽어오는 소스 및 이진화 하는 소스 생략
for(i=0; i < rows; i++){ for(j=0; j < cols; j++){ if (buffer[i*cols+j] <=70){ //70보다 작거나 같을 경우 sum_x += j; //행 증가 sum_y += i; //열 증가 area++; //픽셀 수 증가 } } } x = sum_x/area; //x의 중심좌표 계산 y = sum_y/area; //y의 중심좌표 계산 /* orientation, elongation 계산하기*/ for(i=0;i< rows ;i++){//행증가 for(j=0;j< cols;j++){//열 증가 if(buffer[i*cols +j] <=70){ i_x+=(j-x)*(j-x); //대입 i_y+=(i-y)*(i-y); i_xy+=(j-x)*(i-y); } } } t =0.5*atan((2*i_xy)/(i_x-i_y)); //각각 계산 n_max = (i_x + i_y + sqrt(4*i_xy*i_xy + (i_x-i_y)*(i_x-i_y))); n_min = (i_x + i_y - sqrt(4*i_xy*i_xy + (i_x-i_y)*(i_x-i_y))); printf("중심좌표 : (%f,%f)\n",x,y); //무게 중심 출력하기 printf("orientaion : %f \n",t); //orientation 출력하기 printf("elongation : %f \n",sqrt(n_max)/sqrt(n_min));//elongation출력하기 }
'컴퓨터비전' 카테고리의 다른 글
7. Template matching (0) | 2015.09.17 |
---|---|
6. Iterative thresholding / Otsu's thresholding (0) | 2015.09.17 |
5. Morphology (0) | 2015.09.17 |
4. boundary following (0) | 2015.09.17 |
3. connected component labelling (0) | 2015.09.17 |