automatic lineament extraction from digital images using a segment tracing and rotation...
TRANSCRIPT
Pergamon
Compurers & Geosciences Vol. 21, No. 4, pp. 555-591, 1995 Copyright 0 1995 Elsevier Science Ltd
0098-3004(94)00097-2 Printed in Great Britain. All rights reserved 0098-3004/95 $9.50 + 0.00
AUTOMATIC LINEAMENT EXTRACTION FROM DIGITAL IMAGES USING A SEGMENT TRACING AND ROTATION TRANSFORMATION APPROACH
VENKATESH RAGHAVAN’, SHINJI MASLJMOTO], KATSUAKI KOIKE* and SHUICHI NAGANO’
‘Osaka City University, Faculty of Science, 3-3-138 Sugimoto, Sumiyoshi-ku, Osaka 558, Japan; and 2Kumamoto University, Faculty of Engineering, 2-39-l Kurokami, Kumamoto 860, Japan
(e-mail: hl733@ocugw,cc,osaka-cu.ac.jp)
(Received 13 July 1994)
Abstract-A Segment Tracing And Rotation Transformation (START) approach is described for extracting lineaments (linear features) from digital images. The START algorithm is executed in two stages. First, a binary line element image is generated using the segment tracing algorithm. Second, the rotation transformation algorithm is used to extract lineaments from the line element image. The START algorithm was coded in FORTRAN 77 and implemented on a UNIX-based workstation. The START program is a comprehensive toolkit for lineament mapping that incorporates functions such as image display, graphics routines for on-screen mapping, and image hardcopy generation. The program was tested with LANDSAT MSS and TM images as well as with shaded relief images from digital elevation models (DEMs). The results obtained were successful for a test site in southwestern Japan. The algorithm can be used for other data sets, such as shaded aeromagnetic images.
Key Words: START, Image processing, Segment tracing, Rotation transformation, Lineaments, Automatic extraction.
INTRODUCTION
Lineaments derived from raster image data sets contribute important information in natural resource exploration and hazard assessment. A lineament can be defined as a linear geomorphic element repre- senting a geologic structure or lithologic contact. Various computer-aided lineament extraction pro- cedures have been attempted with the widespread availability of digital satellite images. These tech- niques can be divided broadly into two categories: (1) lineament enhancement for human interpretation (e.g. Chavez, Berlin, and Acosta, 1976; Peters, Speirer, and Moll, 1984); and (2) machine-aided lineament extraction (e.g., Elrich, 1977; Ochi and others, 1987; Wang and Howarth, 1990; Kouda, 1990; Koike, Nagano, and Ohmi, 1993). Lineament enhancement algorithms are incorporated in a wide variety of commercially available image- processing software packages. However, few com- puter programs for automatic lineament extraction are available (e.g., Burdick and Speirer, 1980; Ragha- van, Wadatsumi, and Masumoto, 1994). Automatic lineament extraction procedures involve some sort of an edge-filtering approach as a way to segment the image into lineament and non-lineament pixels. In several situations, the filtering technique generates segmented images containing numerous spurious
lineament pixels that must be eliminated using com- plicated edge-linking algorithms. Further, these linea- ment extraction routines perform indiscriminate extraction of edge pixels without considering the topographic information that is inherent in remotely sensed images.
To overcome some of this problem mentioned, this investigation describes a simple and effective pro- cedure for automatic lineament extraction using the Segment Tracing And Rotation Transformation (START) approach. The START algorithm adopts a nonfiltering approach to detect gray-level boundaries in a digital image. In addition, the topographic information revealed by the direction of shadows in digital images is taken into account in the extraction procedure.
The START algorithm is executed in two stages. In the first stage, the digital image is segmented into a binary line-elements image using the Segment Trac- ing Algorithm (Koike, Nagano, and Ohmi, 1993). In the second step, the rotation transformation or Gen- eralized Hough Transformation (Kang, Park, and Lee, 1991) is used to scan the line-element image in order to detect continuous gray-level boundaries and generate the final lineament map.
Lastly, a self-contained computer program is presented that performs multiple functions such as image display, automatic lineament extraction
555
using START algorithm, on-screen review and edit- ing of interpreted features and hardcopy gener-
Begln START
ation. The program was tested using LANDSAT images and DEM data for southwestern Japan. q
HARDWARE REQUIREMENTS AND PROGRAM ARCHITECTURE
The START program was developed on a general purpose NEC EWS 4800 UNIX-based
segment Tracing
workstation but easily can be ported to any UNIX- based system with minor modification. The major part of the program is coded in FORTRAN 77 (Appendix I). The image display and on-screen graphics functions are supported by the X-library
I.
graphics functions (AT&T, 1990) that are preinstalled in most UNIX-based workstations. A minor part of START is coded in the C language (Appendix II).
(G&z)
The routine coded in C is a driver program used to call the X-library functions in the main
0 FORTRAN 77 program. Hardcopies can be generated on printers that support the Postscript graphics language. Included with START is a driver program coded FORTRAN 77 which generates the Postscript image file. The general layout of the START program is shown in Figure 1. The START program is comprised of various steps described next.
Display of original image
The START program reads a band-separated input image file and displays the original black-and- white images with 128 gray levels using the X-library graphics. The maximum array size for the input image is set at 960 x 960.
Interactive Graphic Display
l display l xfdispx
Segment tracing algorithm Figure 1. Flowchart showing various functions of START program. The steps involved in the Segment Tracing Algor-
ithm (STA) and the mathematical operations per- formed are shown in Figure 2. STA consists of four main steps. In Step 1, the digital image (an 11 x 11 local neighborhood) is examined to determine the direction along which pixels show minimum variation in digital values. The 16 directions shown in Figure 2 are scanned sequentially, and the direction showing minimum variation (kmin) is determined. By selecting 16 directions, it is possible to examine all the pixels in the local neighborhood. In Step 2, the change in brightness level at the center of the 11 x 11 neighbor- hood is calculated by examining pixels in the direc- tion perpendicular to the direction kmin determined in Step 1. A dynamic threshold is set such that line elements lying parallel to the sun’s azimuth have a lower threshold compared to line elements lying perpendicular to the sun’s azimuth (Fig. 2). Pixels with digital values above the threshold are retained as line elements. A more detailed discussion on STA is planned for a future paper by Koike and others. those parallel to the azimuth.
In Step 3, the directions of shadows in the digital image are used as criteria for judging if the gray-level boundary represents a ridge or valley feature. Step 3 is based on the assumption that lineaments may correspond to linear topo- graphic valleys. However, for other applications, such as automatic mapping of large dike swarms, the ridge features may be a more critical cri- terion. Therefore, Step 3 may be changed according to the user’s need. In this study, Step 3 was tailored to retain only topographic depressions (valley features).
Step 4 is applied in order to link line pixels whose distance is less than D (Fig. 2) and generate the line-element image (Fig. 3). The value D is a dynamic threshold that depends on the solar azimuth. The threshold distances for line elements perpendicular to the sun’s azimuth generally are shorter compared to
556 V. Raghavan and others
Hati COPY Generatlon
l PsPnt
Automatic lineament extraction
STEP 1 : Sequential search for continous pixel direction
R=~wj(Z*-Zi)
for (i = -5-5)
557
12 111OQ 13 7
STEP 2 : Calculation of brightness change at kernel center
L=-q=c(zj+l - Zj+Zj_,) 2 lZj for(j=--4-b)
Threshold T is given as T=m +CXG
~c=5/(1+sin~-Sn,misthemean ofLand standard deviation of L
if IO z T then Z, = Line element
STEP 3 : Valley & Ridge judgement routine
If S1 >= S2 pixel is a line element If S1 c S2 pixel is not a line element
STEP 4 : Linking of line pixels closer than a threshold distance
Threshold for distance D=4/(l+sin$)+8
Figure 2. Diagrammatic representation of Segment Tracing Algorithm (STA)
Automatic lineament extraction by rotation transformation
The Automatic Lineament Extraction by Rotation Transformation (ALERT) algorithm constitutes the second stage of the lineament extraction process. The ALERT algorithm is based on the Generalized Hough Transformation. The algorithm can be sum- marized as follows. The edge-element image is rotated about the center of the image plane by a fixed angle step, and each rotated image is searched in the horizontal and vertical direction to determine the endpoints of the horizontal and vertical line seg- ments. Finally these endpoints are rotated inversely to obtain line segments in the original edge-element
image. The algorithm consists of four steps as shown in Figure 4.
During Step 1, each pixel of the line element image (generated by STA) is rotated by an angle (x. In Step 2, an accumulator matrix whose cell addresses correspond to rotated coordinate space (x’, y’) is initialized. The size of the accumulator matrix depends on the quantization interval selected. This interval is similar to the quantization interval p used in conventional Hough transformation (Duda and Hart, 1972). The corresponding cell of the accumulator array [JT(x’,y’) in Fig. 41 is increased by 1 when the line elements are encoun- tered in the rotated coordinate space. By repeat- ing the procedure for every edge element in the
432
336
208
96
48
0 t
V. Raghavan and others
0 40 96 144 192 240 200 336 304 432 400
Figure 3. Line pixel image generated by applying STA to LANDSAT MSS Band 7 subscene (north is parallel to vertical axis, and axes represent number of pixels).
original image, a loaded accumulator matrix is generated.
In Step 3 the accumulator matrix JT(x’,y’) is searched in the horizontal and vertical directions. If the content of the array cell is more than a predefined threshold, the cell is considered as a line element. Also, if more than a specific number (threshold length id in Fig. 4) of line elements exists, which are not separated by a gap, these line elements construct a “segment”. The first and last elements represent starting and ending points of the “segment”.
In Step 4, endpoints of detected “segments” are transformed inversely from rotated coordinate space (x’, y’) to the coordinate space of the original image (x,y). In Step 5, closely spaced “segments” defined by endpoint coordinates are joined using a merging operation described by Raghavan, Wadatsumi, and Masumoto (1994). A merging operation is carried out by calculating the distance between midpoints of line segment pairs (0) and their distance from the center of the image, using the following equations:
e = J(k* - k,)2 + (r, -I,)> (1)
0, = J(k, - k)2 + (,, - 1)2 (2)
c2=,,/(k2-k)2+(12-1)2 (3)
&J=la,-a,1 (4)
60 = IPI - B21 (5)
where u, and f12 are the distance from the image center (k, I), b, and p2 are inclination angles, and (k, , I,) and (k2, iZ) are midpoints of the respective line segment pairs. A threshold is set for values 0, 6a and Sp which are referred to as merge criteria. Line segments with values less than a certain threshold are merged.
In the START program, the merging operation is carried out in two stages. The threshold values for the merge criteria can be changed according to visual judgment. In the first stage, the merge criteria 6a and Sfl are set at 30 and O”, respectively (i.e., line segments trending in the same direction). After completing the first stage of the merging operation, the rotation angle is incremented by a user-defined interval and Steps l-5 are repeated. Because the accumulator array (JT(x’, y’)) is searched in both the vertical and horizontal directions, the original image need not be rotated by more than 90” to scan all the directions. The second stage of merging is carried out when all
Automatic lineament extraction
STEP 1: Rotate line element image
x’ = x coscc + y sina
Y y’ = -x sina + y cosa
559
STEP 2 : Generate Accumulator Matrix Y’
2D Accumulator matrix JT(x’, y? is generated by increasing the corresponding cell content by 1 when a line element is encountered In the rotated co-ordinate space (x’, y’).
STEP 3 : Search Accummulator Matrix
X’
Accumulator matrix IT@‘. y’) in searched in vertical and horizontal direction. if ceil contents are > threshold level over a certain distance +I/); the ceils construct a segment whose end-points are represented by the first and last ceil respectively.
STEP 4 : Inverse Rotation
x = x’cosa - y’sina y = x’sina + y’cosa
Y
t
STEP 5 : Merging Operation Generate iineamsnt map by connecting endpoints and merging closely spaced line segments
Y
. - . * .
l .
.
. . . . .
. :. .
. . .
- *_.
: * . .
.
* : . . . 1 x
Figure 4. Diagrammatic representation of Automatic Lineament Extraction by Rotation Transformation (ALERT) algorithm.
user-defined directions are scanned. The merge cri- teria 6u and SD are set at 40 and 20”. At this point, the line-segment length is used as an additional criteria, and short line segments are eliminated. The threshold of 0 during both merging stages is same as that for user-defined minimum length (iml in Fig. 4).
Interactive graphic display
This module is provided to facilitate the review and validation of machine-interpreted lineaments by a human interpreter. A separate graphics window is opened, and machine-interpreted features are dis-
played over the original image. The graphics window includes object-oriented interactive DISPLAY, DRAW, and ANNOTATE functions. The DISPLAY function is used for displaying lineament information previously stored in computer files. The DRAW function is useful for tracing lineaments on the computer screen. ANNOTATE performs the task of labeling the image with character strings entered from the keyboard.
Hardcopy generation
This part of START generates output processed images. To allow this function, a Postscript driver
560 V. Raghavan
program written in FORTRAN 77 is provided. The overlay of machine-interpreted features on hard- copy images also can be done using this driver program. Final hardcopy can be generated on a black-and-white (e.g., Fig. 5) or color Postscript printers.
RESULTS
The START program was evaluated on the same test site in southwestern Japan as a previous study made by Raghavan, Wadatsumi, and Masumoto (1994). However, comparison of the lineament extraction algorithm used in their study and the START algorithm have not been attempted.
The subscene (480 x 480 array) covering the test site was extracted from the LANDSAT MSS scene (Path 119-Row 36) acquired 15 November 1980. The affine transform and histogram equalization algorithms of the SPIDER image processing library (Joint System Development Corporation, 1983) were used for geometric correction and contrast enhance- ment of the LANDSAT subscene. The START algor- ithm was applied to the corrected subscene. The
and others
output at Stage 1 of the automatic lineament extraction procedure is shown in Figure 3. Sub- sequently, the three user-defined variables used in the ALERT subroutine (size of the accumulator matrix, threshold for minimum length, and scan direction) were set at 200, 20, and NO”E-N18O”E at 1” intervals, respectively. The resulting machine- interpreted lineaments overlaid on the MSS image are shown in Figure 5.
The START algorithm also was tested using a DEM with 250 m resolution which was obtained from the Japanese National Land Information Data- base. The DEM was interpolated using a bicubic spline interpolation program (Shiono, 1982; Raghavan and others, 1993), and the LANDSAT MSS image was coregistered with the DEM. Shaded- relief maps were generated from the interpolated DEM using a Lambertian reflection model. Details regarding the methodology are described by Raghavan, Wadatsumi, and Masumoto (1993), and the source code is listed in Raghavan and others (1993). The START algorithm was applied to the shaded-relief image. The three-user defined variables used in the ALERT subroutine (size of
400
432
336
240
96
0 48 96 144 192 240 200 336 304 432 400
Figure 5. Machine-interpreted lineaments generated by ALERT algorithm using LANDSAT MSS Band 7 subscene (north is parallel to vertical axis, and axes represent number of pixels).
Automatic lineament extraction 561
tor matrix, threshold for minimum length and scan direction) were set at 150, 15, and NO”-Nl80”E at 1” intervals, respectively. The output image at Stage 1 (STA stage) is shown in Figure 6.
Machine-extracted lineaments overlaid on the shaded relief image are shown in Figure 7. Sub- sequently, the machine-interpreted features were smoothed manually using an on-screen graphics func- tion of START. The final lineament map is shown in Figure 8.
The experiment was repeated using a 512 x 400 LANDSAT TM Band 4 subscene covering parts of the test site. The output image, after applying the STA, is shown in Figure 9. The three ALERT user-defined functions (previously described) were set at 200, 15, and NO”E-NI 80”E at lo intervals, respect- ively. The lineament map generated by the ALERT algorithm is shown in Figure 10.
CONCLUSIONS
In an earlier effort to automate lineament mapping, the Sequential Machine Interpreted Lineament
Extraction System (SMILES of Raghavan, Wadatsumi, and Masumoto, 1994) was developed. The present paper differs from this earlier work in two major aspects. First, the START program can be ported to a wider range of UNIX-based machines because it does not require the support of any specialized software library, such as Graphical Kernel System (ISO, 1985) used in developing SMILES. Second, and more important, a new algorithm for automatic lineament extraction using the Segment Tracing And Rotation Transformation (START) approach was developed. START is a simple and effective algorithm that differs from conventional techniques in that it adopts a nonfiltering technique for lineament extraction. Further, START takes into account topographic information that is inherent in digital satellite images.
Preliminary verification of the machine-interpreted features was carried out using aerial photographs of the test site. A majority of the machine-interpreted lineaments represent geomorphic features that are characteristic of geologic lineaments. The compara- tive merit of the Directional Segment Detection Algorithm (DSDA of Ochi and others, 1987), which
480
432
384
336
240
96
0 48 96 144 192 240 288 336 304 432 480
Figure 6. Line pixel image generated by applying STA to shaded-relief image derived from DEM data. (Illumination direction: azimuth 150”, inclination 30”; north is parallel to vertical axis, and axes represent
number of ptxels).
432
336
96
48
0
0 40 96 144 192 240 288 336 384 432 480
Figure 7. Machine-interpreted lineaments generated by ALERT algorithm using shaded-relief image derived from DEM data (Illumination direction: azimuth I50”, inclination 30’; north is parallel to vertical
axis, and axes represent number of pixels).
480
432
384
336
288
240
96
48
0
0 48 96 144 192 240 288 336 384 432 480
Figure 8. Machine-interpreted lineaments extracted using DEM are smoothed manually and overlaid on LANDSAT Band 7 subscene (north is parallel to vertical axis, and axes represent number of pixels).
562
Automatic lineament extraction 563
360
320
280
160
120
80
40
0
0 51 102 153 204 255 306 357 408 459 510
Figure 9. Line pixel image generated by applying STA to LANDSAT TM Band 4 subscene (north is approximately 9 clockwise from vertical axis, and axes represent number of prxels)
400
360
320
280
240
160
80
40
0
0 51 102 153 204 255 306 357 408 459 510
Figure 10. Machine-interpreted lineaments generated by ALERT algorithm using LANDSAT TM Band 4 subscene (north is approximately 9’ clockwise from vertical axis, and axes represent number of pixels).
564 V. Raghavan and others
was incorporated into SMILES, and the START International Standards Organization (ISO), 1985, Graphi-
algorithm was not evaluated. However, a cursory cal Kernel System (GKS)-Functional Description:
examination of the interpreted features indicates that Switzerland, IS0 7942, 245 p.
the START algorithm yields better results. The Joint System Development Corporation, 1983, Spider’s
User’s Manual: Aaencv for Industrial Science and Tech- START algorithm has -been applied to satellite nology, Tokyo, 632 p:
images and DEM data in this work. In addition, there Kang, C. W., Park, R. H., and Lee, K. H., 1991, Extraction
is a potential for applying the algorithm to other of straight line segments using rotation transformation:
image data sets such as illuminated (shaded) Generalized Hough Transformation: Pattern Recog- nition. v. 24, no. 7. p. 633641.
aeromagnetic images.
Acknowledgments-The first author is grateful to the Japanese Ministry of Education, Science and Culture for the award of a scholarship at Osaka City University and to the Director, Centre for Earth Science Studies, India for granting leave to accept the scholarship. We are grateful to Prof. K. Wadatsumi, Dr. K. Shiono of the Osaka City University. and Mr D. C. Peters of U.S. Bureau of Mines for their support and encouragement. Our thanks also to Prof. N. Nishiwaki of Nara University, Japan for his encouragement. We also wish to thank Dr. Brian Penn of the Colorado School of Mines and Dr. Sandra Perry of Perry Remote Sensing Ltd., for their critical review and constructive suggestions. Dr. M. Sakamoto of the Kakugakuin City University is thanked for software support and helping in various other ways.
Peters, D. C., Speirer, R. A., and Mall, S. H., 1984, Image processing for automatic lineament analysis, in Peters, D. C., and others, eds., Proc. GeoTech ‘84: Personal Computers in Geology, Denver, Colorado: Colorado Section: Am. Inst. Prof. Geol., Spec. Issue No. 6, p. 88-91.
Raghavan, V., Masumoto, S., Shiono, K., Sakamoto, M.,
Koike, K:, Nagano, S.\ and Ohmi, M., 1993, Development and application of lineament extraction method using segment tracing algorithm, in Geoinforum ‘93, 4th Annual Meeting Japan Sot. Geoinformatics: Tokyo University, p. 19-20 (in Japanese).
Kouda, R. 1990, Pattern recognition for geological struc- tures of Landsat Thematic Mapper image in Mt. Takakuma area of South Kyushu, Japan: Geoinformat- its, v. 1, no. 2, p. 191-203.
Ochi, M., Komai, J., Arai, K., Fujuoka, H., Tokuo, T., and Ohatani, K., 1987, Photogeological appraisal of automatically extracted lineaments from Landsat data: Mining Geology, v. 37, no. 2, p. 999108 (in Japanese).
REFERENCES
AT&T, 1990, Programmer’s guide: XWIN graphical win- gnd Wadatsumi, K., 1993, ARIES: A subroutine for dowing system Xlib-C language interface: UNIX Press, automatic relief image enhancement and shading: Prentice-Hall, Englewood Cliffs, New Jersey, 416 p. Geoinformatics, v. 4, no. 2, p. 59-88.
Burdick, R. G., and Speirer, R. A., 1980, Development of Raghavan, V., Wadatsumi, K., and Masumoto, S., 1993, a method to detect geologic faults and other linear Automatic extraction of lineament information of satel- features from Landsat images: U.S. Bureau of Mines, lite images using digital elevation data: Nonrenewable Rept. of Invest. 8413, 74 p. Resources, v. 2, no. 2, p. 148-155.
Chavez, P. S., Jr., Berlin, G. L., and Acosta, A. V., 1976, Raghavan V., Wadatsumi, K., and Masumoto, S., 1994, Computer processing of Landsat MSS digital data for SMILES: A FORTRAN-77 program for sequential linear enhancement, in Proc. 2nd Annual W. T. Pecora machine interpreted lineament extraction using digital Memorial Symposium, Sioux Falls, South Dakota: images: Computers & Geosciences, v 20, no. 2., Falls Church, Virginia Am. Sot. for Photogrammetry, p 121-159. p. 235-250. Shiono, K., 1982, A subroutine SFS3L for grid to grid
Duda, P. O., and Hart, P. E., 1972, Use of the Hough conversion: Geological Data Processing, no. 7, p. 89-96 Transformation to detect lines and curves in pictures: (in Japanese). Comm. Assoc. Comp. Machinery, v. 15, p. 1 l-15. Wang, J:, and Howarth, P. J., 1990, Use of Hough
Elrich, R. W., 1977, Detection of global edges in textured transform in automated lineament detection: images: IEEE Trans. on Computers, v. c-26, no. 6, IEEE Trans. Geoscience and Remote Sensing, v 28, p. 589603. no. 4., p. 561-566.
Automatic lineament extraction
APPENDIX I
565
program start c A program for automatic lineament extraction using C Segment Tracing And Rotation Transformation. C Programed at Osaka City University, Japan. C Last edited on 4th December, 1993. * **************************************************
parameterjixmax = %O,kmax=16.nmax=ll) parameter (pai = 3.141592654) dimension ir(256).ig(256),ib(256)jy(4) integer*2 ida(ixmax,ixmax),idb(ixmaxjxmax) common /cml/nx(kmax,nmax), ny(kmax,nmax) common /cm2/ a(kmax). dd(kmax),w(nmax) common /cm3/kda(nmax).p(nmax) character*80 fnl,title,cmd,fn2,fn3 data nx/ 1, 1, 1, 1, 1.3,4,5,6,7,8,9, 1, 1, 1, 1,
1 2,2,2,2,2, 3,4,5,6,7,8,9,2, 2, 2, 2, 1 3, 3, 3.3, 3,4,5,5,6,7,8,8, 3.3, 3, 3, 1 4,4,4,4,4,5,5,6,6,6,7,7.4,4,4,4, 1 5,5,5,5,5,5,6,6,6,6,7,7,5,5,5,5, 1 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 1 7,7,7,7,7,7,6,6,6,6,6,5,7,7.7,7, 1 8,8,8,8,8,7,7,6,6,6,5,5,8,8,8,8, 1 9,9,9,9,9.8,7,7,6,5,5,4,9,9,9,9, 1 10,10,10,10,10,9,8,7,6.5,4, 3,10,10,10,10, 1 11,11,11,11,11,9,8,7.6,5,4, 3,11,11,11.11/
C
datany/6,5,4,3,1,1,1,1,1,1,1,1,11,9,8,7, 1 6,5,4,3,2,2,2.2,2,2,2,2,10,9,8,7, 1 6,5,5,4,3,3,3,3,3,3,3,3,9,8,7,7, 1 6,6,5,5,4.4,4,4,4,4,4,4,8,7,7,6, 1 6,6,6,5,5,5,5,5,5,5.5,5.7,7,6,6, 1 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 1 6,6,6,7,7,7,7,7,7,7,7,7,5,5,6,6, 1 6,6,7,7,8,8,8,8,8,8,8,8,4,5,5,6. 1 6,7,7,8,9,9,9,9,9,9,9,9,3,4,5,5, 1 6, 7, 8,9,10,10,10,10,10,10,10,10,2,3,4,5, 1 6,7, 8,9,11,11,11,11,11,11,11,11,2,3,4,5/
C
print *, ’ Please make sure that none of your old files ’ print *, ’ have the names result & res. This program’ print *, ’ automatically creates files of these names’ print *, ’ and deletes them afer execution !!!!!!!!!!!I print *, ’ Give input file name’ read(* *) fnl open(;l,file=fnl ,form=‘UNFORMATl”ED’) read(5 1) title read(5 1) ncol,nlin,ipl ,il 1 ,ip2,i12 do 10 i = 1,nlin
10 read(51) (ida(k,i),k = l.ncol) close(5 1)
C
do k = 1,128 ir(k) =( k-1)*2 ib(k) =( k-1)*2 ig(k) =( k-1)*2 enddo
C
ir( 129) = 255 ig( 129) = 255
566 V. Raghavan and others
ib(129) = 0 ir(130) = 255 ig(130) = 0 ib(130) = 0 ir(131) = 128 ig(131) = 128 ib(131) = 128
C
C display original image * **********************
call xcsw(ncol+8,nlin+8,ir,ig,ib) call xmouse(idumx,idumy) call xb(30)
C
do i = 1,nlin do j = 1,ncol iy=nlin+l -i idd = ida( call xsfc(idd) call xdp(j+4,iy+4) enddo enddo
C
open(5l,file=‘result’,form=‘UNFORMATTED’) nn= 11 kk= 16 dok= 1,nn w(k) = cos(float(kd)*paiLZO.O) enddo
C
do 11 iiy = 6,nlin - 5 do 12 iix = 6,ncol - 5
C find continous pixel direction in 11X 11 neighbourhood * ********************************************~*******~
call stepl(ida,iix,iiy,pai,nn,kk,kmin) C find brightness level variation at kernel center * ******************************y******************
call step2(ida,iix,iiy,pai,nn,kk,kmin) C
do 14 ish = 1,kk a(ish) = 0.0
14 continue 12 continue 11 continue
close(51) C
C generate line elements * **********************
call linel(ida,ncol,nlin) close(52)
C
open(52,file=‘res’,form = ‘UNFORMATTED’) C generate line element image * **********************a****
call imasta(idb,ncol,nlin) print *,’ Give image output filename ’ read (*,*) fn2 open(52,file=fn2,fotm=‘UNFORMATTED’) title = ‘STA OUTPUT write(52) title write(52) ncol.nlin,0,0,ncol,nlin do 100 i = l.nlin
Automatic lineament extraction
100 write(52) (idb(j,i)j=l,ncol)
567
C
C
*
c C
*
C
C
*
C
C
C
C
*
C
C
close(52) -
generate lineaments using rotation transformation ****************************************~*******~**
call alert(idb,fn2,fn3jy)
display lineaments over original image **************************************
call display(ir,ig.ib,fnl jy) print *,’ Wish to generate Hardcopy on PS printer ? ’ call xmouse(ix1 ,iyl) call xb(30) call xf if(ixl.ge.334.and.ixl.le.376.and.iyl.ge.jy(l).
1 and.iyl .le.jy(2)) then
generate hardcopy on PostScript printer ****************************************
call pspnt(title.fnl,jy) endif call xdw call xcd cmd = ‘rm -f result’ i = system(cmd) cmd = ‘rm -f res’ i = system(cmd) stop end
subroutine step1(ida,iix,iiy,pai,nn,kk,kmin) this subroutine examines a 11X1 1 neighbourhood and detetmines the direction along which pixels show minimum variation. ****************************************~*********~
parameter(ixmax = 960,kmax=l6,nmax=ll) integer*2 ida(ixmax,ixmax) common /cml/nx(ktnax,nmax), ny(kmax,nmax) common /cm2/ a(kmax), dd(kmax),w(nmax) common /cm3/kda(nmax),p(nmax)
dmin = 5000.0
do4Ok= 1,kk do41 i = 1,nn j = 12-i nnx = (nx(kj)-6) + iix MY = (ny(k,i)-6) + iiy xl = float(ida(iix.iiy)-ida(nnx,nny)) a(k) = a(k) + w(i)*(xl**2)
41 continue x 1 = float(nn- 1) dd(k) = a(k) / xl if(dd(k).lt.dmin) then dmin = dd(k) kmin=k endif
C
40 continue return end
CAGE0 2 I ,+-I
568 V. Raghavan and others
C
subroutine step2(ida,iix,iiy,pai,nn,kk,kmin) c this subroutine calculates the brightness level C change at the kernel center of 11X1 1 neighbourhood. * ***************************************************
parameter(ixmax = 96O,kmax=16,mmm=ll) integer*2 ida(ixmax.ixmax) common /cml/nx(kmax~ax), ny(kmax~lmax) common /cm2/ a(kmax), dd(kmax).w(nmax) common /cnL+/kda(mnax),p(nmax)
C
if(kmin.le.8) kkk = kmin + 8 if(kmin.ge.9) kkk = kmin - 8
C
do50iii=l,nn jjj = 12-iii nnx2 = (nx(kkkJjj)d)+iix nny2 = (uy(kkk,iii)++iiy kda(iii) = ida(nnx2,nny2)
50 continue C
pp = 0.0
qq = O&O c do 51 jj = 2.M-1 xl = float(kda(jj+l)-2*kda(ij)+kda(jj-1)) p(jj) = ((xl**2) / kda(ij))
5 1 continue C
do jj = 2,nn- 1
PP=PP+PW Wd;lq + Pti) ** 2
x2 = float(nn-2) ave = pp/x2 var = qq/x2-ave**2 if(var.lt.O.O) var = 0.0 sd = sqrt(var)
C if(kkk.lt.14) then kh=kkk elseif (kkk.eq.14) then kll= 12 elseif(kkk.eq. 15) then kh= 11 elseif(kkk.eq. 16) then kh= 10 else endif
C sita = abs((pai/l6.0)*float(kh-5)) ff = S.O/(l.O+sin(sita))-(5.0n.0) siki = ave+Fsd
C if(p(6).gt.siki) then if(kmin.ge.3.and.kmin.le.7) write(5 1) iix,iiy,kmin if(kmin.eq.l.or.kmin.eq.2.or.kmin.ge.8)
1 call step3(iix,iiy,kmin) endif return end
Automatic lineament extraction 569
C
subroutine step3(iix,iiyJcmin) C this subroutine determines if the detected grey level C represents a valley or a ridge. * *****************************************************
parameter(ixmax = 96O,kmax=16,nmax=ll) common /cml/nx(kmax,nmax). ny(kmax,nmax) common /cm2/ a(kmax), dd(kmax),w(nmax) common /cnWkda(nmax)g(nmax)
C
ml=0 m2=0
C
do6Oi=7,11 ml = ml + kda(i)
60 continue C
do61 i= 1.5 m2 = m2 + kda(i)
61 continue if(ml.gt.m2) then w&(51) iix.iiy&min endif return end
C
subroutine linel(ida,ncol,nlin) C this is subroutine is for linking closely spaced C line pixels to generate line element image. * ************************************************
pafameter(ixmax = 960) dimension s1(8,2).xx(200),yy(2~)~1(8.2) integer*2 ida(ixmax,ixmax) datalW.43369 12996347 lO.ll,ll/ . ..I. .,..,V* data s1/0.0.0.1989123.0.6681786.0.6681786,
1 0.1989123.0.1989123,1.0.0.6681786, 1 0.1989123,0.4142135,1.0,0.4142135, 1 0.0.0.4142135,0.6681786.0.4142135/
C
open@ 1 .file=‘result’,form=‘U~OR~~~) open(X!,file=‘res’,form = ‘UNFORMA’ITED’)
C
do loop = 1.8 do 5 1 = 1,nlin do 5 k = 1,ncol
5 ida(k.1) = 0 C
xe = 0 ye = 0
10 read(5 l,end=20) ix,iy,kk if(loop.eq.1) igrp = 1 if(loop.eq.2) igrp = 3 if(loop.eq.3) igrp = 5 if(loop.eq.4) igrp = 7 if(loop.eq.5) igrp = 9 if(loop.eq.6) igrp = 11 if(loop.eq.7) igrp = 13 if(loop.eq.8) igrp = 15 if(kk.eq.igrp.or.ti.eq.(igrp+l)) then ida(ix,iy) = 1 endif
510 V. Raghavan and others
go to 10 20 rewind(5 1) C
if(loop.lt.5) then ial =6 ia = ncol-5 istp = 1 endif
C
if(loop.ge.5) then ial = ncol-5 ia = 6 istp = -1 endif
C
do 30 iy = 6,(nlin-5) do 30 ix = ial.ia2,istp if(ida(ix.iy).eq.l) then ko = 0 if(loop.eq.1) call case1 (loop.sl.ixjy.ida,xx,yyJto,l1) if(loop.eq.8) call case1 (loop,sl,ix.i~,ida,xx,y~~o,l~) if(loop.eq.2) call case2 (loop,sl,ixjy,ida,xx,yykoJl) if(loop.eq.3) call case2 (loop,sl,ix,iy,i~,~,~~o,ll) if(loop.eq.4) call case3 (loop,sl,ix,iy,ida.xx,yyJco,ll) if(loop.eq.5) call case3 (loop,s1,ix,iy,ida,xx.yYJro,ll) if(loop.eq.6) call case4 (loop,sl,ix,iy,ida,xx,~~o~l) if(loop.eq.7) call case5 (loop,sl,ix,iy.ida.xx,yy~o,ll)
C
if(ko.eq.O) then ida(ix,iy) = 0 else call endpts (loop,xx,yy,ko,xe,ye,ix,iy) endif endif
30 continue enddo rewind(52) return end
C
subroutine casel(loop,sl,ix,iy,ida.xx,yyko,ll)
* **********at************************************
parameter(ixmax=960) integer*2 ida(ixmax,ixmax) dimension xx(200),yy(200).s1(8,2),11(8,2)
C
doku= 1.2 do i = 1 ,ll(loop,ku) xl=ix+i yl = iy + nint(i*sl(loop,ku)) k = int(x1) 1 = int(y1) if(k.gt.ixmax.or.l.gt.ixmax) return if(ida(k.Qeq.1) then ko=ko+ 1 xx(ko) = x 1 yy(ko) = Y 1 endif enddo enddo
Automatic lineament extraction
leturn
end
571
subroutine case2(loop,sl jx,iy jda,xx,yy,ko,ll) ********+**+***********************************
parameter(ixmax=%O) integer*2 ida(ixmax,ixmax) dimension xx(200),yy(200),s1(8,2).11(8,2)
doku= 1.2 do i = 1 .Il(loop,ku) xl = ix-i yl = iy + int(i*sl(loopJN)) k = int(x1) I= int(y1) if(k.gt.ixmax.or.l.gt.ixmax) return if(ida(k,l).eq.l) then ko=ko+ 1 xx(ko) = xl yy(ko) = Y 1 endif enddo enddo return end
subroutine case3(loop,sl,ixjyjda,xx,yy,ko,ll) ***********************************************
parameter(ixmax=960) integer*2 ida(ixmax,ixmax) dimension xx(2OO),yy(2OO),s1(8,2),11(8,2)
doku= 1.2 do i = 1 ,Il(loop,ku) xl = ix - nint(i*sl(loop,ku)) yl= iy+i k = int(x1) 1 = int(y1) if(k.gt.ixmax.or.l.gt.ixmax) return if(ida(k.l).eq. 1) then ko=ko+ 1 xx(ko) = x 1 yy(ko) = Y 1 endif enddo enddo return end
subroutine case4(loop.sl,ix,iy.ida,xx.yyjcojl) ***********************************************
parameter(ixmax=960) integer*2 ida(ixmax,ixmax) dimension xx(2OO),yy(2OO),s1(8,2),11(8,2)
doku= I.2 do i = 1 ,ll(loop.ku) xl = ix + nint(i*sl(loop,ku)) yl= iy+i k = int(x1) 1 = int(y1)
572 V. Raghavan and others
if(k.gt.ixmax.or.l.gt.ixmax) return if(ida(k.l).eq. 1) then ko=ko+ 1 xx(ko) = x 1 yY(ko) = Y 1 endif enddo enddo return end
C
subroutine case5(loop,sl.ix,iy.ida.xx,yy,ko,ll) * ******a****************************************
parameter(ixmax=960) integer*2 ida(ixmax.ixmax) dimension xx(200),yy(200),s1(8,2),11(8,2)
C
doku= 1.2 do i = 1 ,ll(loop,ku) if(ku.eq. 1) then xl=ix+i yl = iy + nint(i*si(loop,ku)) endif if(ku.eq.2) then xl = ix + nint(i*sl(loop,ku)) yl= iy+i endif k = int(x1) 1 = int(y1) if(k.gt.ixmax.or.l.gt.ixmax) return if(ida(k,l).eq.l) then ko=ko+ 1 xx(ko) = xl yy(ko) = yl endif enddo enddo return end
C
subroutine endpts(loop.xx,yy,ko,xe,ye,ix,iy) * ********************************************
parameter(ixmax=960) dimension xx(200), ~~(200)
C
lmax = 0 x = float(ix) y = float(iy) doj= 1,ko 1 = sqrt((xx(j)-x)**2 + @y(j) - y)**2) if(l.gt.lmax) then lmax = 1 xmax = xx(j) ymax = Yyti) endif enddo if(xmax.eq.xe.and.ymax.eq.ye) then return else xe = xmax ye = ymax
Automatic lineament extraction
write(52) x,y.xmax,ymax,lmax.loop endif return end
C
subroutine imasta(idbpco1,r.h) C This program is for generating a binary C line element image file. * ***************************************
parameter(ixmax=960) integer*2 idb(ixmax,ixmax)
C
do i = 1,nlin do k = l.ncol idb(k,i) = 0 enddo enddo
20 read(52,end=997) xl,yl,x2,y2,lmax,loop ix1 = xl iyl = yl ix2 = x2 iy2 = y2 call vec2ras (idb,ncol,nlin,ixl,iyl,ix2,iy2) go to 20
997 return end
C
subroutine vec2ras (idb,inp.inr.ixl,iyl,ix2,iy2) C this subroutine vector line segments into raster format. * ********************************************************
parameter(ixmax=960) integer*2 idb(ixmax,ixmax)
C
dx = (ix2 - ixl) dy=(iy2-iyl) k = abs(dx) n = abs(dy) if(k.gt.n) then c=dy/dx
C
if(ix 1 .gt.ix2) then kl = ix2 k2=ixl y = float(iy2) else kl = ix1 k2 = ix2 y = float(iy1) endif
C
doi=kl,k2 jx = i y=y+c jy = nint(y) if(jx.gt.inp.or.jy.gt.inr) go to 10 idb(jxjy) = 255 idb(jxjy+l) = 255 idb(jx+ ljy) = 255 enddo
10 continue else c=dx/dy
573
574 V. Raghavan and others
C
if(iyl.gt.iy2) then kl = iy2 k2=iyl x = float(ix2) else kl = iyl k2=iy2 x = float(ix1) endif
C
doi=kl,k2 x=x+c jx = nint(x) jy = i if(jx.gt.inp.or.jy.gt.inr) go to 20 idb(jx,jy) = 255 idb(jx+l,jy) = 255 idb(jxjy+l) = 255 enddo
20 continue endif return end
C
subroutine alert(idb.fn2.fn3jy) C this subroutine is for Automatic Lineament Extraction C by Rotation Transformation (ALERT). * *******************************************************
parametex(ixmax=96O,ijmax=960) integeti2 idb(ixmax,ixmax)jt(ijmax,ijmax) dimension px(2), py(2). qpx(5,1OOO)jy(4) character*80 fn2,fn3,title parameter (pai = 3.141592654) open(5 1 .file=fn2,form=‘UNFORMATTED’,status=’OLD) read(5 1) title read(5 1) ncol,nlin,ipl,ill,ip2,i12 do 1 i = l.nli,n read(5 1 ,end=2) (idb(j,i)j=l ,ncol)
1 continue 2 close(51) C
print *,’ Give quantizing levels for accumulator array’ read(*,*) iro print *,’ Give upper and lower limit and step for rotation ’ read(*,*) ial,ia2,istp print *,’ Minimum length defining line element ?’ read(*,*) iml
C
ile = 1 lnum = 0 print *, ‘Give output file name to store line co-ordinates’ read(*.*) fn3 open@ 1 ,file= fn3.form=‘UNFORMATTED’)
C
x0 = (nco1+2)/2 yo = (nlin+2)/2 rohm = sqrt(float(ncol*ncol) + float(nlin*nlin)) isize = int(rohm) roho = rohmJ2. droh = rohm/float(iro)
Automatic lineament extraction 575
do 30 it = ial,iaZistp ang = float(it) kst = lnum + 1
C
C Step 1: Initialize 2D accumulator array * ************************************a**
C
do5j= 1,960 do5i= 1.960 jt(ij) = 0 continue 5
C dth = (pai * ang) / 180. dthl = (pai * (ang+90.))/180. al = sin(dth) a2 = cos(dth)
Step 2: Rotate each edge element and quantize the rotated co-ordinates by multiples of qauntization interval (dmh)
do 40 iy = l.nlin y = float(iy) do 35 ix = l.ncol x = float(ix) ipd = idb(ix,iy) if(ipd.eq.O) go to 35 rl = (x-xo)*a2 + (y-yo)*al irl = (rl + roho)/droh 1-2 = -(x-xo)*al + (y-yo)*a2 is = (-12 + roho)/droh jt(irl,is) = jt(irl.is) + 1
35 continue 40 continue C
C Step 3: Search accumulator array in horizontal C direction to find line element end points * ********************************************** *
pl = float(iro) / float(iml) ipl = int(p1) do 180 Ik = 1,iml jadd = (lk - 1) do 180 i = 1,ipl icl=iml*(i-l)+l+jadd ic2=i*iml+jadd
C
do 180 j = 1,iro ipix = 0 do kl = icl,ic2 if(jt(klj).gt.ile) ipix = ipix + I
C
if(ipix.eq.iml) then lnum = lnum + 1 px(1) = icl py(l)=j px(2) = ic2 PY@) = j
V. Raghavan and others
C
if(py(l).le.py(2)) then qpx(l,lnum) = px(1) qpx(2Jnum) = PY( 1) qpx(3,inum) = px(2) qpx(4,lmun) = py(2) else qpx( 1,lnum) = px(2) qpx(2,lnum) = py(2) qpx(3,lnum) = px(1) qpx(4,lnum) = PY(l ) endif qpx(5,lnum) = dthl endif
180 continue C
C Step 4: Search accumulator array in vertical C direction to find line element end points * *************44*444*4444444444444**44*444444
do 80 lk = 1,iml jadd = (lk - 1) do 80 i = 1,ipl icl=iml*(i-l)+l+jadd ic2=i*iml+jadd
C
do8Oj= 1,iro ipix = 0 do kl = icl.ic2 if(jt(jkl).gt.ile) ipix = ipix + 1 enddo
C
if(ipix.eq.iml) then lnum = lnum + 1 px(l)=_i py(1) = icl pxt2) = j
py(2) = ic2 c if(py(l).le.py(2)) then qpx(l.lnum) = px(1) qpx(2,lnum) = py(1) qpx(3,lnum) = px(2) qpx(4Jmm7) = py(2) else qpx(1 Jnum) = px(2) qpx(2,lnum) = py(2) qpx(3,lnum) = px( 1) qpx(4Jnum) = py(1) endif qpx(5,lnum) = dth endif
80 continue C
C Step 5: Generate line co-ordinate pair by inverse C rotation * 4*444****4***444*44*4444**444444444*44***4*444444*
C
do k = kst.lnum 21 = qpx(l,k) 22 = qpx(2Jr)
Automatic lineament extraction 51-l
cl = (zl*droh) - roho c2 = -(z2*droh) + roho bl = (cl) * a2 - (~2) * al + xo b2 = (cl) * al + (~2) * a2 + yo qpx(l,k) = int(b1) qpx(2,k) = int(b2)
C
zl = qpx(3k) 22 = qpx(4k) c 1 = (z 1 *droh) - roho c2 = -(z2*droh) + roho bl = (cl) * a2 - (~2) * al + xo b2 = (cl) * al + (~2) * a2 + yo qpx(3.k) = int(b1) qpx(4.k) = int(b2) enddo
C
C Step 7: Merge closely spaced line segments * ******************************************
call merge(qpx,ncol&t,ip 1 ,il 1 ,ip2,il2,lnum, 1 iml,it,ia2,lno,lnol ,xo,yokst,istp)
C
C Step 8: Delete edge pixels that that have been C identified to form part of a line segment * **********************************************
call delpix(qpx,lnum,idb) C
C Step 9: Increase rotation angle by quantization C step (istp) and repeat Step 1 - Step 5 * ********NC**************************************
30 continue close(5 1) return end
C
subroutine merge(qpx,inp,inr,ipl.ill,ip2,il2,lnum,ialen, 1 it,ia2,lno,lnol,xo,yo,kst,istp)
C this subroutine merges closely spaced line segments. * ****************************************************
dimension qpx(5,1000),icon(1000) parameter (pai = 3.141592654)
C
do k = 1,lOOO icon(k) = 1 enddo ro = 30.0 an = 0.0 divf = 1.0 call xpol(qpx,lnum.icon,ro,an,xo,yo,ialen.divf,it,ia2,kst) do i = kst,lnum if(icon(i).eq.l) lno = In0 + 1 enddo do i = kst,lnum if(icon(i).eq.l) then write(51) (qpx(j,i)j=lJ) endif enddo lnum = In0 if(it.lt.ia2) return
C
do k = 1.1000
578 V. Raghavan and others
icon(k) = 1 enddo ro = 30.0 an = 0.0 divf= 1.0 call xpol(qpx.lnum.icon,ro~~xo.yo,ialen,divf,it,ia2Jcst) do i = kst,luum if(icon(i).eq.l) lno = In0 + 1 enddo do i = kst.lnum if(icon(i).eq. 1) then write(51) (qpxQi)j=ls) endif enddo rewind(51)
C kst = 1 do kl = kst,lno read(Sl)(qpx(j,kl)j=l,5) enddo rewind(51) au = 20.0 / 180.0 ro=40.0 divf = 1.0 do k= 1,lOOO icon(k) = 1 enddo lnol = 0 call xpoll(qpxJno.iconp,ann.xo,yo.ialen,divf,it,ia2,kst) do i=l.lno if(icon(i).eq.l) lnol = lnol + 1 enddo
C C write header record for output tile * ***********************************
doi= 1,lno if(icon(i).eq. 1) then
C C write (x.y) co-ordinates of line segment end-points * *****************************************************
write(5 1) (qpxcj j)j = 1.4) ix1 = qpx( 1.i) iyl = 9px(2,i) ix2 = qpx(3.i) iy2 = qpx(4.i) endif enddo rewind(51) write(*,lol) lnol
101 format(7x.’ Total Number of liueaments detected ‘j4) return end
C subroutine xpol(qpxJnm,icon,ro,an,xo,yo,ialen,divf,it,ia2,kst)
C this subroutine is a part of the merge subroutine. * ************************************************************~**
dimension qpx(5,lOOO) jcon( 1000) C
pi2 = 3.141592654t2.0
do i = kst.lnm-1
Automatic lineament extraction 579
xl = (qpx(1 j) + qpx(3.i)) / 2.0 yl = (qpx(2.i) + qpx(4.i)) / 2.0 thl = qpx(5.i) roll1 = sqrt(((x1 - xo)**2) + ((yo - yl)**2)) doj=i+l,lnm x2 = (qpx(lj) + qpx(3j)) / 2.0 y2 = (qpx(2j) + qpx(4j)) / 2.0 th2 = qpx(5j) roh2 = sqrt(((x2 - xo)**2) + ((yo - y2)**2)) dfow=abs(mlQ-rohl) dang = abstth2 - thl) v3 = @((x2 - x1)**2) + ((y2 - yl)**2)) VIII = float(ialen) / divf
C if(dang.le.an.and.dw.le.ro) then if(v3.le.vln)then ifloaxl5 i) lt.oi2 and oox(5 i) It oi2) then ._~ ,_-“,‘~__r~~’ ___.~_~ ,-:-,. ~%‘ ~, if(xl.le.x2) then icon(i) = 0 qpx(Sj) = qpx(5.i) qpx(1.j) = qpx(l,i) ifQpx(2$.gt.qpx(2jN qpx(2j) = qpx(2,i) endif if(x 1 .gt.x2) then icon(i) = 0 qpx(5j) = qpx(5.i) qpx(3j) = qpx(3,i) if(qpx(4j).lt.qpx(4.i)) qpx(4j) = qpx(4.i) endif endif
C if(qpx(&j).gt.pi2.and.qpx(5,i).gt.pi2) then if(y 1 .le.y2) then icon(i) = 0 qpx(5J) = qpxU.0 qpx(2j) = qpx(2.i) if(qpx(l.j).ge.qpx( 1.i)) qpx( lj) = qpx(1.i) endif if(yl.ge.y2) then icon(i) = 0 qpx(5j) = qpx(5.i) qpx(4j) = qpx(4.i) if(qpx(3 j).ge.qpx(3.i)) qpx(3 j) = qpx(3.i) endif endif endif endif enddo enddo return end
C subroutine xpoll(qpx,lnm,iconso,au~o,yojalen,divf,it,ia2Jcst)
C This subroutine smoothing line segments that are C generated by the START subroutine C
dimension qpx(5,1000),icon(1000) C
do i = kst.hm- 1 xl = (qpx( 1.i) + qpx(3.i)) / 2.0 yl = (qpx(2.i) + qpx(4.i)) / 2.0
580 V. Raghavan and others
thl = qpx(5,i) rohl = sqrt(((x1 - xo)**2) + ((yo - yl)**2))
2x1 = qpx(l,i) zyl = qpx(2,i) 2x2 = qpx(3,i) zy2 = qpx(4.i) zi = sqrt(((zx2 - zxl)**2) + ((zy2 - zyl)**2))
do j = i+l,lnm x2 = (qpx(lj) + qpx(3j)) / 2.0 y2 = (qpx(2j) + qpx(4.j)) / 2.0 th2 = qpx(5.j) roh2 = sqrt(((x2 - xo)**2) + ((yo - y2)**2)) drow = abs(roh2 - rot11 ) dang = abs(th2 - thl) v3 = sqrt(((x2 - x1)**2) + ((y2 - yl)4*2)) vln = float(ialen) / divf
zxl = qpx(l,j)
ZY 1 = qpxC&j) zx2 = qpx(3,j) zy2 = qpx(4j) zj = sqrt(((zx2 - zxl)**2) + ((zy2 - zyl)**2))
C if(dang.le.an.and.drow.le.ro) then if(v3.le.vln)then icon(i) = 0
C if(zj.ge.zi) then k=i l=j endif
C if(zj.lt.zi) then k=j l=i endif
qpx(l,W = wdl,l) qpx(W) = qpxCW qpx(3.k) = qpx(3,l) qpx(4.k) = qpx(4,l) qpx(Sk) = @x(5,1) + qpx(5M) / 2.0
C endif C
endif endif enddo enddo return end
C subroutine delpix(qpx.lnum,idb)
C This subroutine deletes edge pixels that have C been identified to form part of a line segment. *
parameter(ixmax=960) dimension qpx(5,lOOO) integer*2 idb(ixmax,ixmax) do 20 il = 1,lnum
Automatic lineament extraction
ix1 = int(qpx(l.il)) ix2 = int(qpx(3,il)) iyl = int(qpx(2,il)) $2 = int(qpx(&i 1)) dx = (ix2 - ixl) dy = (iy2 - iyl) k = abs(dx) n = abs(dy) if(k.gt.n) then c=dy/dx
C
if(ix 1 .gt.ix2) then kl = ix2 k2 = ix1 y = float(iy2) else kl = ix1 k2 = ix2 y = float(iy1) endif
C
do i = kl,k2 jx = i y=y+c jy = nint(y) idb(jx jy) = 0 enddo
else c=dx/dy
C
if(iyl.gt.iy2) then kl = iy2 k2=iyl x = float(ix2) else kl = iyl k2 = iy2 x = float(ix 1) endif
C
doi=kl,k2 x=xic jx = nint(x) jy = i idb(jxjy) = 0 enddo endif
20 continue 30 continue
return end
C
subroutine pspnt(title.fnljy) C this is a PostScript driver program for generating C hardcopy of image. * **************************************************
parameter(ixmax = 960) integer*2 ida(ixmax,ixmax) charactefl80 title.fn7,fn4.fnl,txt character* 1 iopt
582 V. Raghavan and others
dimension jy(4) C
open(5 1 ,file=fnl .form=‘UNFORMATlED’) read(5 1) title read(5 1) ncol.nlin,ipl,ill ,ip2,il2 do 10 i = l.nlin
10 read(5 1) (ida(k,i),k = 1 ,ncol) close(51) print *,’ Give title’ read(*,‘(a80)‘) title
C
print *r) Is it a binary image ? ’
C
call xmouse(ixl.iyl) call xb(30) call xf if(ixl.ge.334.and.ixl.le.376.aud.iyl.ge.jy(l).
1 and.iyl.le.jy(2)) then kopt = 2 else kopt = 1 endif
C
if(kopt.eq.2) then do5i= 1,ulin do5j=l,ncol if(ida(j.i).eq.O) then ida(j,i) = 255 else ida(j,i) = 0 endif
5 continue endif
C
lu=52 print *,’ Give Postscript output file name’ read(*,*) fu4
C
print *, ’ Are you using a color PostScript printer ? ’
C
call xmouse(ixl,iyl) call xb(30) call xf if(ixl.ge.334.and.ixl.le.376.and.iyl.ge.jy(l).
1 and.iyl.le.jyQ)) then iopt = ‘C else iopt = ‘M endif
C
open (lu,FlLl%fn4,IOSTAT=ios) write(lu,lOO)
100 format(‘/portrait (60 260 translate) bind def) xd = 1 ./float(ncol) yd = 1 .Moat(nlin) write(lu,lOl) xd,yd,ulin,ncol,nlin
101 format(‘/box (newpath 0 0 moveto ‘,t7.5,,lx,f7.5,’ scale 1 2 setlinewidth 0 ‘,i3.’ rlineto ‘,i3,’ 0 rlineto 0 -I, 1 i3.’ rlineto closepath stroke) bid def) write(lu,lO2) ncol.nlin
102 format (‘/box1 (newpath 0 0 moveto ‘,i3,1x, i3,
Automatic lineament extraction 583
1’ scale closepath) bind def) wlite(1u.103)
103 formats’ /nstr 10 string def ,/,‘/Courier-Bold findfont’,/, 1 ‘12 scalefont’J.‘setfont’J,‘portrait’J,’boxl’~, 1 ‘/DataString 1024 string def) write(lu, 105) ncol,nhn,ncol~in,nlin
105 format(i3,lx.i3,’ 8 (‘.i3.’ 0 0 -‘,i3,’ 0 ‘,i3.’ I’) write(lu.106)
106 format(‘{currenttile DataSuing readhexstring pop)‘, 1 /,‘image’)
C
do 200 i=nlin, 1 ,- 1 write (lu.40) (ida(j.i)j=l,ncol)
40 fomlat(64z2.2) 200 continue C
ik = int(float(nlin)/&O) write(lu.107) ik.nlin
107 format(‘box ‘,/,‘O ‘.i2,lx.i3.’ (dup dup 0 exch moveto -5 0’. 1 ’ rlineto 0.0 setgray stroke 4 sub -35 exch moveto’, 1 ’ 0 setgray nstr cvs show)‘,/.‘for’)
C
ik = int(float(ncol)/&O) write(lu.108) ik,ncol
108 format(‘0 ‘,i2,lx,i3,/,‘( dup dup 0 moveto 0 -5 rlineto stroke’. 1 ’ dup nstr cvs stringwidth pop 2 div sub -25 moveto nstr’ 1 (1 cvs show ) ‘J,‘for’)
write(1u.109) 109 format(‘/Courier-Bold findfont ‘J.94 scalefont’,’ setfont’) C
xt = float(ncol)/2.0 kt = int(xt) It = nlin + 15 write(lu.110) kt,lt
110 format(i3,lx,i3.’ moveto’) C
call chara(title.lu) write(lu, 111)
111 format(’ stingwidth pop 2 div 0 exch sub 0 rmoveto show’) print *,’ Wish to superimpose lineaments on image ? ’ call xmouse(ixl,iyl) call xb(30) call xf if(ixl.ge.334.and.ixl.le.376.and.iyl.ge.jy(l).
1 and.iyl.le.jy(2)) then C
if(iopt.eq.‘m’.or.iopt.eq.‘M’) then write(lu,l12)
112 format(‘l.0 setgray’J,‘[5 11 0 setdash’) endif
C
if(iopt.eq.V.0r.iopt.eq.C) then write(lu.114)
114 format(‘O.O 0.0 1.0 setrgbcolor’,/,‘[lO 11 0 setdash’) endif print *,’ Give file name ’ read(*,*) fn7 open(54,file = fn7,form=‘UNFORMAlTED’)
C
CAOEO 21/4-J
584 V. Raghavan and others
998 read(54.endS99) xl .y 1 .x2.y2 write(lu,l15) xl,ylJt2.y2
115 format(f5.l,lx,f5.1,‘moveto’.f5.l.lx,f5.l.’ lineto stroke’) go to 998
999 continue endif
C
print *,’ Click ANNOTATE to annotate image ’ call xmouse(ix1 .iy 1) call xb(30) call xf if(ixl.ge.l54.and.ixl.le.234.and.iyl.ge.jy(l).and.
1 iyl.le.jy(2)) then print *,’ Click END to finish annotation session’ call xsfc( 128)
C
885 call xmouse(ixl,iyl) call xb(30) call xf if(ixl.ge.36.and.ixl.le.68.and.iyl.ge.jy(l).and.
1 iyl.le.jy(2)) then go to 9991 endif print *,’ Type text ’ read(*,‘(a80)‘) txt call xds(ixl,iyl,txt) call xf kt = ix1 lt=nlin+l -iyl
C
if(iopt.eq.‘m’.or.iopt.eq.‘M) then write(lu.710) kt,lt
710 format(‘l.O setgray ‘,i3,lx.i3,’ moveto’) else write(lu.712) kt,lt
712 format(‘l.O 1.0 1.0 setrgbcolor ‘,i3,lx,i3,’ moveto’) endif
C
call chara(txt,lu) write(lu,7 11)
711 format(’ stringwidth pop 2 div 0 exch sub 0 rmoveto show’) C
go to 885 endif
9991 write(lu.116) 116 format(‘showpage’)
close(lu) close(54) return end
C
subroutine chara(title.lu) C this is a subroutine for determining the number of C characters in a given alphanumeric string. * ***Y**********%%****%%**%%*%%*%**%**%*****%**%****
character*80 title C
Automatic lineament extraction 585
11 = lcstart(title) 12 = lcend( title) length = len(title(l1:12)) write(lu, 10)
10 format(‘(‘,$) do i = 1,length write (lu.15) title(i:i)
15 format (al& enddo write(lu,20)
20 format(‘) dup.) return end
C
integer function Icstart(x) characte~80 x character* 1 2
1 = len(x) dolOi=l.l 2 = x(i:i) if (z.ne.’ ‘) go to 20
10 continue 20 lcstart=i
return end
C
integer function lcend(x) charactefl80 x character* 1 z 1 = len(x) do 10 i=l,l n=l-i+l z = x(n:n) if(z.ne.’ ‘) go to 20
10 continue 20 lcend= n
return end
C
subroutine display(ir.ig,ib.fnljy) C this is a subroutine for dispaying original image C and superimposing machine interpreted lineaments C on the original image. * ****************************************~********
diinsion iG?56).ib@56),ig(256) jx(4) jy(4) integer*2 ida(96096O),ip(960) character%0 title.str,menu.strl .fnl .fn5,fn6 logical there open(5 1 .file =fn l,form=‘UNFoRMATIED’) read(5 1) title read(5 1) ncol.nlin,ip 1 ,il 1 .ip2.i12
do 10 k = l.nlin read(5 1) (ip(i)j = 1 ,ncol) iy = nlin+l - k do 11 I= l.ncol ida(l.iy) = ip(1)
11 continue 10 enddo
close(5 1)
586 V. Raghavan and others
call xcsw(ncol+50,ulin+50.ir,ig,ib) call xmouse(idumx.idumy) call xb(30) ca1t xf
doi=l,ulin do j = Lncol iy = i idd = ida(j,i)/2 call xsfc(idd) call xdp(j+25,iy+l5) enddo enddo
call xsbc(64) call xsla( 3.0) menu = ‘END
jy(1) = (nlin+l5)+6 jy(2) = (ulin+15)+19 jy(3) = (nlin+15)+19 jy(4) = (nlin+15)+6 jx( 1) = 36 jx(2) = 36 jx(3) = 68 jx(4) = 68
C
call xfpll(jx,jy) call xf catt xsfc( I29) kx=3g ky = (nlin+l5)+17 call xds( kxky.menu) call xf
C
call x&$128) jx(1) = 96 jx(2) = 96 jx(3) = 138 jx(4) = 138 call xfp4(jxjy) call xf
call xsfc( 130) kx=kx+60 menu = ‘DRAW
call xds( kxJry,menu) call xf
call xsbc( 129) jx(1) = 154 jx(2) = 154 jx(3) = 234 jx(4) = 234
call xf&jx,jy) call xf
C
call xsfc( 127)
kx=kx+60
menu = ‘ANNOTATE
Automatic lineament extraction 587
call xds( kxJcy,menu) call xf call xsbc(128) jx(1) = 254 jx(2) = 254 jx(3) = 326 jx(4) = 326 call xfp4(jx,jy) call xf
C
call xsfc( 17) kx=kx+loo menu = ‘DISPLAY call xds( kxSy,menu) call xf
C
call xsbc( 129) jx( 1) = 336 jx(2) = 336 jx(3) = 378 jx(4) = 378 call xfp4Qxjy) call xf
C
call xsfc( 127) kx=kx+80 menu = ‘OKAY call xds( kx,ky,menu) call xf
C
strl = ’ Click mouse to select’ 997 call xsfc( 129)
call xds(25,(nlin+48),strl) call xf call xmouse(ixl,iyl) call xb(30) if(ixl.ge.36.and.ixl.le.68.and.iyl.ge.jy(l).and.
1 iyl.le.jy(2)) then go to 996 endif
C
if(ixl.ge.254.and.ixl.le.326.and.iyl.ge.jy(l), 1 and.iyl.le.jy(2)) then print *,’ Give file name’ read (*,*) fn6 open(52,file=fn6,form=‘UNFORMAlTED’)
C read(52) lnum,ipl,ill,ip2,i12 222 read(52,end=998) xl,yl,x2,y2
ix1 = int(x1) + 25 ix2 = int(x2) + 25 iyl = nlin + 1 - int(y1) + 15 iy2 = nlin + 1 - int(y2) + 15 call xsfc( 128) call xdl(ixl ,iy l ,ix2,iy2) call xf go to 222 endif
998 close(52) C
if(ixl.ge.96.and.ixl.le.138.and.iyl.ge.jy(l).and. 1 iyl.le.jy(2)) then
588 V. Raghavan and others
print *,’ Give filename for storing line co-ordinates’ read(*.*) fn5
C
open(58,file=fn5,f~=‘UNFORMA1TED’,status=’UNKNOWN’)
inquire(58,EXiST=there) if(there) then
333 read(58,end=lW8) xl,yl,x2.y2 ix1 = int(x1) + 25 ix2 = int(x2) + 25 iyl = nlin + 1 - int(y1) + 15 iy2 = nlin + 1 - int(y2) + 15 call xsfc( 128) call xdl(ix1 jy 1 jx2.iy2) call xf go to 333
1998 continue endif
C
print *,’ Click END to finish drawing session’ call xsfc( 129)
223 continue call xmouse(ix1 jyl) call xb(30) if(ixl.ge.36.and.ixl.le.68.and.iyl.ge.jy(l).and.
1 iyl.le.jy(2)) then go to 995 endif call xmouse(ix2jy2) call xb(30) xl = float(ix1) - 25 yl = nlm+l- float(iy1) +15 x2 = float(ix2)-25 y2 = nlin+l_float(iy2) + 15 write(58) xl.yl,x2.y2 call xdl(ix1 ,iy 1 .ix2,iy2) call xf go to 223 endif
995 close(58) C
if(ixl.ge.l54.and.ixl.le.234.aud.iyl.ge.jy(l).and. 1 iyl.le.jy(2)) then print *,’ Click END to finish annotation session’ call xsfc( 128)
C
885 call xmouse(ixl.iyl) call xb(30) if(ixl.ge.36.and.ixl.le.68.and.iyl.getjy(l).and.
1 iyl.le.jy(2)) then go to 999 endif print *,’ Type text ’ read(*.‘(a80)‘) str call xds(ix1 jy 1 .str) call xf go to 885 endif
999 continue C
go to 997 996 return
end
Automatic lineament extraction 589
APPENDIX II
#include d[l l/Xlib.h> #include <xl l/Xutil.h> #include cstdio.h> #include <xl l/Xatom.b> P program xfdispx.c
this is a C language driver program for making calls to Xlib graphics functions that are used in the START program. All character strings starting with a capital letter are standard Xlib functions. Last edited on 4th December, 1993. Programmed at the Osaka City University, Japan.*/
Display *d; Window w; Gc gc; colormap cmap; XColor colorI2561; Font fl;
xcsw_(iwx,iwy.ir.ig,ib) int *iwx,*iwy; int ir[256].ig[256].ib[256];
1 Window r; int i;
d = XOpenDisplay (NULL); cmap=DefaultColormap(d,O);
for ( i=O; i&55; i++ ) I color[i].red =65535*ir[i]/255; color[i].gteen=65535*ig[i]/255; color[i].blue =65535*ib[i]/255; XAllocColor(d,cmap.&color[i]); I
r = DefaultRootWindow (d);
w=XCreateSimpleWindow (d,r,100,100,*iwx.*iwy.2,0,0); XMapWindow (d,w); gc= XCreateGC (d,r,O,O);
fl=XLoadFont (d,“-adobe-courier-bold-o-normal--14-140-75-75-m-90-iso8859-1”); XSetFont (d,gc,fl);
XSelectInput(d. w, ExposureMasklButtonPressMask);
XSetFillRule (d,gc,WindingRule);
XFlush(d);
return; ]
XfpuX,Y) int x[41,y[41;
1 static XPoint p[5];
590 V. Raghavan and others
XFil~olygon(d,w,gc,pS,Complex,CooniModeOrigin); return; 1
xsfc_(icl) int *icl;
( XSe@oregrouud (d,gc,color[*icl].pixel); return;
I
xsbc_(icl) kit *id- ,
I XSetBackground (d,gc,coIor[*icll.pixel); return;
1
xdl_(xl.yl,x2.y2) int *x I ,*y I ,*x2,*y2;
( XDrawLiue (d,w,gc,*xl,*Yl,*x2,*y2); return;
I xb_(iper)
int Yper;
XBell(d,*iper); I
XL0 I
mush(d); return;
xdw_()
XDestroyWindow(d,w); XRush(d); return;
x&O
1 XCloseDispiay(d);
1
xdp_(ix,iY) int *ix,*iy;
Automatic lineament extraction 591
1 XDrawPoiut(d,w,gc,*i,*iy); return;
I
Xds_(X,Y,str) int *x.*y; char str[SO];
( XDrawString (d,w,gc,*x,*y,str,SO);
xmouse_(ix. iy) int *ix, *iy;
( XEvent event:
XNextEvent(d, &event); switch(event.xany.type) (
case ButtonPress: *ix = event.xbutt0n.x; *iy = event.xbutt0n.y;
xsla_(lw.ls) int *Iw.*ls;
1 if (*ls==O) I XSetLinek’tibutes (d,gc,*lw,LineSolid.CapButtJoinMiter);
1 if (*Is-l) ( XSetLineAttributes (d,gc.*lw,LineOsh,CapBut~oinMiter);
1 if (*ls==2) ( XSetLineAttributes (d.gc,*lw,LineDoubleDash,CapButt,JoinMiter); I
XClearWindow (d.w); XFlush(d); return;