Contents

Develop
2016.10.15 12:24

[matlab] ZigZag-Scanning (2-D Array)

조회 수 1970 댓글 0
Atachment
첨부 '12'
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

[MatLab] ZigZag-Scanning (2-D Array)


# ZigZag-Scanning 과제 내용

주어진 2차원 배열을 다음 그림과 같이 지그재그 형태로 탐색하여 1차원 배열의 결과물을 만드는 MatLab 코드를 만들어야 함.


zigzag.png

[이미지] https://en.wikipedia.org/wiki/JPEG

[참고] https://en.wikipedia.org/wiki/File:JPEG_ZigZag.svg



# MatLab 실행 영상



# 구현 방법

다음과 같은 2차원(3x3) 배열 Q가 있다고 할 때,


no_01.png



1. 원본 Q 배열의 좌/우를 뒤집는다. (fliplr() 함수 사용)

결과는 다음 afterFliplr1 과 같다.


no_02.png



2. 위의 1번의 결과 배열에서 대각 배열을 만든다. (spdiags() 함수 사용)

결과는 다음 afterSpdiags 와 같다.


no_03.png



3. 위의 2번의 결과 배열의 좌/우를 뒤집는다. (fliplr() 함수 사용)

결과는 다음 afterFliplr2 와 같다.


no_04.png



4. 위의 3번의 결과 배열의 홀수번째 컬럼의 위/아래를 뒤집는다. (flipud()함수 사용)

결과는 다음 afterFlipud 과 같다.


no_05.png



5. 위의 5번의 결과 배열에서 0을 제거하고 1차원 배열로 출력한다.

결과는 다음 orderNonZero 와 같다.


no_06.png


6. 위의 5번의 결과는 Q 배열을 탐색하는 인덱스의 순서이다.

MatLab에서 배열 인덱스는 1부터 시작하므로, 

원본 Q 배열을 orderNonZero 인덱스의 순서대로 탐색하여 Zig-Zag 1차원 배열을 만들 수 있다.

결과는 다음 ZigZag 와 같다.


no_07.png



# MatLab 소스코드 (Ver.1)

clear all; clc;

%% Test elements #1
Q = [1 2 3;
     4 5 6;
     7 8 9];
%% Test elements #2
Q = [01 02 06 07;
     03 05 08 13;
     04 09 12 14;
     10 11 15 16];
 
%% Init
tmp = reshape(1:numel(Q), size(Q));

%% Flip left/right -> Diagonal matrix -> Flip left/right again
afterFliplr1 = fliplr( tmp );
afterSpdiags = spdiags( afterFliplr1 );
afterFliplr2 = fliplr( afterSpdiags );

%% Flip up/down(odd columns)
afterFlipudOdd = afterFliplr2;
afterFlipudOdd(:,1:2:end) = flipud( afterFliplr2(:,1:2:end) );

%% Remove zero
orderNonZero = afterFlipudOdd;
orderNonZero( orderNonZero==0 ) = [];

%% Get elements (by zigzag-order)
ZigZag = Q(orderNonZero)

%keyboard



# MatLab 소스코드 (Ver.2)

clear all;
clc;

%% ZigZag %%

%% Test array1
Q = [1 2 3;
     4 5 6;
     7 8 9];
%% Test array2
Q = [01 02 06 07;
     03 05 08 13;
     04 09 12 14;
     10 11 15 16];

%% Init
tmp = reshape(1:numel(Q), size(Q));

%% Flip left/right -> Diagonal matrix -> Flip left/right again
order = fliplr( spdiags( fliplr(tmp) ) );

%% Flip up/down(odd columns)
order(:,1:2:end) = flipud( order(:,1:2:end) );

%% Remove zero
order(order==0) = [];

%% Get elements (by zigzag-order)
ZigZag = Q(order)

keyboard


# 관련 함수 설명

reshape.png


fliplr.png


spdiags.png


flipud.png



TAG •

?

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
781 Develop [ios] 비디오,네트워크,소셜로그인 테스트 file hooni 2017.04.04 672
780 Develop [ios] Xcode에서 특정 파일만 ARC 따로 설정하는 방법 file hooni 2017.03.29 931
779 Develop 사이버보안실무 수업 메모 secret hooni 2017.03.23 0
778 Develop Mac OS 에 Jenkins 설치하기 (Homebrew) 2 file hooni 2017.03.15 8050
777 Develop [ios] 동영상 플레이어 샘플 (for PIP Player) file hooni 2017.03.15 1245
776 Develop [js] Javascript로 만든 포트리스 (2010) 5 file hooni 2017.03.03 2279
775 Develop [ios] Facebook Cache 갱신하는 함수 file hooni 2017.02.27 1165
774 Develop [ios] 동영상 플레이어 샘플 (for Remote Url) file hooni 2017.02.07 1629
773 Develop [ios] 동영상 플레이어 샘플 (for Local File) file hooni 2017.02.07 1059
772 Develop XML, JSON, BSON, MSGPACK 장,단점 비교 file hooni 2017.01.11 2228
771 Develop [android] 버전 별 앱 알림 설정으로 이동하는 방법 file hooni 2016.11.28 2146
770 Develop [ios] FlckrFeed Example App (Swift) file hooni 2016.11.27 1061
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 71 Next
/ 71