summaryrefslogtreecommitdiff
path: root/html/en/proc_samples.html
blob: e51ff3755dcb4d6bb1aa31cf6cce78347248e1db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!doctype HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Processing Samples</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>

<body>

<h1>Image Processing Samples</h1>
<h3><a name="proc_fourier">Fourier Transform</a></h3>

  <p>This is another command line application that process an image in the 
  Fourier Frequency Domain. In this domain the image is a map of the spatial 
  frequencies of the original image. It depends on the IM main library and on 
  the IM_FFTW library. The FFTW is a very fast Fourier transform, but is 
  contaminated by the GPL license, so everything must be also GPL. To use it in 
  a commercial application you must contact the MIT and pay for a commercial 
  license.</p>
  <p>Se also
  <a href="doxygen/group__transform.html">
  Reference / Image Processing / Domain Transform Operations</a>.</p>
  <p>You can view the source code here: <a href="../download/proc_fourier.cpp">
  proc_fourier.cpp</a></p>

<h3><a name="houghlines">Hough Lines</a></h3>

  <p>The Hough transform can be used to detect lines in an image. But it results 
  are highly dependent on other operations done before and after the transform. 
  Here you can see a small pseudo code that ilustrates a possible sequence of 
  operations to detect lines using the hough transform.</p>
  <p>First the canny operator will isolate the borders, the threshold will mark 
  the candidate pixels. After the transform the local maximum are isolated to 
  detect the line parameters of the lines that have many pixels from the 
  cadidate ones. The last operation will just draw the detected lines over the 
  original gray scale image.</p>
  
    <pre>imProcessCanny(in,out,stddev)
imProcessHysteresisThreshold(in,out,low,high)

imProcessHoughLines(in,out)
imProcessLocalMaxThreshold(in,out,size,min)

imProcessHoughLinesDraw(in1,in2,out)</pre>
  
  <p>Or a more complete sequence using another approach:</p>
  
    <pre>gray = imImageCreate(width, height, IM_GRAY, IM_BYTE);
binary = imImageCreate(width, height, IM_BINARY, IM_BYTE);
binary2 = imImageClone(binary);

rhomax = sqrt(width*width +height*height)/2;
hough_height=2*rhomax+1;
hough = imImageCreate(180, hough_height, IM_GRAY, IM_INT);
hough_binary = imImageCreate(180, hough_height, IM_BINARY, IM_BYTE);

imConvertColorSpace(rgb, gray);

// very important step, the quality of the detected lines are highly dependent on
// the quality of the binary image
// Using a simple threshold like in here maybe not a good solution for your image
imProcessPercentThreshold(gray, binary, percent=50); 

// eliminates unwanted objects, depending on the quality of the threshold
// this step can be skiped
imProcessBinMorphClose(binary, binary2, 3, 1); 
imProcessPrune(binary2, binary, 4, size=100, 0);

// Is there any holes in the objects?
// Holes also have borders...
imProcessFillHoles(binary, binary2, 4);

// leave only the object borders
imProcessPerimeterLine(binary2, binary);  

// here you should have near only the lines you want to detect.
// if there are more or less lines that you want redo the previous steps

imProcessHoughLines(binary, hough);
imProcessLocalMaxThreshold(hough, hough_binary, 7, 100);

// this is optional, it will draw the results
imProcessHoughLinesDraw(gray,hough_binary,draw_hough); </pre>
  
  <p>In the result of <b>imProcessLocalMaxThreshold</b> there will be several white 
  pixels. They represent the detected lines. Defining:</p>
  
    <pre>Y = a * X + b
cos(theta) * X + sin(theta) * Y = rho

where:
  X = x - width/2
  Y = y - height/2

because the origin of the transform is in the center of the image</pre>
  
  <p>Each coordinate in the transform has values in the intervals:</p>
  
    <pre>theta = 0 .. 179  (horizontal coordinate of the hough space)
rho = -rhomax .. rhomax    (vertical coordinate of the hough space, 
                            vertically centered in the image)

where:
    rhomax = sqrt(width*width + height*height) /2            (width and height of the original image)</pre>
  
  <p>For each (xi, yi) point found in the result image:</p>
  
    <pre>theta = xi;
rho = yi - rhomax;

then:

a = -cos(theta)/sin(theta);
b = (rho + (width/2)*cos(theta) + (height/2)*sin(theta))/sin(theta);</pre>
  
  <p>The complex formula for &quot;b&quot; came from the fact that we have to shift the 
  result to the image origin at (0,0).</p>

<h3><a name="analysis">Image Analysis</a></h3>

  <p>The following pseudo code ilustrates the sequence of operations to measure 
  regions. This is also called Blob Analysis.</p>
  <p>First the regions are isolated from background using a threshold. Then 
  regions too small or too large are eliminated and the holes are filled in this 
  example. After the regions are found we can start measuring properties of the 
  regions like area and perimeter.</p>
  
    <pre>imProcessSliceThreshold(in, out, level1, level2)
imProcessPrune(in, out, connect, size1, size2)
imProcessFillHoles(in, out, connect)
imAnalyzeFindRegions(in, out, connect)
imAnalyzeMeasureArea(in, area)
imAnalyzeMeasurePerimeter(in, perim)</pre>
  


</body>

</html>