Halcon에서는 Region과 XLD가 상호 변환 가능하다. 하지만 이러한 변환은 **"무손실"**이 아니다. XLD는 열려 있을 수 있지만, Region은 반드시 닫혀 있어야 한다 Consequently, converting an open XLD to Region and then back to XLD results in differences between the original and converted XLD.
이제 Region의 크기 조절에 대해 설명한다.
1. Region 크기 조절
Region 크기 조절은 간단하다. zoom_region 연산자를 사용하면 되는데, 함수 서명에서 ScaleWidth와 ScaleHeight는 너비와 높이의 배율 인자이다:
zoom_region(Region : RegionZoom : ScaleWidth, ScaleHeight : )
크기 조절 시 Row와 Column 좌표가 배율에 따라 확대 또는 축소된다. 따라서 크기 조절 후 Region 위치가 이동하는데, 이동을 방지하려면 다음과 같이 처리한다:
<strong>set_system ('clip_region', 'false'</strong><strong>)
zoom_region (InputRegion, ScaledRegion, </strong><strong>0.5, 0.5</strong><strong>)
area_center (InputRegion, Area, Row, Column)
area_center (ScaledRegion, Area1, Row1, Column1)
<strong>move_region (ScaledRegion, AdjustedRegion, Row - Row1, Column - Column1)</strong>
주의할 점은 Region 크기 조절 후 일부가 캔버스 외부로 나가는 경우가 자주 발생한다는 것이다. Halcon은 기본적으로 캔버스 외부의 Region을 자른다. 자르지 않으려면 프로그램 시작 부분에 **set_system ('clip_region', 'false')**를 추가하면 된다.
2. XLD 크기 조절
본 문서开头에서 분석한 바와 같이 "XLD → Region → XLD" 변환은 무손실이 아니다. 그러나 이를 감수할 수 있다면(또는 영향이 크지 않다면), XLD 크기 조절을 Region을 매개로 수행할 수 있다.
1) Region을 매개로 XLD 크기 조절
1 gen_image_const (Image, 'byte', 8200, 4200)
2 set_system ('clip_region', 'false')
3 read_contour_xld_dxf (Contours,'01.dxf', [], [], DxfStatus)
4 *Region으로 변환
5 <strong>gen_region_contour_xld (Contours, Region, 'margin')
</strong>6 *Region 크기 조절
7 <strong>zoom_region (Region, RegionZoom, 0.2, 0.2)
</strong>8 *다시 XLD로 변환
9 <strong>gen_contour_region_xld (RegionZoom, Contours2, 'border')</strong>
만약 아래와 같은 XLD는 어떻게 될까?
위 방법으로는 결과가 완전히 맞지 않는다. 다음과 같은 문제가 발생한다:
그렇다면 어떻게 처리해야 할까?
2) XLD 각 점의 좌표 값을 직접スケーリング하여 XLD 크기 조절
1 gen_image_const (Image, 'byte', 8200, 4200)
2 set_system ('clip_region', 'false')
3 read_contour_xld_dxf (Contours,'02.dxf', [], [], DxfStatus)
4 count_obj (Contours, Num)
5
6 <strong>*처리 시간 단위를 위한 XLD 점 샘플링 간격
</strong> 7 <strong>Step := 10</strong>
8 <strong>*배율
</strong> 9 <strong>Scale := 0.3</strong>
10 gen_empty_obj (ResultContours)
11 for i := 1 to Num by 1
12 select_obj (Contours, SingleContour, i)
13 <strong> get_contour_xld (SingleContour, Y, X)</strong>
14 Y1 := []
15 X1 := []
16 for j := 0 to |Y|-1 by Step
17
18 <strong> Y1:=[Y1,Y[j] * Scale]</strong>
19 <strong>X1:=[X1,X[j] * Scale]</strong>
20
21 endfor
22
23 <strong> *윤곽선이 닫혀 있는지 확인. 닫혀 있으면 마지막 점을 첫 번째 점과重合(크기 조절 후 XLD도 닫히도록)
</strong>24 <strong> test_closed_xld (SingleContour, IsClosed)</strong>
25 <strong>if (IsClosed == 1)</strong>
26 <strong>Y1:=[Y1,Y[0] * Scale]</strong>
27 <strong> X1:=[X1,X[0] * Scale]</strong>
28 <strong> endif</strong>
29
30 <strong> gen_contour_polygon_xld (PolyContour, Y1, X1)</strong>
31 smooth_contours_xld (PolyContour, SmoothedContour, 5)
32 concat_obj (ResultContours, SmoothedContour, ResultContours)
33 endfor
각 연산자 설명:
get_contour_xld (SingleContour, Y, X)는 XLD에서 일련의 점을 추출한다;
gen_contour_polygon_xld (PolyContour, Y1, X1)는 일련의 점들을 이용해 XLD를 재구성한다.
결과는 다음과 같이 나타난다: