2011/03 - 해당되는 글 10건
크리에이티브 커먼즈 라이선스
Creative Commons License

안드로이드에서 기본적으로 제공해주는 ListView를 수정하여 사용자가 정의하는 CustomView를 작성해본다.


 

우선 사용자가 화면에 뿌려주고자 하는 값들을 가진 데이터(MyData)클래스를 구현 한 다음 ArrayAdapter를 상속받은 새로운 어댑터(MyAdapter) 클래스를 구현한다.

ArrayAdapter를 상속받은 리스트는 다양한 메소드가 존재하지만 그 중 화면에 어떠한 방법으로 보여줄지를 결정하는 getView()메소드가 가장 중요하다.

우선 이 메소드를 오버라이딩하여 내부를 다시 구성한다.


LayoutInflater는 xml파일을 파싱해서 실제 object를 만들어 내는 역할을 한다.

그리고 같은 정보를 다시 갱신하지 않도록 하기 위해 ViewHolder클래스를 두고 태그로 저장하고 불러오는 형태로 효율을 높인다.

최종적으로 만들어진 뷰를 리턴하여 리스트에서 하나의 아이템으로 보일 수 있도록 한다.



 

저작자 표시
신고

'Study > Android' 카테고리의 다른 글

[Android: SharedPreference]  (0) 2011.04.05
[Android: Web Parsing]  (0) 2011.04.04
[Android: CustomView]  (0) 2011.03.29
[Android: ListView]  (0) 2011.03.28
[Android: Activity만들기]  (0) 2011.03.23
[Android: Media Scanner]  (0) 2011.03.23
Trackback 0 | Comment 0
크리에이티브 커먼즈 라이선스
Creative Commons License

리스트 뷰는 복수 개의 항목을 수직으로 표시하는 위젯이다.

리스트 뷰, 그리드 뷰, 스피너, 갤러리 등이 모두 항목 집합을 표시하는데 이들을 묶어서 어댑터 뷰라고 부른다. 각 위젯은 집합을 표시한다는 면에서 기능적으로 동일하지만 항목을 표시하는 방법이 다르다. 공동 조상인 AdapterView는 ViewGroup으로부터 파생되므로 어댑터 뷰는 항목에 해당하는 여러 개의 차일드 뷰를 가질 수 있다. 뿐만 아니라 리니어, 렐러티브같이 배치만 담당하는 레이아웃과는 달리 사용자와 상호작용도 처리하므로 터치나 키패드로 항목을 선택할 수도 있다.



코드에서 문자열 배열을 직접 정의하는 것은 효율적이지 못하며 관리에도 불리하다. 고정적인 문자열이라면 컬렉션이나 배열을 쓰는 것보다 리소스에 정의해 놓고 읽어와 사용하는 것이 바람직하다. 배열도 일정의 리소스이다. 패키지 탐색기의 values 노드에 arrays.xml파일을 만들고 다음 문서를 작성한다.

 

저작자 표시
신고

'Study > Android' 카테고리의 다른 글

[Android: Web Parsing]  (0) 2011.04.04
[Android: CustomView]  (0) 2011.03.29
[Android: ListView]  (0) 2011.03.28
[Android: Activity만들기]  (0) 2011.03.23
[Android: Media Scanner]  (0) 2011.03.23
[Android: 다국어 지원]  (0) 2011.03.23
Trackback 0 | Comment 0
크리에이티브 커먼즈 라이선스
Creative Commons License
안드로이드는 4개의 컴포넌트로 구성된다. 그 중 액티비티를 만드는 방법을 보려고 한다.

다음과 같은 순서로 진행한다.
  1. Activity클래스를 상속한 클래스 생성.
  2. 레이아웃을 위한 android XML파일 생성.
  3. AndroidManifest에 Activity를 등록.

 

 


저작자 표시
신고

'Study > Android' 카테고리의 다른 글

