Intelligent Interactive Media Lab. The Catholic University of Korea

Download Report

Transcript Intelligent Interactive Media Lab. The Catholic University of Korea

Computer vision
- Image and Matlab Basic
Presented by
Master Course, 1st Semester
Kim Sung Yong
Intelligent Interactive Media Lab. The Catholic University of Korea
Overview
• Image Formation
– Binary Image
– Grey Image
– Color Image
• Portable Bit Map Family
• Image Read and Write
• MATLAB
Intelligent Interactive Media Lab. The Catholic University of Korea
Image Formation (1)
• Image Formation
– Binary Image (1 bit image)
– 하나의 픽셀을 0과 1로 표현
– Grey Image (8 bit grey image)
– 각 픽셀을 0 (black) ~ 255 (white) 사이의 값으로 표현
– 256개 = 28 = 8 bit
– Color Image
• 24 bit color image
» RGB (Red, Green, Blue)로 표현
» Red 8 bit + Green 8 bit + Blue 8 bit = 24 bit
• 8 bit color image
» Color 정보를 8 bit로 줄여서 표현
Intelligent Interactive Media Lab. The Catholic University of Korea
Image Formation (2)
• Common Image File Formation
– BMP
– 압축하지 않은 이미지 파일 저장하는 형식
– Windows와 OS/2에서 기본으로 사용
– JEPG
– 가장 많이 사용되는 이미지 파일 압축 형식
– 1,600만 색상 표현 가능
– 압축으로 인한 정보 손실 존재
– GIF
– JEPG과 더불어 가장 많이 사용되는 이미지 파일 압축 형식
– JEPG에 비해 압축 효율 낮음, 256 색만 표현 가능
– PSD (For Photo Shop)
– PNG (Portable Network Graphic)
Intelligent Interactive Media Lab. The Catholic University of Korea
Overview
• Image Formation
• Portable Bit Map Family
– PGM
– PPM
• Image Read and Write
• MATLAB
Intelligent Interactive Media Lab. The Catholic University of Korea
Portable Bit Map Family (1)
• Portable Bit Map Family
– PGM (Portable Grey Map) : grey image
– PPM (Portable Pixel Map) : color image
gray
(ASCII)
– Two Type of Formation
• ASCII Formation
– P2 : grey
– P3 : color
• Binary Formation
– P4 : grey
– p5 : color
P2
512 512
255
image size
(Height x Width)
Max value
image gray
value
220 199 198 198 199 195 199 197 200 …
193 198 196 194 195 194 197 197 191 …
193 195 193 192 194 193 192 193 192 …
197 201 196 200 200 201 200 205 205 …
Intelligent Interactive Media Lab. The Catholic University of Korea
Overview
• Image Formation
• Portable Bit Map Family
• Image Read and Write
– Image Read
– Image Write
• MATLAB
Intelligent Interactive Media Lab. The Catholic University of Korea
Image Read and Write (1)
• Use Text Pad !
– LenaG.pgm
P2
512 512
255
220 199 198 198 199 195 199 197 200 198 197 197 …
gray (ASCII)
image size
Max value
193 198 196 194 195 194 197 197 191 195 194 195 …
193 195 193 192 194 193 192 193 192 195 195 196 …
197 201 196 200 200 201 200 205 205 206 206 203 …
image gray
value
Intelligent Interactive Media Lab. The Catholic University of Korea
Image Read and Write (2)
• Use Text Pad !
– LenaC.ppm
P3
512 512
255
246 210 204 240 183 173 235 183 179 235 183 179 …
color (ASCII)
image size
Max value
240 183 173 240 180 173 240 185 173 240 183 168 …
235 183 173 235 183 168 235 174 163 235 180 163 …
image value
235 178 163 235 180 168 235 178 163 240 174 158 …
R, G, B
Intelligent Interactive Media Lab. The Catholic University of Korea
Overview
•
•
•
•
Image Formation
Portable Bit Map Family
Image Read and Write
MATLAB
Intelligent Interactive Media Lab. The Catholic University of Korea
Matlab의 개요(1)
• Matlab 이란?
–
MATrix LABoratory 의 약자, 수치해석, 행렬연산, 신호처리 및 간편한 그래픽기능
등을 통합하여 고성능의 수치 계산 및 결과의 가시화 기능을 제공하는 프로그램.
–
행렬과 벡터를 기본 자료로 사용하여 기능을 수행하는 계산환경을 제공
–
기본적으로 행렬을 사용하므로 차원이 필요치 않으며 프로그래밍 언어를 사용하
지 않고도 쉽게 수치 계산을 수행
–
M-file을 사용함으로서 특정한 해를 구하는데 필요한 응용 프로그램을 손쉽게 작
성할 수 있음.
• Matlab의 구성
–
명령을 내리는 명령창
–
M-file을 작성하는 편집기
–
명령 수행 결과의 일부인 그림창
–
여러 가지 모듈을 이용하여 시뮬레이션을 수행하는 SIMULINK로 구성
Intelligent Interactive Media Lab. The Catholic University of Korea
Matlab의 실행(2)
①은 Toolbox를 보여주는 Lanch
Pad와 밑의 Workspace 탭을 선택
하면 사용된 변수들의 내용을 볼 수
있다.
②는 현재 디렉토리를 보여주고 있으며 또한
밑의 Command History 탭을 선택하면 지금
까지 입력한 명령들의 히스토리를 볼 수 있다.
③은 명령 창으로 명령을 입력하거나 프로그램을 실행
하는데 사용되는 창이다
Intelligent Interactive Media Lab. The Catholic University of Korea
Matlab 사용법(3)
• 행렬 입력의 규칙
– 원소들은 빈칸 또는 쉼표를 사용하여 분리
– 전체 원소들은 대괄호( [ ] )로 감싼다.
– 원소의 끝에 세미콜론( ; )을 붙이면 한 행의 종료를 의
미.
• 행렬의 원소들
– MATLAB에서 사용되는 임의의 표현들 (수치, 함수, 수
식, 문자 등)은 모두 행렬의 원소로 사용될 수 있다. 단
수치, 함수 또는 수식을 문자와 함께 행렬의 원소로 지
정할 수 없다
Intelligent Interactive Media Lab. The Catholic University of Korea
Matlab 사용법
–
–
–
–
–
–
Assignment = a = b (assign b to a)
Addition +
a+b
Subtraction - a - b
Multiplication * or.* a*b or a.*b
Division / or ./
a/b or a./b
Power ^ or .^
a^b or a.^b
Intelligent Interactive Media Lab. The Catholic University of Korea
Matlab 사용법(4)
• 관계 연산
– MATLAB에서는 차원이 같은 두 행렬에 대하여 적용할
수 있는 6가지의 관계연산자가 있다.
– 미만(Less Than)
<
– 이하(Less Than or Equal)
<=
– 초과(Greater Than)
>
– 이상(Greater Than or Equal)
>=
– 같음(qual To)
==
– 같지 않음(Not Equal To)
~=
Intelligent Interactive Media Lab. The Catholic University of Korea
Matlab 사용(5)
연산자
의미
&
그리고(and)
|
또는(or)
~
부정(not)
– C = A &B : 행렬 A와 행렬 B의 대응 원소들이 둘다 1일 경우에는 1을, 하나라 도
0이면 0을 돌려준다.
– C = A | B : 행렬 A와 행렬 B의 대응 원소들중 하나라도 1일 경우에는 1을, 두
원소들 중에서 둘 다 0일 경우에는 0을 돌려준다.
– B = ~A : A의 원소가 1일 경우에는 0을, 0일 경우에는 1을 돌려준다.
Intelligent Interactive Media Lab. The Catholic University of Korea
Matlab 사용법(6)
for 변수=시작값:증가분:최종값
실행문
end
Intelligent Interactive Media Lab. The Catholic University of Korea
Matlab 사용법(7)
• while 루프 : 국부적인 조건(local condition)에 따
라서 하나 이상의 문장들을 불확정적인 횟수만큼
반복하여 실행
while 국부적 조건
실행문
end
Intelligent Interactive Media Lab. The Catholic University of Korea
Matlab 사용법(8)
• break 문 : 루프를 빠져나가기 위한 명령어이다.
사용법은 단순히 루프 안에서 빠져나가기 원하는
위치에 'break'라고 쓰면 됨
• if 문 : 조건문이 참일 때 실행문을 행한다. 여기
서 '참'이란 조건문이 '0'이 아닌 수이거나 임의의
조건을 만족할 때이다.
if 조건문1
실행문1
elseif 조건문2 실행문2
Else
그외 실행문
end
Intelligent Interactive Media Lab. The Catholic University of Korea
Matlab 사용법(9)
• switch 문 : 변수나 표현에 의해서 임의의 실행문
이 선택적으로 수행
switch expression (scalar or string)
case value1
실행문1
case value2
실행문2
.....
otherwise
실행문
end
Intelligent Interactive Media Lab. The Catholic University of Korea
Matlab 사용법(10)
• 도움말 기능
– MATLAB과 관련된 대부분의 내용에 대하여 내장 도움말이 제공되
는데 아무때나 help 하고 함수명을 입력하면 MATLAB에 관한 도
움말을 얻을 수 있고 특별한 항목을 지정하여 요청하면 그 항목에
대하여 정보를 얻을 수 있다.
Intelligent Interactive Media Lab. The Catholic University of Korea
Matlab 실습(10)
• 영상에 격자 무늬를 만드세요!!
• 영상에 사각형을 그리세요!!
– Rectangle size : 100*100
– Start position : (100, 100), End position (200, 200)
• 영상에 정해진 영역을 잘라보세요!!
– Rectangle size : 100*100
– Start position : (100, 100), End position (200, 200)
• HINT : imread, imshow
Intelligent Interactive Media Lab. The Catholic University of Korea