http://winmerge.org/

소스의 변경된 부분을 쉽게 파악 가능


참고

http://blog.naver.com/reinstate10/220144595705

Posted by 우주여행가
,

imshow가 처리하는 데이터 타입형은 uint8 형 또는 [0,1] 사이의 값을 갖는 double 형이다.


double 형 data의 범위를 꼭 [0,1] 사이로 정규화 하여야 한다.


예를 들어 N장의 uint8 영상의 평균값을 구하면,


평균영상을 double 형으로 선언하였다면,


이 영상에 N개의 영상의 합계를 저장하고, 영상을 255*N 으로 나누어야 한다. 


(N : 평균을 구하기 위해, 255 : 0~1 정규화하기 위해)

Posted by 우주여행가
,

특정 폴더 내의 특정 파일을 모두 불러오고 싶은 경우

(폴더 내의 이미지를 모두 불러오기 등)


dir 명령어를 쓰면 손쉽게 해결할 수 있다.


디렉토리 경로 밑에 '*.확장자' 를 붙여주면 끝.





list = dir('D:\Pictures\*.jpg');

N = size(list,1);


for i=1:N

 fn = ['D:\Pictures\ list(i).name];

IM= imread(fn);

~~

~~


end





Posted by 우주여행가
,

MATLAB에서 대규모의 영상에 대해, 결과를 직접 눈으로 검토해야 할 경우가 있다.


예를 들어, 얼굴검출 결과를 본다거나, tone mapping 결과를 본다거나...



이때 보통 for문 안에서


pause 함수를 써서 몇초간 기다렸다가 다음 영상의 결과를 볼 수도 있지만


(pause(n)  : pause for 5 seconds)


대부분의 결과 영상은 빨리 넘기고, 특정 영상은 자세히 관찰해야하는 경우와 같이


for문 안에서 그림을 넘기는 시점을 직접 제어해야 편리할 때가 있다.


이때는 waitforbuttonpress 함수를 써보자.






for i=1:N


% image processing

% algorithm


% 결과 display

figure;

imshow(I)


% 사용자가 버튼을 누를때, 다음 영상으로 이동

waitforbuttonpress;


end





MATLAB의 설명


 WAITFORBUTTONPRESS Wait for key/buttonpress over figure.

    T = WAITFORBUTTONPRESS stops program execution until a key or

    mouse button is pressed over a figure window.  Returns 0

    when terminated by a mouse buttonpress, or 1 when terminated

    by a keypress.  Additional information about the terminating

    event is available from the current figure.

 

    Example:

        f = figure;

        disp('This will print immediately');

        keydown = waitforbuttonpress;

        if (keydown == 0)

            disp('Mouse button was pressed');

        else

            disp('Key was pressed');

        end

        close(f);




Posted by 우주여행가
,

연구용 이미지 DB를 수집 중인데,


특정 사이트의 공개된 DB에 실제 이미지 파일 대신, URL만 적혀있는 경우가 있었다.


MATLAB으로 간편하게, URL 리스트를 입력받아 로컬에 저장하면, 손쉽게 DB를 모을 수 있다.


여기서는 urlread , urlwrite, fileparts 함수 등을 이용하였다.



url_list : url이 담긴 리스트

N : url 리스트의 길이






 for i=1:N

       url = url_list(i);         

       X = [ '[',num2str(i) ,'/', num2str(N), ']',':', url];

       disp(X);        

     

       [path, name, ext] = fileparts(url);

       name = [name ext];

       [S , STATUS] = urlread(url);

       if STATUS == 1

        urlwrite(url,name);

       end

   end





모든 url에 실제 파일이 존재하면 urlread는 사용하지 않아도 무방하지만, 


url 리스트에 있는 일부 url에 실제 파일이 존재하지 않을 경우 urlwrite에서 오류가 나서 


loop를 빠져나오기 때문에,


파일의 실제 존재 여부를 확인하기 위해서 urlread로 STATUS를 알아내고,


STATUS가 1인 경우에만, 즉 파일이 존재할 경우에만 파일로 저장하였다.


fileparts 함수는 url 에서 파일이름을 추출할때 사용하였다.


예를 들어 아래 URL에서 파일이름만 따올 경우 

http://assets0.chictopia.com/photos/Amber_Randell/6454092040/geometric-print-motel-rocks-dress-striped-zara-blazer-charlotte-russe-purse_400.jpg


파일이름을 fileparts를 이용하여

geometric-print-motel-rocks-dress-striped-zara-blazer-charlotte-russe-purse_400.jpg 로 지정하여 저장한다..



Posted by 우주여행가
,

char형 단위로 초기화 시킬 수 있기 때문에

memset으로 float형 array를 1로 초기화 하는 것은 불가능

(1바이트 단위로 값이 assign되기 때문에 , 초기화값이 다름)


http://rockdrumy.tistory.com/328

http://blog.naver.com/cor2738?Redirect=Log&logNo=150119468104

Posted by 우주여행가
,


출처 : http://jed00.blog.me/140188732903


탐색기실행

명령프롬프트에서 탐색기를 띄우기 위해 다시 마우스로 손이 가야하는 번거로움을 피하기 위해서,

start 명령을 사용할 수 있습니다.

  • start  . 은 현재디렉토리를 띄우라는 뜻
  • start 특정경로 는 특정경로의 폴더를 띄우라는 뜻

 

끝내기 

명령프롬프트에서 창을 닫기위해 x버튼을 클릭해야 하는 번거로움을 피하기 위해서,

exit 명령을 입력해서 바로 닫을 수 있습니다.

 

 

화면지우기

현재 콘솔창의 내용을 다 지우고 싶으면 cls 명령을 입력하면 됩니다.

 

 

중단/일시정지

dir C:\Windows\System32 처럼 파일이 너무 많아서 실행시간이 조금 걸릴 때 실행중단을 시킬 수 있습니다.

Ctrl + C 단축키를 누르거나 Ctrl + Break 키를 누르면 중단됩니다.

 

반면 일시중지하려면 Pause 키를 누릅니다.

다시 재개하려면 Pause, Lock(NumLock 이나 CapsLock 따위) 이외의 아무키나 누릅니다.

 

 

경로자동완성

dir "Program Files" 처럼 명령어에 입력할 경로가 너무 길다면,

앞 몇글자만 누르고 Tab 키를 누르면 자동완성이 됩니다.

  • 공백이 포함된 경로라면 큰따옴표까지 붙여줍니다.
  • Tab 키를 또 누르면 해당하는 다음 경로로 바뀝니다.
  • Shirt + Tab 은 이전 경로로 바꿉니다.

 

히스토리

 키

 기능

 위쪽 방향키

 이전에 실행한 명령을 명령프롬프트상에 찍어준다

 아래쪽 방향키

 그 다음에 실행한 명령을 명령프롬프트상에 찍어준다

 오른쪽 방향키

 방금전 실행한 명령 중 현재 캐럿위치에 해당하는 한 문자를 명령프롬프트상에 찍어준다

 F1

 방금전 실행한 명령 중 현재 캐럿위치에 해당하는 한 문자를 명령프롬프트상에 찍어준다

 F3

 방금전 실행한 명령 중 현재 캐럿위치에 해당하는 글자부터 명령프롬프트상에 찍어준다

 

 

 

 

 

입력취소

명령프롬프트에 입력하다가 취소하기 위해서는 백스페이스키나 DEL 키를 사용해도 되지만,

통째로 취소하려면 ESC 키를 누르면 됩니다.

아니면 Ctrl + C 나 Ctrl + Break 를 눌러도 됩니다.


Posted by 우주여행가
,

http://people.cs.ubc.ca/~lowe/525/matlab.html

Introduction to Matlab for Computer Vision

By David Lowe, Jan. 2012

To start Matlab in Unix use one of the following:

matlab &            % This starts the standard matlab desktop
                    % The optional "&" spins it off as separate process.

matlab -nodesktop   % Command line interface, useful for remote access
                    %   or running inside Emacs
quit                % Quits command-line interface
Warning: expect Matlab to take some time to start as its a large system.

Matlab's getting started tutorial

If you are a beginner with Matlab, first start Matlab (the desktop version), and select "MATLAB help" under the Help menu. Go through all the sections under "Getting started." Try typing and executing the examples in Matlab as you read to see how they work. This will take several hours, but provides an excellent first introduction. You can skip some of the details, such as details of plotting, but you should know where to go back for help if you need it later.

You can also read the same documentation from the Matlab documentation site but it is much better to read it while you can execute the examples.

Other ways to get online help:

   help function    % Gives help on function
   doc function     % Jumps to help documentation on function
   type function    % Shows source code for function

Quick review

Once you have finished the Matlab tutorial, the following can be cut-and-pasted into Matlab to remind you of their function:
% Entering matrices
A = [ 1, 2, 3 ]         % produces a row vector
C = [ 1 2 3 ]' 	        % commas are redundant, "'" - operator gives transpose
1:10			% a:b is a short form for [ a, a + 1, ..., b ]
1:0.2:3			% a:i:b specifies use of an increment i

% Some special matrix building functions:
zeros(2, 3)		% Matrix of zeros
ones(4, 2)		% Ones
eye(5)			% Identity matrix
rand(10,2)		% 10x2 matrix of random numbers in range [0,1]

% Indexing matrix elements
D(3, 2)			% single elements are obtained in the obvious way
D(:, 2)			% colon gives an entire column...
D(1, :)			% or row
D(:)                    % appends all columns into a single vector (useful!)
D(2:4, 6:9)		% vectors can be used to index sub-matrices
D(1:2:end, :)           % select every second row ("end" is last element)

% Matrix operations
A = [1 2 3]; B = [1 0 -1];
A + B                   % Vector addition
A + 100			% Scalars can be added to each element
A * B'                  % Dot product
A' * B                  % Outer product is a matrix
A .* B                  % Use the "." to specify pointwise operations
[1:10] .^ 2		% Square each number from 1 to 10
D = rand(5,3)           % Create array of random numbers
sum(D)                  % Sum columns of D
sum(D(:))               % Sum all the elements in D
help elfun		% List of all elementary functions (exp,round,etc...)

% Plotting and Printing
X = 1:10;
Y = X .^ 2;
plot(X, Y);		% "plot" can plot 2-D data in many convenient ways
figure;                 % Start a new figure (otherwise previous is replaced)
plot(X, Y, 'r+');	% Uses red "+"s as markers
X = [-6:0.1:6]';        
Y = [sin(X), 2 * cos(X), 3 * abs(cos(X))];   % Plot 3 functions at once
plot(Y);
doc plot		% Look here for details

% Writing your own functions
% Using your favorite text editor, place the following 2 lines into a file
%   called test.m in current directory:
function r = test(m)
    r = [m m];         % Append two copies of the matrix m
% Now you can call the function from Matlab (it can use any *.m files in
%   the current directory or other directories you place in its path)
test([1 2; 3 4])

% If you edit a file using your own editor, Matlab may not notice the
%    change unless you enter the following command to reinitialize.
clear all;

Images in Matlab

We will use functions from the image-processing toolbox in Matlab as it provides simpler routines for displaying images, but all of the following could also be done in basic Matlab using other routines.

The "imread" function reads an image from a file. The file location is specified relative to current directory or by giving its full path. Matlab can read most common image file formats, such as tif, jpg, and ppm. The imread function returns the image in an 8-bit format. Most other Matlab commands require floats, so the first step is usually to convert to double.

im = imread('cameraman.tif');  % This image is already available in Matlab
im2 = im2double(im);           % Convert to double for processing
   im2 = rgb2gray(im2);        % Optional for color image: convert to grayscale
imshow(im2);                   % Display the image

im3 = im2 + 0.2;               % Make image brighter
imshow(im3);
imwrite(im3, 'bright.jpg');    % Writes to file (file extension gives format)

box = ones(5,5);               % Create simple 5x5 box filter
box = box / sum(box(:));       % Normalize filter elements to sum to 1
im4 = conv2(im2, box, 'same'); % Convolve with image and keep size 'same'
imshow(im4);                   % View blurred image


Posted by 우주여행가
,

%%# Read an image
I = imread('peppers.png');
%# Create the gaussian filter with hsize = [5 5] and sigma = 2
G = fspecial('gaussian',[5 5],2);
%# Filter it
Ig = imfilter(I,G,'same');
%# Display
imshow(Ig)

Posted by 우주여행가
,

http://www.mathworks.co.kr/kr/help/images/ref/imnoise.html


imnoise

Add noise to image

Syntax

J = imnoise(I,type)
J = imnoise(I,type,parameters
J = imnoise(I,'gaussian',m,v)
J = imnoise(I,'localvar',V)
J = imnoise(I,'localvar',image_intensity,var)
J = imnoise(I,'poisson')
J = imnoise(I,'salt & pepper',d)
J = imnoise(I,'speckle',v)

Description

J = imnoise(I,type) adds noise of a given type to the intensity image Itype is a string that can have one of these values.

Value

Description

'gaussian'

Gaussian white noise with constant mean and variance

'localvar'

Zero-mean Gaussian white noise with an intensity-dependent variance

'poisson'

Poisson noise

'salt & pepper'

On and off pixels

'speckle'

Multiplicative noise

J = imnoise(I,type,parametersDepending on type, you can specify additional parameters to imnoise. All numerical parameters are normalized; they correspond to operations with images with intensities ranging from 0 to 1.

J = imnoise(I,'gaussian',m,v) adds Gaussian white noise of mean m and variance v to the image I. The default is zero mean noise with 0.01 variance.

J = imnoise(I,'localvar',V) adds zero-mean, Gaussian white noise of local variance V to the image IV is an array of the same size as I.

J = imnoise(I,'localvar',image_intensity,var) adds zero-mean, Gaussian noise to an image I, where the local variance of the noise,var, is a function of the image intensity values in I. The image_intensity and var arguments are vectors of the same size, andplot(image_intensity,var) plots the functional relationship between noise variance and image intensity. The image_intensity vector must contain normalized intensity values ranging from 0 to 1.

J = imnoise(I,'poisson') generates Poisson noise from the data instead of adding artificial noise to the data. If I is double precision, then input pixel values are interpreted as means of Poisson distributions scaled up by 1e12. For example, if an input pixel has the value5.5e-12, then the corresponding output pixel will be generated from a Poisson distribution with mean of 5.5 and then scaled back down by 1e12. If I is single precision, the scale factor used is 1e6. If I is uint8 or uint16, then input pixel values are used directly without scaling. For example, if a pixel in a uint8 input has the value 10, then the corresponding output pixel will be generated from a Poisson distribution with mean 10.

J = imnoise(I,'salt & pepper',d) adds salt and pepper noise to the image I, where d is the noise density. This affects approximatelyd*numel(I) pixels. The default for d is 0.05.

J = imnoise(I,'speckle',v) adds multiplicative noise to the image I, using the equation J = I+n*I, where n is uniformly distributed random noise with mean 0 and variance v. The default for v is 0.04.

    Note   The mean and variance parameters for 'gaussian''localvar', and 'speckle' noise types are always specified as if the image were of class double in the range [0, 1]. If the input image is of class uint8 or uint16, the imnoise function converts the image todouble, adds noise according to the specified type and parameters, and then converts the noisy image back to the same class as the input.

Class Support

For most noise types, I can be of class uint8uint16int16single, or double. For Poisson noise, int16 is not allowed. The output image J is of the same class as I. If I has more than two dimensions it is treated as a multidimensional intensity image and not as an RGB image.

Examples

I = imread('eight.tif');
J = imnoise(I,'salt & pepper',0.02);
figure, imshow(I)
figure, imshow(J)

Posted by 우주여행가
,