[Android: CustomView]  (0) 2011.03.29
[Android: ListView]  (0) 2011.03.28
[Android: Activity만들기]  (0) 2011.03.23
[Android: Media Scanner]  (0) 2011.03.23
[Android: 다국어 지원]  (0) 2011.03.23
[Android: 위젯의 클릭 이벤트]  (0) 2011.03.21
Trackback 0 | Comment 0
크리에이티브 커먼즈 라이선스
Creative Commons License
에뮬레이터를 사용하여 안드로이드를 개발하게 될 경우, SD카드를 설정해주고, 그 SD카드에 이미지나 음악파일을 추가하여 사용할 경우가 있다. 

이때, 파일을 추가한 후, 추가한 정보가 바로 나타나지 않을 경우가 있는데, 이런 겨우에는 Media Scanner를 이용하여 가상 SD카드를 스캔해주어야 한다. 

아래는 Media scanner에 접근 하는 방법이다. 

 
저작자 표시
신고

'Study > Android' 카테고리의 다른 글

[Android: ListView]  (0) 2011.03.28
[Android: Activity만들기]  (0) 2011.03.23
[Android: Media Scanner]  (0) 2011.03.23
[Android: 다국어 지원]  (0) 2011.03.23
[Android: 위젯의 클릭 이벤트]  (0) 2011.03.21
[Android: 이벤트 핸들러]  (0) 2010.10.16
Trackback 0 | Comment 0
크리에이티브 커먼즈 라이선스
Creative Commons License
안드로이드는 쉽게 다국어를 지원할 수 있도록 설계되어있다.
다른 언어에 대해 일일이 체크할 필요 없이 xml파일을 수정하여 추가하는 방법을 사용하면 된다.
res폴더에 values-ko(한국어)폴더를 새로 만든다.



values폴더에 들어있는 strings.xml파일을 values-ko폴더에 복사한후 다음과 같이 수정한다.


이곳까지 진행이 되었다는 프로그램 구현시 작업은 모두 끝이 났고 이제 모바일 단말에서 설정만 수정하면 사용자에게 맞는 언어로 변환되어 나타날 것이다.

다음은 모바일 단말에서 언어를 선택하는 방법이다.


 

 

 

 

저작자 표시
신고

'Study > Android' 카테고리의 다른 글

[Android: Activity만들기]  (0) 2011.03.23
[Android: Media Scanner]  (0) 2011.03.23
[Android: 다국어 지원]  (0) 2011.03.23
[Android: 위젯의 클릭 이벤트]  (0) 2011.03.21
[Android: 이벤트 핸들러]  (0) 2010.10.16
[Android: 출력]  (0) 2010.10.15
Trackback 0 | Comment 0
크리에이티브 커먼즈 라이선스
Creative Commons License


비슷한 코드가 반복되므로 리팩토링을 한다. 안드로이드는 하나의 리스터를 여러 뷰에 대해 등록하는 것을 허용한다.



액티비티가 OnClickListener 인터페이스를 직접 구현하였으므로 이 경우 리스너는 액티비티 자신인 this이다. 한 리스너를 두 버튼의 클릭 메서드로 같이 등록했으므로 어떤 버튼을 누르나 호출되는 메서드는 동일하다. 대신 onClick 메서드는 누구를 클릭했는지 View타입의 인수 v를 전달받으며 vgetId 메서드를 호출하여 클릭된 버튼을 알아내고 각 버튼별 클릭처리를 수행한다.

 

핸들러가 하나로 통합되었다는 면에서 바람직하지만 액티비티를 리스너로 사용한다는 점은 다소 부담스럽다. 최상위의 액티비티는 그대로 두고 별도의 리스너 객체를 멤버로 선언한 후 이 멤버를 리스너로 사용하는 것이 좀 더 깔끔하다.

 


위의 코드는 위젯의 리스너를 처리하는 가장 정석적인 방법이다.

저작자 표시
신고

'Study > Android' 카테고리의 다른 글

[Android: Media Scanner]  (0) 2011.03.23
[Android: 다국어 지원]  (0) 2011.03.23
[Android: 위젯의 클릭 이벤트]  (0) 2011.03.21
[Android: 이벤트 핸들러]  (0) 2010.10.16
[Android: 출력]  (0) 2010.10.15
[Android: 레이아웃(Layout)?]  (0) 2010.10.03
Trackback 0 | Comment 0
크리에이티브 커먼즈 라이선스
Creative Commons License

