0. Remapping
matrix equation으로 표현할 수 없는 형태(non-linear)의 이미지 모양 변환을 위한 기능.
OpenCV에서 cv2.remap()
함수를 통해 제공되며,
- lens distortion 및
- radial distortion등을
모델링하거나 제거하는데 사용가능함.
dst = cv2.remap(src, mapx, mapy, interpolation, dst, borderMode, borderValue)
src
: 입력 이미지mapx
,mapy
: x축과 y축으로 이동할 좌표, src와 동일한 크기,dtype=float32
임.dst
: 결과 이미지, optional- 그 외 :
cv2.warpAffine()
과 동일
mapx[0][0] = 9.0
, mapy[0][0] = 3.0
인 경우,
입력 image의 (0,0)
의 픽셀이 출력에서 (9,3)
의 픽셀로 이동하게 됨.
identical mapping의 경우는 다음과 같이 처리하면 됨. (초기화로 많이 사용됨)
mapy, mapx = np.indices( (rows,cols), dtype = float)
1. Radial distortion
일반적으로 렌즈의 굴절률로 인해 발생하며,
렌즈의 중심에서의 거리 (radial distance, 방사거리)를 독립변수로 가짐
(=distortion의 정도가 radial distance에 의해 결정됨).
다음과 같은 세 종류의 distrotion이 있음.
1.1 Barrel distortion
렌즈의 배율(magnification)이 렌즈의 중심 (optical axis)에서 멀어질수록 감소하는 경향성을 보이며,
격자 무늬가 술통(barrel)처럼 보이게 된다고 해서 Barrel distortion이라고 불림.

광각 렌즈에서 흔히 관찰되며 가운데가 볼록해 보임.
In barrel distortion, image magnification decreases with distance from the optical axis. The apparent effect is that of an image which has been mapped around a sphere (or barrel).
Barrel distortion model은 다음과 같음.
rd=ru(1−α|ru|2)↔ru=rd1−αr2d
- rd : the distance from the center of distortion (or lens) in the distorted image.
- ru : the distance from the center of distortion (of lens) in the original image.
- α : a constant specific to the distortion. (negative for barrel distortion)
Ref. : Andrew W. Fitzgibbon (2001). Simultaneous linear estimation of multiple view geometry and lens distortion
다른 모델로는 다음과 같은 수식도 있음. *** (OpenCV의 Camera Calibration에서 사용됨)
rd=ru(1+k1r2u+k2r4u)
- kp : distortion coefficient. (positive for barrel distortion).
- 예1 : k1=0.5,k2=0.2
- 예2 : k1=0.001,k2=0
Ref. : Zhang Z. (1999). Flexible camera calibration by viewing a plane from unknown orientation
1.2 Pincushion distortion
Barrel과 반대됨.
- 렌즈의 배율(magnification)이 렌즈의 중심 (optical axis, Principal point)에서 멀어질수록 증가하는 경향성을 보임.
- 핀꽂이에서 유래.

망원 렌즈에서 보이는 distortion 으로 가운데가 오목하게 들어가 보임.
In pincushion distortion, image magnification increases with the distance from the optical axis. The visible effect is that lines that do not go through the centre of the image are bowed inwards, towards the centre of the image, like a pincushion.
수학적 모델은 다음 수식에서 α가 positive임.
rd=ru(1−α|ru|2)↔ru=rd1−αr2d
- rd : the distance from the center of distortion (or lens) in the distorted image.
- ru : the distance from the center of distortion (of lens) in the original image.
- α : a constant specific to the distortion. (positive for pincushion distortion)
1.3 Mustache distortion.
barrel distortion과 pincushion distortion의 mixture임.
complex distortion이라고도 불림.
- 이미지의 중앙에서는 barrel distortion과 비슷하다가
- 중심에서 멀어질수록 점차적 pincushion distion의 경향성을 뜀.

Mustache 라는 이름은 중간에서 위로 1/2 정도 지점의 왜곡이 마치 콧수염처럼 보이는 것에서 유래됨.
A mixture of both types, sometimes referred to as mustache distortion (moustache distortion) or complex distortion, is less common but not rare. It starts out as barrel distortion close to the image center and gradually turns into pincushion distortion towards the image periphery, making horizontal lines in the top half of the frame look like a handlebar mustache.
2. Python code
Andrew W. Fitzgibbon (2001)의 모델을 통해 barrel distortion과 pincushion distortion을 구현함.
https://gist.github.com/dsaint31x/023aa5d9ac08ce547128301fbeef18c2
dip_distortion_barrrel_pincushion.ipynb
dip_distortion_barrrel_pincushion.ipynb. GitHub Gist: instantly share code, notes, and snippets.
gist.github.com
참고 : Optical axis 란?

참고 : Lenna 이미지
레나 (이미지) - 위키백과, 우리 모두의 백과사전
위키백과, 우리 모두의 백과사전. 레나 레나(Lenna 또는 Lena)는 플레이보이 잡지 1972년 11월자의 센터폴드에 실린 스웨덴의 모델인 레나 포르센(1951년 3월 31일 - )의 사진의 일부분을 말한다. 얼굴과
ko.wikipedia.org
2024.09.10 - [Programming/DIP] - [DIP] Tangential Distortion (접선왜곡)
[DIP] Tangential Distortion (접선왜곡)
접선 왜곡(Tangential distortion)은 일반적인 렌즈를 사용하는 광학 시스템에서 발생하는 렌즈 왜곡(lens distortion)의 한 유형임. 렌즈 축에서 멀어진 객체의 위치가 왜곡되어 이미지 포인트가 이상적
dsaint31.tistory.com
'Programming > DIP' 카테고리의 다른 글
[DIP] Image Quality 관련 정량화 지표들: Resolution, Contrast, SNR (0) | 2023.10.04 |
---|---|
[DIP] Function plot and Image display (0) | 2023.09.26 |
[DIP] Basic Operations (on a binary image) for Morphological Operations (0) | 2023.05.11 |
[OpenCV] imshow 창설정 및 종료 처리 (x버튼 처리) (0) | 2023.04.07 |
[OpenCV] Desired Data Type : ddtype (0) | 2023.04.03 |