Explanation of parameters

Gabor filtering

This block implements one or multiple convolutions of an input image with a two-dimensional Gabor function:

equation 1.1

To visualize a Gabor function select the option "Gabor function" under "Output image". The Gabor function for the specified values of the parameters "wavelength", "orientation", "phase offset", "aspect ratio", and "bandwidth" will be calculated and displayed as an intensity map image in the output window. (Light and dark gray colors correspond to positive and negative function values, respectively.) The image in the output widow has the same size as the input image: select, for instance, input image octagon.jpg to get an output image of size 100 by 100. If lists of values are specified under "orientation(s)" and "phase offset(s)", only the first values in these lists will be used.

Two-dimensional Gabor functions were proposed by Daugman [1] to model the spatial summation properties (of the receptive fields) of simple cells in the visual cortex. They are widely used in image processing, computer vision, neuroscience and psychophysics. The parametrisaton used in Eq.(1) follows references [2-7] where further details can be found.



Wavelength (λ)

This is the wavelength of the cosine factor of the Gabor filter kernel and herewith the preferred wavelength of this filter. Its value is specified in pixels. Valid values are real numbers equal to or greater than 2. The value λ=2 should not be used in combination with phase offset φ=-90 or φ=90 because in these cases the Gabor function is sampled in its zero crossings. In order to prevent the occurence of undesired effects at the image borders, the wavelength value should be smaller than one fifth of the input image size.


The images (of size 100 x 100) on the left show Gabor filter kernels with values of the wavelength parameter of 5, 10 and 15, from left to right, respectively. The values of the other parameters are as follows: orientation 0, phase offset 0, aspect ratio 0.5, and bandwidth 1.


Orientation(s) (θ)

This parameter specifies the orientation of the normal to the parallel stripes of a Gabor function. Its value is specified in degrees. Valid values are real numbers between 0 and 360.



The images (of size 100 x 100) on the left show Gabor filter kernels with values of the orientation parameter of 0, 45 and 90, from left to right, respectively. The values of the other parameters are as follows: wavelength 10, phase offset 0, aspect ratio 0.5, and bandwidth 1.

For one single convolution, enter one orientation value and set the value of the last parameter in the block "number of orientations" to 1. 
If "number of orientations" is set to an integer value N, N >= 1, then N convolutions will be computed. The orientations of the corresponding Gabor functions are equidistantly distributed between 0 and 360 degrees in increments of 360/N, starting from the value specified under "orientation(s)". An alternative way of computing multiple convolutions for different orientations is to specify under "orientation(s)" a list of values separated by commas (e.g. 0,45,110). In this case, the value of the parameter "number of orientations" is ignored. 


Phase offset(s) (φ)

The phase offset φ in the argument of the cosine factor of the Gabor function is specified in degrees. Valid values are real numbers between -180 and 180. The values 0 and 180 correspond to center-symmetric 'center-on' and 'center-off' functions, respectively, while -90 and 90 correspond to anti-symmetric functions. All other cases correspond to asymmetric functions.

T

he images (of size 100 x 100) on the left show Gabor filter kernels with values of the phase offset parameter of 0, 180, -90 and 90 dgerees, from left to right, respectively. The values of the other parameters are as follows: wavelength 10, orientation 0, aspect ratio 0.5, and bandwidth 1.

If one single value is specified, one convolution per orientation will be computed. If a list of values is given (e.g. 0,90 which is default), multiple convolutions per orientation will be computed, one for each value in the phase offset list. 


Aspect ratio (γ)

This parameter, called more precisely the spatial aspect ratio, specifies the ellipticity of the support of the Gabor function. For γ = 1, the support is circular. For γ < 1 the support is elongated in orientation of the parallel stripes of the function. Default value is γ = 0.5.



The images (of size 100 x 100) on the left show Gabor filter kernels with values of the aspect ratio parameter of 0.5 and 1, from left to right, respectively. The values of the other parameters are as follows: wavelength 10, orientation 0, phase offset 0, and bandwidth 1.


Bandwidth (b)

The half-response spatial frequency bandwidth b (in octaves) of a Gabor filter is related to the ratio σ / λ, where σ and λ are the standard deviation of the Gaussian factor of the Gabor function and the preferred wavelength, respectively, as follows:

equation 2.1

The value of σ cannot be specified directly. It can only be changed through the bandwidth b. The bandwidth value must be specified as a real positive number. Default is 1, in which case σ and λ are connected as follows: σ = 0.56 λ. The smaller the bandwidth, the larger σ, the support of the Gabor function and the number of visible parallel excitatory and inhibitory stripe zones.


The images (of size 100 x 100) on the left show Gabor filter kernels with values of the bandwidth parameter of 0.5, 1, and 2, from left to right, respectively. The values of the other parameters are as follows: wavelength 10, orientation 0, phase offset 0, and aspect ratio 0.5.


Number of orientations

Default value is 1. If an integer value N, N >= 1, is specified then N convolutions will computed. The orientations of the corresponding Gabor functions are equidistantly distributed between 0 and 360 degrees, with increments of 360/N, starting from the value specified in "orientation(s)". For this option to work, one single value (without a comma present) must be specified for the parameter "orientation(s)".

저작자 표시
신고
Trackback 0 | Comment 1
크리에이티브 커먼즈 라이선스
Creative Commons License

 Gabor filter
 


In image processing, a Gabor filter, named after Dennis Gabor, is a linear filter used for edge detection. Frequency and orientation representations of Gabor filter are similar to those of human visual system, and it has been found to be particularly appropriate for texture representation and discrimination. In the spatial domain, a 2D Gabor filter is a Gaussian kernel function modulated by a sinusoidal plane wave. The Gabor filters are self-similar – all filters can be generated from one mother wavelet by dilation and rotation.

Its impulse response is defined by a harmonic function multiplied by a Gaussian function. Because of the multiplication-convolution property (Convolution theorem), the Fourier transform of a Gabor filter's impulse response is the convolution of the Fourier transform of the harmonic function and the Fourier transform of the Gaussian function. The filter has a real and an imaginary component representing orthogonal directions[1]. The two components may be formed into a complex number or used individually.

Complex

g(x,y;\lambda,\theta,\psi,\sigma,\gamma) = \exp\left(-\frac{x'^2+\gamma^2y'^2}{2\sigma^2}\right)\exp\left(i\left(2\pi\frac{x'}{\lambda}+\psi\right)\right)

Real

g(x,y;\lambda,\theta,\psi,\sigma,\gamma) = \exp\left(-\frac{x'^2+\gamma^2y'^2}{2\sigma^2}\right)\cos\left(2\pi\frac{x'}{\lambda}+\psi\right)

Imaginary

g(x,y;\lambda,\theta,\psi,\sigma,\gamma) = \exp\left(-\frac{x'^2+\gamma^2y'^2}{2\sigma^2}\right)\sin\left(2\pi\frac{x'}{\lambda}+\psi\right)

where

x' = x \cos\theta + y \sin\theta\,

and

y' = -x \sin\theta + y \cos\theta\,

In this equation, λ represents the wavelength of the sinusoidal factor, θ represents the orientation of the normal to the parallel stripes of a Gabor function, ψ is the phase offset, σ is the sigma of the Gaussian envelope and γ is the spatial aspect ratio, and specifies the ellipticity of the support of the Gabor function.




Wavelet space

Gabor filters are directly related to Gabor wavelets, since they can be designed for a number of dilations and rotations. However, in general, expansion is not applied for Gabor wavelets, since this requires computation of bi-orthogonal wavelets, which may be very time-consuming. Therefore, usually, a filter bank consisting of Gabor filters with various scales and rotations is created. The filters are convolved with the signal, resulting in a so-called Gabor space. This process is closely related to processes in the primary visual cortex[2]. Jones and Palmer showed that the real part of the complex Gabor function is a good fit to the receptive field weight functions found in simple cells in a cat's striate cortex[3].

The Gabor space is very useful in image processing applications such as optical character recognition, iris recognition and fingerprint recognition. Relations between activations for a specific spatial location are very distinctive between objects in an image. Furthermore, important activations can be extracted from the Gabor space in order to create a sparse object representation.




Demonstration of a Gabor filter applied to Chinese OCR. Four orientations are shown on the right 0°, 45°, 90° and 135°. The original character picture and the superposition of all four orientations are shown on the left.


저작자 표시
신고
Trackback 0 | Comment 1
크리에이티브 커먼즈 라이선스
Creative Commons License

Gaussian filter

Shape of a typical Gaussian filter

In electronics and signal processing, a Gaussian filter is a filter whose impulse response is a Gaussian function. Gaussian filters are designed to give no overshoot to a step function input while minimizing the rise and fall time. This behavior is closely connected to the fact that the Gaussian filter has the minimum possible group delay. Mathematically, a Gaussian filter modifies the input signal by convolution with a Gaussian function; this transformation is also known as the Weierstrass transform.

 

Definition

The one-dimensional Gaussian filter has an impulse response given by

g(x)= \sqrt{\frac{a}{\pi}}\cdot e^{-a \cdot x^2}

or with the standard deviation as parameter

g(x) = \frac{1}{\sqrt{2\cdot\pi}\cdot\sigma}\cdot e^{-\frac{x^2}{2\sigma^2}}

In two dimensions, it is the product of two such Gaussians, one per direction:

g(x,y) = \frac{1}{2\pi \sigma^2} e^{-\frac{x^2 + y^2}{2 \sigma^2}} [1][2][3]

where x is the distance from the origin in the horizontal axis, y is the distance from the origin in the vertical axis, and σ is the standard deviation of the Gaussian distribution.


Digital implementation

The Gaussian function is non-zero for  x \in [-\infty,\infty] and would theoretically require an infinite window length. However, since it decays rapidly, it is often reasonable to truncate the filter window and implement the filter directly for narrow windows, in effect by using a simple rectangular window function. In other cases, the truncation may introduce significant errors. Better results can be achieved by instead using a different window function; see scale space implementation for details.

Filtering involves convolution. The filter function is said to be the kernel of an integral transform. The Gaussian kernel is continuous. Most commonly, the discrete equivalent is the sampled Gaussian kernel that is produced by sampling points from the continuous Gaussian. An alternate method is to use the discrete Gaussian kernel which has superior characteristics for some purposes. Unlike the sample Gaussian kernel, the discrete Gaussian kernel is the solution to the discrete diffusion equation.

Since the Fourier transform of the Gaussian function yields a Gaussian function, the signal (preferably after being divided into overlapping windowed blocks) can be transformed with a Fast Fourier transform, multiplied with a Gaussian function and transformed back. This is the standard procedure of applying an arbitrary finite impulse response filter, with the only difference that the Fourier transform of the filter window is explicitly known.

Due to the central limit theorem, the Gaussian can be approximated by several runs of a very simple filter such as the moving average. The simple moving average corresponds to convolution with the constant B-spline, and, for example, four iterations of a moving average yields a cubic B-spline as filter window which approximates the Gaussian quite well.

Borrowing the terms from statistics, the standard deviation of a filter can be interpreted as a measure of its size. The cut-off frequency of the filter can be considered as the ratio between the sample rate Fs and the standard deviation σ

f_c = \frac{F_s}{\sigma}

A simple moving average corresponds to a uniform probability distribution and thus its filter width of size n has standard deviation \sqrt{({\sigma}^2-1)/12}. Thus m moving averages with sizes {\sigma}_1,\dots,{\sigma}_m yield a standard deviation of

\sigma = \sqrt{\frac{{\sigma}_1^2+\cdots+{\sigma}_m^2-m}{12}}.

(Note that standard deviations do not sum up, but variances do.)

When applied in two dimensions, this formula produces a Gaussian surface that has a maximum at the origin, whose contours are concentric circles with the origin as center. A two dimensional convolution matrix is precomputed from the formula and convolved with two dimensional data. Each element in the resultant matrix new value is set to a weighted average of that elements neighborhood. The focal element receives the heaviest weight (having the highest Gaussian value) and neighboring elements receive smaller weights as their distance to the focal element increases. In Image processing, each element in the matrix represents a pixel attribute such as brightness or a color intensity, and the overall effect is called Gaussian blur.

The Gaussian filter is non-causal which means the filter window is symmetric about the origin. This is usually of no consequence for most applications. In real-time systems, a delay is incurred because incoming samples need to fill the filter window before the filter can be applied to the signal.



Order

1. gaussian sigma 구하기
  - Mask size를 통해서 sigma값을 구한다.
  - sigma = (maskSize - 1) * 6.0;

2. gaussian mask를 구한다.
  - (1/ (2.0 * pi * sigma * sigma) * exp( -1 * (x * x + y * y)/ (2.0 * sigma * sigma))

3. gaussian mask의 max값을 구한다.

4. gaussian mask(RGB) weight 값을 구한다.
  - weight = 255 / max;

저작자 표시
신고
Trackback 0 | Comment 1
크리에이티브 커먼즈 라이선스
Creative Commons License

Level set method 

 
An illustration of the level set method

A very simple, yet powerful way to understand the level set method is by first studying the accompanying illustration before proceeding towards a more technical definition, which then becomes quite accessible. The figure on the right illustrates several important ideas about the level set method. In the upper-left corner we see a shape; that is, a bounded region with a well-behaved boundary. Below it, the red surface is the graph of a level set function \varphi determining this shape, and the flat blue region represents the xy plane. The boundary of the shape is then the zero level set of \varphi, while the shape itself is the set of points in the plane for which \varphi is positive (interior of the shape) or zero (at the boundary).

In the top row we see the shape changing its topology by splitting in two. It would be quite hard to describe this transformation numerically by parameterizing the boundary of the shape and following its evolution. One would need an algorithm able to detect the moment the shape splits in two, and then construct parameterizations for the two newly obtained curves. On the other hand, if we look at the bottom row, we see that the level set function merely got translated downward. We see that it is much easier to work with a shape through its level set function than with the shape directly, where we would need to watch out for all the possible deformations the shape might undergo.

Thus, in two dimensions, the level set method amounts to representing a closed curve Γ (such as the shape in our example) using an auxiliary function  \varphi , called the level set function. Γ is represented as the zero level set of  \varphi by

\Gamma = \{(x, y)|\, \varphi(x, y) = 0 \}, \,

and the level set method manipulates Γ implicitly, through the function \varphi. \varphi is assumed to take positive values inside the region delimited by the curve Γ and negative values outside.[2][3]



The level set equation

If the curve Γ moves in the normal direction with a speed v, then the level set function \varphi satisfies the level set equation

\frac{\partial\varphi}{\partial t} = v|\nabla \varphi|.

Here, |\cdot| is the Euclidean norm (denoted customarily by single bars in PDEs), and t is time. This is a partial differential equation, in particular a Hamilton-Jacobi equation, and can be solved numerically, for example by using finite differences on a Cartesian grid.[2][3]

The numerical solution of the level set equation, however, requires sophisticated techniques. Simple finite difference methods fail quickly. Upwinding methods, such as the Godunov method, fare better; however the level set method does not guarantee the conservation of the volume and the shape of the level set in an advection field that does conserve the shape and size, for example uniform or rotational velocity field. Instead, the shape of the level set may get severely distorted and the level set may vanish over several time steps. For this reason, high-order finite difference schemes are generally required, such as high-order essentially non-oscillatory (ENO) schemes, and even then, the feasibility of long-time simulations is questionable. Further sophisticated methods to deal with this difficulty have been developed, e.g., combinations of the level set method with tracing marker particles advected by the velocity field.[4]







http://en.wikipedia.org/wiki/Level_set_method
저작자 표시
신고
Trackback 0 | Comment 0

강군v's Blog is powered by Daum & tistory

 

티스토리 툴바