IMAGE: a FORTRAN V program for image analysis of particles

23
Computers & Geosciences rot. 13. No. I. pp. 37-59. 1987 0098-3004,87 $3.00 + 0.00 Printed in Great Britain. Pergamon Journals Ltd IMAGE: A FORTRAN V PROGRAM FOR IMAGE ANALYSIS OF PARTICLES JOHN S'rARKEYand SANDRASIMIGIAN Department of Geology. University of Western Ontario. London. Ontario. Canada N6A 3B7 (Received 10 February 1986: accepted 30 July 1986) Abstract--A FORTRAN V computer program. IMAGE. has been developed which recognizes individual particle boundaries from a digitized image. The data ['or IMAGE are obtained from a transparency using an X- Yrecording microdensitometer. For each particle the program also computes the size. long dimension and width at right angles to it. aspect ratio, center of gravity, length of the perimeter, and orientation of the long dimension. The form of a particle is analyzed by deriving a regular geometric shape, such as a rectangle or an ellipse. Three regular shapes are computed for comparison, enveloping rectangle, area ellipse, and best-fit ellipse. Key Wordr: Image analysis. Digitize, Form analysis. Microdensitometer. Particles. Pixel. INTRODUCTION The method described here uses data obtained by an X-Y recording microdcnsitomctcr from a photo- micrograph. A computer program, iMAGE, analyzes the data and recognizes individual particles and com- putes the following parameters for each particle: area, length of the perimeter, long dimension and width at right angles to it, aspect ratio, center of gravity, and orientation of the long dimension. Particles of any shape, including particles with "holes" are analyzed. The program eliminates particles which are not com- pletely within the area of the photomicrograph. For each particle the program also fits regular shapes, rectangles, and ellipses, to the irregular particle boun- daries. The data obtained from IMAGE for the individual particles are combined to compute averages for the aggregate. In particular, average ellipses and rectang- les are fitted to the data which summarize size, aspect ratio, and orientation of the long axes of the particles in the aggregate (Simigian and Starkey, 1986). PROCEDURE A number of preliminary steps are required before the data are obtained, these are illustrated in Figure !. A photomicrograph of the specimen, in this situation ribbon-quartz from the Saxony Granulites (Kolisnik, 1985; Starkey. 1979). is enlarged to 125 × 175ram. this is the size of film which can be examined by the Optronics P-1000 optical microdcnsitomctcr used in this study. A sheet of transparent acetate is placed over the photograph and all the boundarics to be measured are traced (Fig. 2). Any particles which are to be ignored are blackened. This permits the selection of features which will be measured and the elimina- tion of others, such as fractures and scratches produced during sample preparation. However. in othcr specimcns this step of tracing thc photograph on to thc acctatc may not be ncccssary if a photo- graphic ncgativc can be prcparcd in which thc fcatures of intcrcst are suflicicntly wcll dclincatcd. The quantification of thc imagc is accomplishcd by digitization using an Optronics International Photo- scan system P-1000, which is similar to thc drum microdensitomcter described by Moore (1968). This microdcnsitometcr samples the image on a square raster, and at each point the optical density of a square elcment of the image, a pixel, is determined. The grid spacing oftbe raster and the pixel size can be varied, in this study they were both set at 200p. The microdcnsitometer writes the digitized information, in 8-bit natural binary code, onto a magnetic tape as a series of records, one record for each scan of the image. Once the quantization is complete, the magnetic tape from the densitometer is read by the program, IMAGE, and the results are printed and plotted as required. PROGRAM OUTLINE The program, I M AG E, consists of a main routine, ten subroutines, and one function as well as some common machine-dependent functions. A flowchart of the program is illustrated in Figure 3 and the listing of the program is given in the Appendix. Before the microdcnsitometer file is read, subroutine FRAME is called to plot the X-Y axes for the final plots. One record at a time is read from thc microdcnsitometcr filc into the buffer of the CDC Cyber 170 series 835, installed in the Acadcmic Computing Center of the University of Western Ontario. The word size of the Cyber is 60 bits and hence the record is stored as an array of 60-bit words, each of which contains seven 37

Transcript of IMAGE: a FORTRAN V program for image analysis of particles

Page 1: IMAGE: a FORTRAN V program for image analysis of particles

Computers & Geosciences rot . 13. No. I. pp. 37-59. 1987 0098-3004,87 $3.00 + 0.00 Printed in Great Britain. Pergamon Journals Ltd

IMAGE: A FORTRAN V PROGRAM FOR IMAGE ANALYSIS OF PARTICLES

JOHN S'rARKEY and SANDRA SIMIGIAN Department of Geology. University of Western Ontario. London. Ontario. Canada N6A 3B7

(Received 10 February 1986: accepted 30 July 1986)

Abstract--A FORTRAN V computer program. IMAGE. has been developed which recognizes individual particle boundaries from a digitized image. The data ['or IMAGE are obtained from a transparency using an X- Y recording microdensitometer. For each particle the program also computes the size. long dimension and width at right angles to it. aspect ratio, center of gravity, length of the perimeter, and orientation of the long dimension.

The form of a particle is analyzed by deriving a regular geometric shape, such as a rectangle or an ellipse. Three regular shapes are computed for comparison, enveloping rectangle, area ellipse, and best-fit ellipse.

Key Wordr: Image analysis. Digitize, Form analysis. Microdensitometer. Particles. Pixel.

INTRODUCTION

The method described here uses data obtained by an X - Y recording microdcnsitomctcr from a photo- micrograph. A computer program, iMAGE, analyzes the data and recognizes individual particles and com- putes the following parameters for each particle: area, length of the perimeter, long dimension and width at right angles to it, aspect ratio, center of gravity, and orientation of the long dimension. Particles of any shape, including particles with "holes" are analyzed. The program eliminates particles which are not com- pletely within the area of the photomicrograph. For each particle the program also fits regular shapes, rectangles, and ellipses, to the irregular particle boun- daries.

The data obtained from IMAGE for the individual particles are combined to compute averages for the aggregate. In particular, average ellipses and rectang- les are fitted to the data which summarize size, aspect ratio, and orientation of the long axes of the particles in the aggregate (Simigian and Starkey, 1986).

PROCEDURE

A number of preliminary steps are required before the data are obtained, these are illustrated in Figure !. A photomicrograph of the specimen, in this situation ribbon-quartz from the Saxony Granulites (Kolisnik, 1985; Starkey. 1979). is enlarged to 125 × 175ram. this is the size of film which can be examined by the Optronics P-1000 optical microdcnsitomctcr used in this study. A sheet of transparent acetate is placed over the photograph and all the boundarics to be measured are traced (Fig. 2). Any particles which are to be ignored are blackened. This permits the selection of features which will be measured and the elimina- tion of others, such as fractures and scratches

produced during sample preparation. However. in othcr specimcns this step of tracing thc photograph on to thc acctatc may not be ncccssary if a photo- graphic ncgativc can be prcparcd in which thc fcatures of intcrcst are suflicicntly wcll dclincatcd.

The quantification of thc imagc is accomplishcd by digitization using an Optronics International Photo- scan system P-1000, which is similar to thc drum microdensitomcter described by Moore (1968). This microdcnsitometcr samples the image on a square raster, and at each point the optical density of a square elcment of the image, a pixel, is determined. The grid spacing oftbe raster and the pixel size can be varied, in this study they were both set at 200p. The microdcnsitometer writes the digitized information, in 8-bit natural binary code, onto a magnetic tape as a series of records, one record for each scan of the image.

Once the quantization is complete, the magnetic tape from the densitometer is read by the program, IMAGE, and the results are printed and plotted as required.

PROGRAM OUTLINE

The program, I M AG E, consists of a main routine, ten subroutines, and one function as well as some common machine-dependent functions. A flowchart of the program is illustrated in Figure 3 and the listing of the program is given in the Appendix. Before the microdcnsitometer file is read, subroutine FRAME is called to plot the X-Y axes for the final plots. One record at a time is read from thc microdcnsitometcr filc into the buffer of the CDC Cyber 170 series 835, installed in the Acadcmic Computing Center of the University of Western Ontario. The word size of the Cyber is 60 bits and hence the record is stored as an array of 60-bit words, each of which contains seven

37

Page 2: IMAGE: a FORTRAN V program for image analysis of particles

38 J. STAgKEY and S. SIMIGIAN

M I cro$coDe Pl~otogroDtl Acilfotll Densltometer

Image acquisition

ToPe

Comoefer

~: :> Image storage and processing

Ptof$ Tobte$ GroDhlc$

Resutfs

Figure I. Flow diagram for image analysis.

Figure 2. Tracing of particle boundaries, originally prepared on transparent acetate.

and one-half 8-bit, bytes. The function NEXT pro- cesses pairs of the 60-bit Cyber words which contain fifteen 8-bit bytes as written by the microden- sitometer. Individual microdensitometer data are ex- tracted by masking the word pairs. The function NEXT would have to be modified for use with com- puters with a different word length.

The data extracted by NEXT from one record are stored in a singly dimensioned array, ISCANC, which thus corresponds to one scan of the image by the microdensitometer. The data recorded for each ele- ment of the scan are converted to integer ones or zeros, depending on whether the optical density is high or low, thus a binary data file is produced. Figure 4 shows part of a record representing a traverse across a black boundary with typical density values recorded in each element. The transparent acetate has an opti- cal density of approximately 7. The maximum binary number stored in a byte is 2' or 256, thercforc thc range of numbers is between 0 and 255, the optical

density of the black areas of the acetate tracing attain the maximum value of 255. In this instance a thresh- old value oi"25 is sch.'ctcd to distinguish between black and transparent areas, and any values < 25 are con- sidered to be white and are converted to the integer value one, whereas values greater than or equal to the threshold value are considered to be black and are converted to a zero, Figurc 4 illustrates that the thick- ness of the particle boundary was 18 pixels (0.36 ram), this was obtained using a 0.5 Rapidograph pen to prepare the tracing.

AFter the first scan has been converted to a binary record in ISCANC this is stored as ISCANB, the second microdensitometer record is read, processed by the function NEXT and is stored as ISCANC. The array, ISCANB, which now contains zeros and ones corresponding to one record of microdensitometer data is analyzed pixel by pixel. If a pixel contains a one, it is considered to be part of a particle and a number which acts as a reference to that particle is assigned to it. As each new particle is located they are numbered consecutively (Fig. 5a). This assigned number serves to link all the information about that particle.

Once the scan stored in ISCANB has been pro- ecssed and the reference numbers assigncd, it is stored in ISCANA and ISCANC is stored in ISCANB. The next record is read, processed by the function NEXT and stored as ISCANC. Thus, data for three scans are stored in memory. ISCANB is compared with IS- CANA and continuing particles arc identified by the juxtaposition of the pixcls containing ones. A particle is flagged with a large negative number, if it has been determined to be in the first or last scan or in the first or last pixcl oFa scan. Such a flagged particle therefore

Page 3: IMAGE: a FORTRAN V program for image analysis of particles

Image analysis of particles 39

! Sot ¢o~$fonts J

I Lo¢ofe eoch porficl.e

l I.o¢ofe perlmelor

~ n s

Figure 3. Flowchart of computer program IMAGE; names of subroutines are capitalized.

is recognized as a particle which extends beyond the border and it is not considered further.

In subroutine A D D I N G the area of a particle is determined by counting the number of pixcls in IS- CANB which corresponds to the particle. Because the particle can extend over many scans, the area is in- cremented and stored in an array. In addition the X-coordinate of each pixel, which is its location in the scan, and the Y-coordinate, which is the number of the scan, are summed and stored separately.

It is usual for two or more particles on one scan to combine into a single particle on the next scan (Fig.

Threshold

Threshold

7 1 6 1 9 1 l 1 6 1 5 1 5 1 6 l

_10 1 - - 82 0

205 0 245 0 255 0 255 0 255 0 255 0 255 0 255 0 255 0 255 0 255 0 113 0 84 0 95 0 129 o 101 0

~27 0 - I 1

l 1 l I l I 5 I 7 I

Particle

Boundary

Particle

Figure 4. Portion of re~ord as written by microdensitometer. Next to it is converted record lUled with ones and zeros, ones reprc~nt particle and zeros repr¢~nt boundary b~twccn particles. Note, particle boundary is 18 pixcls wide and

threshold value is set to 25.

5b). Subroutine MIDSPOT is called to identify such bifurcations. If one is identified then the two parts of the particle are assigned the lowest reference number and all the corresponding data such as those per- raining to the size and X- Y coordinates are identified and indexed accordingly. If a particle with a shape analogous to an upside down "U" occurs, it is not considered to have bifurcated because the separate arms are assigned automatically the same reference number.

The perimeter pixels of the particle are identified by considering ISCANA. ISCANB, and ISCANC together. Because a pixel is a square element of the image then a perimeter pixel is one which is located in ISCANB and has one or more of the adjacent pixels occupied by a zero, Once such a pixel has been iden- tified, subroutine NUMB is called to store the X-coor- dinate, Y-coordinate, and refrence particle number of the pixel.

Finally. subroutine ENDS is called to determine if any particles have terminated. If a particle is present in ISCANA but not in ISCANB then that particle has terminated and subroutine SHAPE is called.

in SHAPE, the particle is first checked to sec if it is flagged as a border particle or is a particle so small that it is considered to be dust, these small spots are summed as IDUST. in either situation the data are ignored and the program returns to ENDS to retrieve another finished particle. If the particle is entirely

Page 4: IMAGE: a FORTRAN V program for image analysis of particles

40 J. STARr~Y and S. SIMIGIAN

(a)

8~FORE [0lolo]I111£IoloI~111ololololoI~'111~111oI)111ololc3J

"FTER [dl01011 11 l;'10101zlzlolo101010131]1313101~l~ 101010l

Figure 5a. BEFORE: data from microdensitometer record converted to ones and zeros. AFTER: data from microdensitometer record in which ones. representing particles, are replaced with identification numbers

for each particle.

(b)

Iololo1~1: I~ l o l o l t l ~ l o l o l o l o l o l a a ~ o l ~ l ~ l o l o i o I

A Io]'o 11' 11 I~ I! lo Io Io U t : I ~ o'1o m ~ o Io Iol'- I~ 14 Iol

B Iololoi~ i~ I~ I~'[o Io [ o . m , ~ , , ~ , ~ o Io Io 141o Iol

Figure 5b. Bifurcated particle. Particles 2 and 3 converge on scan B and data pertaining to particle 3 are added to particle 2 and identification numbers are changed to 2"s.

Y- oxis (ram)

I0 20 30 40 50 ~0 70 O0 90 tO0 II0 120 130 140 150 160 I . , t , i I l I J I I I I J l ) t

Figure 6. Computer-drawn particle boundaries from photomicrograph of quartz particles from Saxony Granulites (of. Fig. 2).

within the area being analyzed, SHAPE uses the A'-Y coordinates of the peripheral pixels and the size of the particle to calculate and store the area, center of gravity, long dimension and the width at right angles to it, aspect ratio, the length of the perimeter and the angle of inclination of the long dimension of the particle relative to the Y-axis of the image.

Subroutine DRAW is called from SHAPE and the particle is drawn on a Calcomp plotter, in DRAW the perimeter pixels are sorted and plotted sequentially as contiguous elements of the periphery. The plot (Fig. 6) permits ready comparison with the acetate tracing

(Fig. 2) to indicate the particles which were analyzed. After the particle has been plotted control of the program returns to SHAPE.

in the subroutine SHAPE, three other subroutines are called, BESTFIT. RECTANG, and ELLIPSE. These subroutines calculate and plot regular shapes which describe the particles (Simigian and Starkey, 1986), an example of the best-fit ellipses calculated from Figure 2 is illustrated in Figure 7. The par- amcters calculated for the particles in these sub- routines are written to an output file. Upon returning to the main routine of the program, ISCANB is stored

Page 5: IMAGE: a FORTRAN V program for image analysis of particles

Image analy~s of particles 41

G"

3 ~

Y-ox is (ram)

10 20 30 40 50 60 70 80 90 100 110 120 130 14'0 150 tgO I I I 1 I I 1 l ] I I [ I [ I

Figure 7. Computer drawn best-fit ellipses corresponding to particles shown in Figure 6.

in ISCANA, [SCANC is stored in ISCANB, and a eering Research Council of Canada. which gratefully is ack- new record is read into ISCANC. nowledgcd.

DISCUSSION

The image-analysis system described hcre mostly is automated, but it does require the transfer of data between the X-Y recording microdensitometer and the mainframe computer and therefore is not interac- tive. It also is a software-based method of image processing not machine based (Moore. 1968). This type of image processing has advantages over machi- ne-based systems such as lower initial expense and flexibility, especially for research use, where only lim- ited numbers of images are being processes (Fabbri, 1984). Alternative image-analysis systems are des- cribed in Ehrlich and others (1984), Fabbri (1984), and Serra (1982).

Acknowledfments---This research was supported by oper- ating grant A3555 from the National Science and Engin-

REFERENCES

Erhlich, R., Kennedy, S. K., Crabtree. S. J., and Cannon, g. L., 1984. Petrographic image analysis. !. Analysis of reservoir pore complexes: ]our. Sed. Pet., v. 54. no. 4, p. 1365--I 378.

Fabbri, A. G., 1984, Image processing of geological data: Van Nostrand Reinhold Co., New York. 244p.

Kolisnik. A., 1985, Grain shape and crystallographic orientation fabric of quartz in the Saxony granulites: unpubl, bachelor thesis. Univ. Western Ontario, 82p.

Moore, G. A., 1968, Automatic scanning and computer processes for the quantitative analysis of micrographs and equivalent subjects, in Cheng. G. C.. Ledlcy. R. S.. Pollack, D. K., and Rosenfeld. A.. eds., Symposium on automatic photointerpretation, Pictorial pattern recog- nition. Washington, DC., p. 275-326.

Scrra. J.. 1982. Image analysis and mathematical morphol. ogy: Academic Press. New York. 6lOp.

Simigian, S.. and Starkey. J.. 1986, Automated grain shape analysis: Jour. Struct. Geology. v. 8. no. 5. p. 589-592.

Starkey, J.. 1979, Pctrofabric analysis of Saxony granulites by optical and X-ray diffraction methods: Tectonophys- ics, v. 58. no. I-2, p. 201-219.

A P P E N D I X

The program IMAGE as listed runs on the CDC Cyber 170 series 835 Computer, installed in the Academic Computing Center of the University of Western Ontario. The following statements are specific to this installation.

The initial PROGRAM statement opens the files TAPEI0, TAPEI !, etc. for reading or writing data. The BUFFER IN statement performs auto buffering. Records are read from the microdcnsitometer file on TAPEI0,

which is written in 8.bit natural binary, and stored into a two dimensional array IBUFFR. The first dimension of IBUFFR indicates the length of the record, in words, the second dimension serves to alternate between two buffers so that the data in one can be processed while data are read into the other.

The SHIFT function masks the packed data stored in 60-bit words in IBUFFR to enable the individual 8-bit bytes to be extracted and stored, unpacked, in ISCANC.

Page 6: IMAGE: a FORTRAN V program for image analysis of particles

42 J. STARKEr' and S. SIM|GIAN

PROGRAM IMAGE (OUTPUT,TAPEI0,TAPEII ,TAPEI2,TAPEI4)

C C *** **

C A PROGRAM TO: C I. READ A DENS ITOMETER TAPE. C 2. STORE THE DATA INTO A MATRIX. C 3. LOCATE GROUPS OF DATA CREATER THAN BACKGROUND, C CORRESPONDING TO THE SPOTS. C 4. PRINT OUT PERTINENT PARAMETERS. C SPOTS WHICH INTERSECT THE EDGES OF THE MATRIX ARE ELIMINATED.

C THREE ROWS OF THE MATRIX ARE LOCATED IN MEMORY AT ONE TIME. C THE ORIGIN OF THE MATRIX IS CONSIDERED TO BE THE UPPER RIGHT C HAND CORNER. C THE ANGLES ATHETA AND BTHETA ARE MEASURED FROM THE

C PERPENDICULAR TO THE SCAN DIRECTION. IN THE FINAL OUTPUT C THE X-AXIS IS THE Y-AXIS OF THE PLOTTER. C***** C

COMMON /LOOK/ ISCANB ( 800), ISCANA(800), LIMIT, IX, ICOUNT CO.',tMON /PERPH/ NUM, IXCORD(6000), IYCORD(6000) ,NUMBER(6000) COMMON /SAVE/ ISPOT( 500), IXC(500), IYC(500) ,KOUNT, IDUST COMMON /CONST/ PI,RAD COHHON /STORE/ IS IZE(500 ) , IXX(500 ) , IYY(500 ) COMMON /BUFF/ IBUFFR(512,2) DIMENSION IBAD(IO0) , ISCANC(800) CALL PLOTS (200,75.0,I0.75,2) CALL FRAME (2.35) CALL FRAHE (12.0) CALL FRAHE (21.5) CALL FRAHE (31.0)

C C*****

C DESCRIPTIONS OF VARIABLES IN COMMON. C***** C C C C C C C C C C C C C C C C C C C C C C C C C C C C

*ISCANA AND ISCANB* STORE TWO RECORDS FROM THE DENSITOMETER FILE.

*LIMIT* IS THE MAXIMUM LENGTH OF THE RECORD. *IX* IS THE NUMBER OF THE RECORD AND DEFINES THE Y-AXIS. *ICOUNT* IS A CONSECUTIVE NUMBER ASSIGNED TO EACH PARTICLE. *ISPOT* STORES THE SIZE OF PARTICLES FOR EACH FINISHED PARTICLE. *ISIZE* STORES THE SIZE OF PARTICLES ON THE CURRENT SCAN. *IXC* STORES THE X-COORDINATES OF THE FINISHED PARTICLES. *IXX* STORES THE X-COORDINATES OF PARTICLES ON THE CURRENT SCAN. *lYe* STORES THE Y-COORDINATES OF THE FINISHED PARTICLES. *IYY* STORES THE Y-COORDINATES OF PARTICLES ON THE CURRENT SCAN. *NUM* IS THE NUMBER OF PERIMETER PIXELS OF ALL PARTICLES

COMBINED. *IXCORD* STORES THE X-COORDINATES OF PERIMETER PIXELS. *IYCORD* STORES THE Y-COORDINATES OF PERIMETER PIXELS. *NUMBER* STORES THE PARTICLE NUMBER OF PERIMETER PIXELS. *ALONG* IS THE LONGEST AXIS OF EACH FINISHED PARTICLE. *ASHORT* IS THE SHORT AXIS OF EACH FINISHED PARTICLE CALCULATED

USING THE FORMULA FOR THE AREA OF ELLIPSE. *ATHETA* IS THE ANGLE OF INCLINATION OF ALONG WITH RESPECT TO

THE K-AXIS FOR EACH FINISHED PARTICLE. *KOUNT* IS THE TOTAL NUMBER OF FINISHED PARTICLES. *IDUST* IS THE NUMBER OF THE PARTICLES WITH A SIZE GREATER THAN I

BUT LESS THAN I0 PIXELS. *RSHORT* IS THE SHORT AXIS DEFINED AS THE MAXIMUM DIMENSION AT

RIGHT ANGLES TO ALONG FOR EACH FINISHED PARTYCLE. *BLONG* IS THE LONG AXIS CALCULATED USING AN EIGENVALUE METHOD

FOR EACH FINISHED PARTICLE.

Page 7: IMAGE: a FORTRAN V program for image analysis of particles

Image analysis of panicles

C *BSHORT* IS THE SHORT AXIS CALCULATED USING AN EIGENVALUE

C ~THOD FOR EACH FINISHED PARTICLE. C *BTHETA* IS THE ANGLE OF INCLINATION OF BLONG WITH RESPECT TO C THE X-AXIS FOR EACH FINISHED PARTICLE.

C***** C

P, = ATAN( 1.0)'4.0 PAD = 1 8 0 . 0 / P I IX ffi - 1 ITHRES ffi 240 [DUST ffi 0

KOUNT = 0 NUM ffi 0

ICOUNT = 0 DO 10 I = 1 , 5 0 0

ISPOT(1) = 0 i x c ( i ) - o IYC(1) - 0

10 CONTINUE LREC = l

C C***** C READ INITIAL SCAN AND DETERMINE ITS LENGTH. C***** C

BUFFER IN (I0,I) ([BUFFR( I,LREC),IBUFFR(512,LREC)~ IF (UNIT(IO)) 30 , 300 , 20

20 WRITE (14,80) 30 CONTINUE

LEN = LENGTH(lO) WRITE (14,40) LEN

40 FORMAT ('I',' ','LEN = ',IlO) ILEN = ((5000*(32-0))/200) ILEN = ILEN-2 LIMIT = ILEN-4 WRITE (14,50) LIMIT

50 FORMAT (' ','LIMIT',IIO) 60 IF (UNIT(IO)) 90 , 300 , 70 70 WRITE (14,80) 80 FORMAT (I ','ERROR') 90 LREC2 = 3-LREC

C C***** C HEAD SUBSEQUENT SCANS. C * * * * *

C BUFFER IN (I0,I) (IBUFFR(I,LREC2),IBUFFR(LEN,LREC2))

IX = IX+I C C***** C C C***** C

DO I00 I = 5,1LEN I I = I-4 ISCANC ( I I ) mm NEXT( I , LREC ) IF ( I S C A N C ( I I ) . L T . I T H R E S ) I S C A N C ( I I ) = 0 IF (ISCANC(II).GE.ITHRES) I S C A N C ( I I ) = 1

lO0 CONTINUE IF ( IX.EQ.O) GO TO 280

SET DATA IN THE SCAN TO I IF DARKER THAN THRESHOLD, OTHERWISE SET TO 0 .

43

Page 8: IMAGE: a FORTRAN V program for image analysis of particles

44 J'. ST*~r,~ and S. S~o~N

C~rka-k* C LOCATE PARTICLES ON ISCANB

C KOURT EQUALS THE TOTAL NUMBER OF PARTICLES LOCATED AND ICOUNT C EQUALS THE NUMBER OF PARTICLES ON ISCANB. C***** C

MINB = 0

DO 190 J = I,LIMIT IF ( I S C A N B ( J ) . E Q . 0 ) GO TO 110 IF (J.EQ.LIMIT.AND.MINB.NE.O) GO TO 130 IF (J.EQ.LIMIT.AND.MINB.EQ.0) GO TO 120 IF (MINB.EQ.O) MINB = a

GO TO 190 110 IF (MINB.EQ.0) GO TO 190

MAXB - J - I

GO TO 140

120 MINB - LIMIT 130 MAXB = LIMIT 140 IF (IX.NE.I) GO TO 160

ICOUNT - ICOUNT+I DO 150 L = MINB,MAXB

ISCANB(L) " ICOUNT ISIZE(ICOUNT) = -I00000

150 CONTINUE CO TO 180

C C***** C C***** C

160

PARTICLE FOUND IN ISCANB - CHECK CONTINUATION IN ISCANA.

MINA - MINB-!

IF (MINA.LT.I) MINA - l MAXA - MAXB+I

IF (MAXA.GT.LIMIT) MAXA = LIMIT DO 170 K = MINA,MAXA

IF (ISCANA(K).EQ.O) GO TO 170 LL - ISCANA(K) CALL MIDSPOT (MINB,MAXB,K,MAXA,LL)

GO TO 180 170 CONTINUE

ICOUNT = ICOUNT+I CALL ADDINC (MINB,MAXB,ICOUNT)

180 MINB = 0 190 CONTINUE

IF ( I X . B Q . I ) CO TO 260 C C***** C FIND THE XmY COORDINATES FOR THE PERIMETER PIXELS OF EACH C PARTICLE. C***** C

INDEX - 1 DO 200 I " I,ICOUNT

IF (ISPOT(1).GE.O) GO TO 200 IBAD(INDEX) - I

INDEX - INDEX+I 200 CONTINUE

IBAD(INDEX) - 0

DO 230 K = I,LIMIT DO 210 I - I,INDEX

IF ( ISCANB(K).EQ.IBAD(I)) CO TO 230

Page 9: IMAGE: a FORTRAN V program for image analysis of particles

Image analysis of panicles

210 CONTINUE L ,, K-I M = K+I IF (L.LT.I) L- i IF (M.GT.LIMIT) M " LIMIT IF (ISCANA(K).EQ.O) GO TO 220 IF (ISCANC(K).EQ.O) GO TO 220 IF (ISCANB(L).EQ.O) GO TO 220 IF (ISCANB(M).EQ.O) GO TO 220 GO TO 230

220 CALL NUMB (K,IX,ISCANB(K)) 230 CONTINUE

IF (NUM.GT.5500) WRITE (14,240) NUM 240 FORMAT (' ','ERROR - MUM IS = ',IlO)

CALL ENDS IF (ICOUNT.GT.450)WRITE (14,250) ICOUNT

250 FORMAT (' ','ERROR - ICOUNT IS s ',IlO) C C***** C RENAME SCANS - GO ON TO NEXT SCAN.

C***** C

260 CONTINUE DO 270 J = 1,LIMIT

ISCANA(J) " ISCANB(J) 270 CONTINUE 280 DO 290 J = 1,LIMIT

ISCANB(J) " ISCANC(J) 290 CONTINUE

LREC = LREC2 GO TO 60

300 CONTINUE WRITE (14,310) IX,KOUNT,ICOUNT,IDUST

310 FORMAT ( ' ' ' IX = ' , I 5 , / , ' ','KOUNT = ' , I 5 , / , ' ' , ' ICOUNT = ' , I 5 , / , * ' ','IDUST" ',I5,/) CALL ENDPLT STOP END SUBROUTINE ADDING (MIN,HAX,LL)

C

C***** C DETERMINE THE SIZE AND X-Y COORDINATES OF PARTICLES. C***** C

COMMON /LOOK/ ISCANB(800), ISCANA(800),LIMIT, IX, ICOUNT COMMON /SAVE / IS POT( 500 ), IXC ( 500 ), IYC ( 500 ), KOUNT, IDUST COMMON /STORE/ ISIZE(5OO),IXX(5OO),IYY(500) COMMON /PERPH/ MUM, IXCORD(6000) ,IYCORD(6000) ,NUMBER(6000) ISIZE(LL) ,. 0 IXX(LL) - 0 IYY(LL) = 0 DO 20 L " HIM,MAX

ISCANB(L) = LL IF (L.EQ.I.OR.L.EQ.LIMIT) GO TO I0 ISIZE(LL) = ISIZE(LL)+I IXX(LL) - IXX(LL)+L IYY(LL) - IYY(LL)+IX GO TO 20

I0 ISIZE(LL) = -I00000 20 CONTINUE

C C****~

45

Page 10: IMAGE: a FORTRAN V program for image analysis of particles

46 J. ST~U~'~ and S. SI~UG~N

C ACCUMULATE THE PARTICLE SIZE AND X,Y CORRDINATES OF PIXELS

C WITHIN THE PARTICLE. C***** C

ISPOT(LL) = ISPOT(LL)+ISIZE(LL) IXC(LL) = IXC(LL)+IXX(LL) IYC(LL) = [YC(LL)+IYY(LL) RETURN END SUBROUTINE BESTFIT (NO,IAREA,XX,YY,KOUNT,BLONG,BSHORT,BTHETA)

C C***** C CALCULATE THE LONG AND SHORT AXES AND THE INCLINATION ANGLE OF C THE LONG AXIS OF A PARTICLE. C GIVEN THE PERIMETER AND CENTRIOD CALCULATE THE SECOND CENTRAL C MOMENT, THE ErGEN VALUES OF THE SECOND CENTRAL MOMENT AND C THE EIGEN VECTOR WITH THE MAXIMUM EIGEN VALUE OF THE SECOND C CENTRAL MOMENT. C***** C

COMMON /SAME/ XCORD(3000),YCORD(3000) COMMON /CONST/ PI,RAD ASUM = 0 . 0 BSUM = 0.0 OSUM = 0.0 DO I0 I I' I,NO

ASUM = A S U M + ( ( X X - X C O R D ( I ) ) * * 2 )

BSUM ,' BSUM+((YY-YCORD([))**2) OSUM *' OSUM+(XCORD( I ) - X X ) * ( Y C O R D ( I ) - - Y Y )

I0 CONTINUE ASUM = ASUM/NO BSUM = BSUM/NO OSUM = OSUM/NO

C

C***** C CALCULATE THE EIGEN VALUES OF SECOND CENTRAL MOMENT.

C***** C

DUMM = SQRT((ASUM-BSUM)**2+4*(OSUM)**2) EIGENI., (ASUM+BSUM+DUMM)/2 EIGEN2 = (ASUM+BSUM-DUMM)/2 AREA " FLOAT(IAREA) CONST = AREA/P[ IF (EICEN|.NE.EIGEN2) CO TO 30 WRITE (14,20) KOUNT

20 FORMAT (' ',I5,'THE PARTICLE IS CIRCULAR') BLONC = SQRT(CONST)*2.0 BSHORT = BLONG BTHETA - 0 . 0 GO TO 70

30 IF (EIGEN2.NE.0.O) GO TO 50 WRITE (14,40) NO,KOUNT,AREA,XX,YY,ASUM,BSUM,OSUM,DUM~M,CONST,EIGENI

* ,ErGEN2 40 FORMAT (' ',215,10FI0.2)

GO TO 80 50 REICEN '. SQRT(EICENI/EIGEN2)

BLONG = SQRT(CONST*RE IGEN) BS HORT = AREA/(P I*BLONG) BLONG = BLONG*2.0 BSHORT = BSHORT*2.0

Page 11: IMAGE: a FORTRAN V program for image analysis of particles

lmase analysis of particles

C * * * * *

C CALCULATE THE EICEN VECTOR.

C***** C

IF (OSUM. NE.O) GO TO 60 I F (BSUM.GT.ASUM) BTHETA = 9 0 . 0 IF (BSUM.LT.ASUM) BTHETA = 0 . 0 G O T O 70

60 TANTHET = (EIGENI-ASUN)/OSUM BTtiETA = ATAN(TANTHET)*RAD

70 CALL ELLIPSE ( B L O N G , B S H O R T , B T H E T A , X X , Y Y , 2 1 . 5 ) 8 0 RETURN

END SUBROUTINE DRAW ( N N , O V E R )

C C***** C SORT ALL THE PERIMETER PIXELS OF A PARTICLE INTO A CONTIGUOUS C ARRAY AND PLOT THEM. C***** C

COMMON /SAME/ XCORD(3000) ,YCORD(3000) NO= NN STEP = 0.2/25.4

I0 Xl = XCORD(I) YI = YCORD(1) XLO = Xl-l.O XHI - Xl+l.0 YLO = YI-I.O

YHI = YI+I.O X I I " XI*STEP YII = YI*STEP Xll " 6.3-Xli+2.35 Yll = YI I+OVER CALL PLOT (Yll,Xll,3) NO = NO-I IF (NO.EQ.O) GO TO 140 DO 20 I = I,NO

XCORD(I) = XCORD(I+I) YCORD(1) = YCORD(I+I)

20 CONTINUE 30 DO 40 J = I,NO

IF (XCORD(J).NE.XLO.OR.YCORD(J).NE.(YLO+I)) GO TO 40 JJ =J GO TO 120

40 CONTINUE DO 50 J = I,NO

IF (XCORD(J).NE.(XLO+I).OR.YCORD(J).NE.YHI) GO TO 50 JJ =J GO TO 120

50 CONTINUE DO 60 J = I,NO

IF (XCORD(j).NE.XHI.OR.YCORD(J).NE.(YLO+I)) GO TO 60 jJ =J GO TO 120

50 CONTINUE DO 70 J = I,NO

IF (XCORD(J).NE. (XLO+I).OR.YCORD(J).NE.YLO) GO TO 70 JJ =j GO TO 120

70 CONTINUE DO 80 J = I ,NO

47

C~gO 1)zI-D

Page 12: IMAGE: a FORTRAN V program for image analysis of particles

48 J. S'r~.r~-~ and S. S ~ u L , q

IF (XCORD(J).NE.XLO.OR.YCORD(J).NE.YHI) GO TO 80 Jj,,J GO TO 120

80 CONTINUE DO 9 0 J " I,NO

IF (XCORD(J).NE.XHI.OR.YCORD(J).NE.YHI) GO TO 90 jj -J GO TO 120

90 CONTINUE DO 100 J = 1,NO

IF (XCORD(J).NE.XHI.OR.YCOKD(J).NE.YLO) GO TO 100 Jj = J GO TO 120

100 CONTINUE DO 110 J - I,NO

IF (XCORD(J).NE.XLO.OR.YCORD(j).NE.YLO) GO TO 110 JJ - J GO TO 120

110 CONTINUE GO TO 150

120 X - 6.3-(XCORD(JJ)*STEP)÷2.35 y s (YCORD(JJ)*STEP)+OVER CALL PLOT (Y,X,2) XLO - XCORD(JJ)-I.O XHI - XCORD(JJ)+I.O YLO - YCORD(JJ)-I.0 YHI - YCORD(JJ)+I.0 NO " NO-I IF (NO.EQ.0) GO TO 160 DO 130 I • JJ ,NO

XCORD(I) " XCORD(I+I) YCORD(I) = YCORD(I+I)

130 CONTINUE IF (XI.EQ.XLO.AND.YI.EQ.YLO.OR.XI.EQ.XLO.AND.YI.EQ.(YLO+I)) GO TO

* 140 GO TO 30

140 CALL PLOT (YII ,XII ,2) 150 IF (NO.NE.O) GO TO lO 160 CALL PLOT (Yll,Xll,3)

RETURN END SUBROUTINE ELLIPSE (ELONG,ESHORT,ETHETA,XCC,YCC,OVER)

C C***** C PLOT THE ELLIPSES. C*****

C COMMON /CONSTI PI,RAD DI ME NS ION XNEW( 3000),YNEW(3000), ROTX (3000), ROTY (3000) ZLONG - ELONG/2.0 ZSHORT - ESHORT/2.0 ZTHETA - ETHETA-90.0 IF (ZTHETA.LT.O.O) ZTHETA - ZTHETA+ISO.O ZTHETA - ZTHETA/RAD STEP - 0.2/.25.4 Y - (YCC*STEP)+OVER X - 6.3-(XCC*STEP)+2.35

C C***** C CALCULATE THE PERIMETER OF THE ELLIPSE FOR INCREMENTS X, C USING THE QUADIL%DIC EQUATION OF THE STANDARD FOILM C FOR THE EQUATION OF THE ELLIPSE.

Page 13: IMAGE: a FORTRAN V program for image analysis of particles

Image analysis of particles

C**~r**

C THE X, Y QUADRANT.

C***** C

INDEX = 0 DO 10 I = 0,ZLONG

INDEX = INDEX+I XNEW(INDEX) = I QUAD = I. 0- ( XNEW( INDEX )**2/ZLONG** 2 ) QUAD = SQRT(QUAD) YNEW(INDEX) = QUAD*ZSHORT

I0 CONTINUE INDEX = INDEX+I

C

C***** C ~tqEW AND YNEW ARE THE ARRAYS WHICH STORE THE PERIMETER PIXELS C IN SEQUENTIAL ORDER. C***** C

XNEW(INDEX) = ZLONG YNEW(INDEX) = 0 . 0

c C***** C LOCATE THE OTHER THREE QUADRANTS IN THE ORDER THE PLOTTER C WILL USE ( 0 , B TO A,O TO 0 , - B TO - A , 0 TO 0 , B ) . C***** C THE X~ -Y QUADRANT. C***** C

NDEX = INDEX+INDEX-I N = INDEX- 1 DO 20 [ = (INDEX+I),NDEX

XNEW(1) = XNEW(N)

YNEW(1) - -YNEW(N) N= N-I

20 CONTINUE

C C***** C -X, -Y QUADRANT. C"**** C

KDEX = NDEX+(NDEX-INDEX)

K = NDEX-I DO 30 I = (NDEX+I),KDEX

XNEW(I) - -XNEW(K) YNEW(1) = YNEW(K) K = K - I

30 CONTINUE. C C***** C THE -X,Y QUADRANT. C***** C

MDEX - KDEX+(KDEX-NDEX) M = KDEX-|

DO 40 I = (KDEX+I),MDEX X~EW(I) = XNEW(M) YNEW(I) = -YSEW(H) M=M-I

40 CONTINUE

49

Page 14: IMAGE: a FORTRAN V program for image analysis of particles

50

Ce****

C ROTATE XNEW AND YNEW. C***** C

J. STA~r,t'Y and S. S|M|GIAN

ESIN = SIN(ZTHETA) ECOS = COS(ZTHETA) DO 50 I = I,MDEX

ROTX(1) = XNEW(I)*ECOS-YNEW(1)*ESIN ROTY(1) = XNEW(1)*ESIN+YNEN(1)*ECOS

C***** C TRANSLATE XNE@ AND YNEW. C***** C

ROTX(I) = (ROTX (I)*STEP)+Y ROTY(I) = (ROTY(I)*STEP)+X

50 CONTINUE C C***** C PLOT THE ELLIPSE. C***** C

CALL PLOT (ROTX(1),ROTY(1),3) DO 60 I = I,MDEX

CALL PLOT ( R O T X ( I ) , R O T Y ( I ) , 2 ) 60 CONTINUE

CALL PLOT (ROTX (MDEX), ROTY (MDEX), 3 ) RETURN END SUBROUTINE ENDS

C C***** C CHECK TO SEE IF A PARTICLE HAS TERMINATED.

C***** C

COMMON /LOOK/ ISCANB(800) IISCANA(800) ILIMIT, IX, ICOUNT IVAL = - l DO 20 I = I jLIMIT

IF (ISCANA(I).EQ.O) GO TO 20 IF (ISCANA(I) .EQ.IVAL) GO TO 20 IVAL = ISCANA(I) DO lO J = I ,LIMIT

IF (ISCANB(J).NE.IVAL) GO TO 10 COTO 20

I0 CONTINUE CALL SHAPE (IVAL)

20 CONTINUE RETURN END

SUBROUTINE FRAME (OVER) C C***** C DRAM THE BORDERS AND SCALE ON EACH PLOT. C***** C

CHARACTER NUMBER(17)*3, NAME(3) DATA NUMBER / '0 ')'I0','20')'30','40','50','60','70','80','90'

! t ! ! ! ! | ! | ! P I00 , II0 , 120 , 130 , 140 , ' 1 5 0 ' , ' 1 6 0 ' I

CALL PLOT (OVER,2.35,3) CALL PLOT ( ( O V E R + 4 . 5 3 ) , 2 . 3 5 , 2 ) CALL PLOT ( ( O V E R + 4 . 5 3 ) , 8 . 6 5 , 2 ) CALL PLOT (OVER,8.65,2)

Page 15: IMAGE: a FORTRAN V program for image analysis of particles

Image analysis of parlicles

CALL PLOT (OVER,2.35,2)

C C***** C PLOT TICK MARKS ALONG THE X - A X I S .

C * * * * * C

DIST = 10.0/25.4 YLO = 2.25 YHI - 2.35 XS = OVER DO I0 I = 1,12

XSTEP = I - I . 0 XSTEP = ( X S T E P * D I S T ) + X S CALL PLOT ( X S T E P s Y L O , 3 ) CALL PLOT ( X S T E P , Y H I . 2 )

10 CONTINUE C C***** C N U M B E R THE X - A X I S . C***** C

Y = YHI-0.32 HT = 0.12 WT = HT*(6.0/7.0) DO 20 I = 10,120,10

INANE = I-I0 XSTEP = (I-I0)/I0.0 XSTEP = (XSTEP*DIST)+XS

ICHAR = 2

IF (INAME.EQ.O) ICHAR - l

IF ( INAME.GE. I O 0 ) ICHAR - 3 CHAR = ICHAR XX = XSTEP-((CHAR*WT) / 2.0) J = INAME/10+I

NAME(I) - NUMBER(J)( I : I )

NAME(2) = NUMBER(J)(2:2) NAME(3) = NUMBER(J)(3:3) CALL SYMBOL (XX,Y,HT,NAME,O.O,ICHAR)

20 CONTINUE C C***** C LABEL THE X-AXIS. C***** C

Y = Y-0.32 HT2 = 0.14 WT2 = HT2"(6.017.0)

X = XS+((4.3/2.0)-(5.0"WT2)) CALL SYMBOL (X,Y,HT2,'X-AXIS (MM)',0.0,11)

C C***** C PLOT TICK MARKS ALONG THE Y-AXIS. C***** C

XLO = X S - 0 . 1 XHl = XS

YS = 2.35 DO 30 I = 1 , 1 7

YSTEP = I - 1 YSTEP = (YSTEP*DIST)+YS CALL PLOT ( X L O , Y S T E P , 3 ) CALL PLOT ( X H I , Y S T E P , 2 )

51

Page 16: IMAGE: a FORTRAN V program for image analysis of particles

52 J. STARKEY and S. S~moum

30 CONTINUE C C * * * * * C NUMBER THE Y - A X I S .

C* '**** C

X = XLO-O. 1 DO 40 I - l O , 1 7 0 , 1 0

INAME = I - l O YSTEP = ( I - l O ) / l O . 0 YSTEP = (YSTEP*DIST)+YS ICHAR - 2 IF (INAME.EQ.O) ICHAR = I IF ( I N A M E . G E . I O 0 ) ICHAR = 3 CHAR = ICHAR YY = YSTEP-((CHAR*WT)/2.0) j - INAME/10+[ NAME(l) = N U M B E R ( J ) ( I : I ) NAME(2) = NUMBER(J)(2:2) NAME (3) = NUMBER(J)(3: 3) CALL SYMBOL (X,YY,HT,NAME,90.O,ICHAR)

40 CONTINUE C C * * * * * C LABEL THE Y - A X I S .

C * * * * * C

X = X-0.32 Y = YS÷((6.3/2.0)-(5.0*WT2)) CALL SYMBOL (X,Y,HT2,'Y-AXIS (MM)',90.0,11) CALL PLOT (XS,YS,3) RETURN END

SUBROUTINE MIDSPOT (MINB ,MAXB ,MIN ,MAXA, LL) C C***** C CHECK EACH PARTICLE TO SEE IF IT IS SPLIT INTO MORE THAN ONE PART. C***** C

COMMON /LOOK/ ISCANB(800) , ISCANA(800) ,LIMIT, IX, ICOUNT COMMON /PERP H/ NUM, IXCORD ( 6000 ) ~ IYCORD (6000), NUMBER ( 6000 ) COMMON / SAVE / IS POT ( 500 ), IXC ( 500 ), IYC (500) , KOU NT, I DUST DIMENSION ISPLIT(20) INDEX = 0 DO I0 I = 1,20

ISPLIT(I) = 0 I0 CONTINUE

DO 30 L = MIN,MAXA IF (ISCANA(L).EQ.0) GO TO 30 IF (ISCANA(L).EQ.LL) GO TO 30 IF (INDEX.EQ.O) GO TO 20 IF (ISPLIT(INDEX).EQ.ISCANA(L)) GO TO 30

20 INDEX = INDEX+I I S P L I T ( I N D E X ) = ISCANA(L)

30 CONTINUE CALL ADDING (MINB,MAXB,LL) IF (INDEX.EQ.0) GO TO 90 DO 50 I = I,ICOUNT

DO 40 K = I,INDEX IF (I.NE.LL) GO TO 40 ISPOT(I) = ISPOT(I)+ISPOT(ISPLIT(K))

Page 17: IMAGE: a FORTRAN V program for image analysis of particles

60 C C*****

lmaFanalymofparf id~

IXC( I ) - I X C ( I ) + I X C ( I S F L I T ( K ) ) I Y C ( I ) - I Y C ( I ) + I Y C ( I S P L I T ( K ) ) I S P O T ( I S F L I T ( K ) ) - 0 I X C ( I S F L I T ( K ) ) - 0 IYC(ISPLIT(K)) - 0

40 CONTINUE 50 CONTINUE

DO 80 K - I,INDEX DO 60 I - MIN,LIMIT

IF (ISCANA(I).NE.ISPLIT(K)) CO TO 60 ISCANA(I) - LL

CONTINUE

C C C***** C

A PARTCLE WAS FOUND TO BE SPLIT, A NUMBER ASSIGNED TO ONE OF THE PARTS IS APPLIED TO THE OTHER PARTS.

DO 70 L = I,NUM IF (NUMBER(L).NE.ISPLIT(K)) CO TO 70 NUMBER(L) = LL

70 CONTINUE 80 CONTINUE 90 RETURN

END FUNCTION NEXT (IF,IBFNUM)

C C * * * * * C EXTRACT THE 8 BIT WORDS WRITTEN BY THE DENSITONETER FROM C T H E 6 0 BIT WORDS USED BY THE CYBER. C * * * * * C

CO~e'lON /BUFF/ IBUFFR(512,2) K = MOD(IF+I4,15)+I L = ((IF-I)/15)'2+I GO TO (I0,20,30,40,50,60,70,80,90,I00,II0,120,130,140,150), K

l0 IAA " SHIFT(IBUFFR(L,IBFNUM),8)

GO TO 160 20 IAA = SHIFT(IBUFFR(L,IBFNUM),I6)

CO TO 160 30 IAA " SHIFT(IBUFFR(L,IBFNUM),24)

CO TO 160 40 IAA " SHIFT(IBUFFR(L,IBFNUM),32)

GO TO 160 50 IAA " SHIFT(IBUFFR(L,IBFNUM),40)

GO TO 160 60 IAA " SHIFT(IBUFFR(L,IBFNUM),48)

GO TO 160 70 IAA " SHIFT(IBUFFR(L,IBFNUM),56)

CO TO 160 80 CONTINUE

IAA - AND(IBUFFR(L,IBFNUM),O"IT") IBB - AND( IBUFFR(L+I, IBFNUM) ,O"74000000000000000000") IAA - SHIFT(IAA,4) IBB - SHIFT(IBB,4) NEXT - IAA+IBB RETURN

90 IAA - SHIFT(IBUFFR(L+I , IBFNUM), I2) CO TO 160

100 IAA = SHIFT(IBUFFR(L+It IBFNUM),20) GO TO 160

l l 0 IAA = SHIFT(IBUFFR(L+I , IBFNUM),28)

53

Page 18: IMAGE: a FORTRAN V program for image analysis of particles

54

120

130

140

150 160

J. ST,,~r..~ and S. Szmoum

GO TO 160 IAA = SHIFT( IBUFFR(L+I ,IBFNUM),36) GO TO 160 IAA = SHIFT(IBUFFR(L+I,IBFNUM),44)

GO TO 160 IAA - SHIFT(IBUFFR(L+I,IBFNUM),52) GO TO 160 IAA = SHIFT(IBUFFR(L+I,IBFNUM),60) NEXT ,= AND(IAA,O"377") RETURN END SUBROUTINE NUMB ( I , J , K )

C C***** C STORE THE NUMBER OF PERIMETER PIXELS AND THEIR X-Y COORDINATES C FOR ALL THE PARTICLES WITHOUT A NEGATIVE NUMBER IN *ISPOT*. C***** C

COMMON /PERPH/ NUM, IXCORD(6000 ), IYCORD( 6000 ), NUMBER ( 6000 ) NUM - NUM+I IXCORD(NUM) " I IYCORD(NUM) - J NUMBER(NUM) - K RETURN END SUBROUTINE RECTANG (XLOW, YLOW, XH I, YH I , NO, XCC, YCC, KOUNT, ATHETA,

* ALONG,OVER, RSHORT) C C***** C CALCULATE THE MAXIMUM DIMENSION OF A PARTICLE C PERPENDICULAR TO THE LONG AXIS, C***** C

COMMON /SAME/ XCORD(3OOO),YCORD(3000) COMMON /CONST/ PI~,RAD STEP = 0.2125.4 DUMI - 0.0 DUM2 = 0.0 IFLAG = 0 IF (ATHETA.EQ.O.0) GO TO 260 IF (ATHETA.EQ.90.0) GO TO 280 IF (ATHETA.GT.90.O) GO TO 130

C C***** C CALCULATE THE DISTANCE OF THE SHORT AXIS FOR A SMALL THETA. C***** C

RTHETA " ATHETA/RAD DO 120 I = I,NO

XX = XLOW-XCORD(I) YY = YLOW-YCORD(I) IF (XX.EQ.O.O.OR.YY.EQ.0.O) GO TO I0 ANG = ATAN(YY/XX)

I0 IF (XX) 50 , 20 , 60 20 IF (YY) 40 , 120 , 30 30 ANG = 9O.O/RAD

CO TO I00 40 ANG = -go.O/RAD

CO TO 100 50 IF (YY) 90 , 70 , 90 60 IF (YY) I00 , 80 , IO0 70 ANG " 0.0

Page 19: IMAGE: a FORTRAN V program for image analysis of particles

Image analysis of particles

GO TO 90

80 ANG = 0.0 GO TO 100

90 ANG " RTHETA-ANG

GO TO 110

i00 ANG " PI+RTHETA-ANG

II0 ZZ = SQRT(XX**2+YY**2)

DIST = SIN(ANG)*ZZ IF (DIST.GT.DUMI) DUMI ~ DIST

IF (DIST.LT.DUM2) DUM2 " DIST

120 CONTINUE

GO TO 300

C

C * * * * * C CALCULATE THE DISTANCE OF THE SHORT AXIS FOR A LARGE THETA. C * * * * * C

130 RTHETA ,, (180.0-ATHETA)/RAD

IFLAG " i

DO 250 I - I ,NO XX - XLOW-XCORD(1)

YY - YLOW-YCORD(1)

IF (XX.EQ.O.O.OR.YY.EQ.0.0) GO TO 140 ANG - ATAN(YY/XX)

140 IF (XX) 180 , 150 , 190

150 IF (YY) 170 , 250 , 160

160 ANG = 9 0 . 0 / R A D GO TO 230

170 ANG = -90.01RAD

GO TO 230

|80 IF (YY) 220 , 200 , 220

190 IF (YY) 230 , 210 , 230

200 ANG = 0.0 GO TO 220

210 ANG - 0.O

GO TO 230

220 ANG - PI+RTHETA+ANG

GO TO 240

230 ANG ", RTHETA+ANG

240 ZZ " SQRT(XX**2.0+YY**2,0)

DIST " SIN(ANG)*ZZ IF (DIST.GT.DUMI) DUM| = DIST

IF (DIST.LT.DUM2) DUM2 = DIST

250 CONTINUE GO TO 300

260 DO 270 I = I,NO

DIST = YLOW-YCORD(1)

IF ( D I S T . G T . D U M 1 ) DUMI = DIST IF ( D I S T . L T . D U M 2 ) DUM2 = DIST

270 CONTINUE GO TO 300

280 DO 290 I = I,NO DIST = XLOW-XCORD(I)

IF (DIST.GT.DUMI) DUMI " DIST

IF (DIST.LT.DUM2) DUM2 = DIST

290 CONTINUE

300 DUM2 " -DUM2

RSHORT " DUMI+DUM2

C C * * * * * C PLOT THE LONG AXIS (ALONG),

55

Page 20: IMAGE: a FORTRAN V program for image analysis of particles

J. STAJRICI~ and S. S|M|GIAN

C XREC = 6.3-(XLOW*STEP)+2.35

YREC = (YLOW*STEP)+OVER CALL PLOT (YREC,XREC,3) CALL PLOT (YREC,XREC,2) XREC = 6.3-(XHI*STEP)+2.35 YREC = (YHI*STEP)+OVER CALL PLOT (YREC,XREC,2)

C C***** C PLOT THE SHORT AXIS (RSHORT). C***** C

IF ( IFLAG.EQ.O) CO TO 310 XS1 = XCC-{DUMI*SIN(RTHETA)) YS l = YCC-< DUMI*COS(RTHETA) ) XS2 = XCC÷{DUM2*SIN(RTHETA)) YS2 = YCC+tDUM2*COS(RTHETA)) CO TO 320

310 XS I = XCC+(DUMI*SIN(RTHETA)) YS I - YCC-(DUHI*COS(RTHETA)) XS2 - XCC-(DUM2*SIN(RTHETA)) YS2 - YCC+(DUM2*COS(RTHETA))

320 XS[ = 6.3-(XSI*STEP)+2.35 YSI " (YSI*STEP)+OVER

XS2 = 6.3-(XS2*STEP)+2.35 YS2 - (YS2*STEP)+OVER CALL PLOT (YSI,XSI,3) CALL PLOT (YSI,XSI,2) CALL PLOT (YS2,XS2,2) CALL PLOT (YS2,XS2,3) RETURN END SUBROUTINE SHAPE (KKK)

C C***** C CALCULATE THE LENGTHS OF THE LONG AND SHORT AXES AND THE C ORIENTATION OF THE LONG AXIS OF THE FINISHED PARTICLES. C WRITE ALL THE PARAMETERS OF THE FINISHED SPOTS.

C***** C

COMMON /PERPH/ NUM, IXCORD(6000), IYCORD(6000) ,NUMBER(6000) COMMON /SAVE/ I S P O T ( 5 0 0 ) , I X C ( 5 0 0 ) , I Y C ( 5 0 0 ) , K O U N T , [ D U S T COMMON /SAME/ XCORD(3000) ,YCORD(3000) COMMON /CONST/ PI,RAD NO = 0 RSHORT = 0 . 0 BLONG = 0.0 BSHORT = 0 . 0 BTHETA = 0 . 0 INN = NUH-I

C C***** C KKK IS THE REFERENCE NUMBER OF THE TERMINATED PARTICLE. C***** C

IF (ISPOT(KKK).LE.50) GO TO 230 DO I0 J = I,NUM

IF (NUMBER(J).NE.KKK) CO TO 10 NO = NO+l XCORD(NO) - IXCORD(J)

Page 21: IMAGE: a FORTRAN V program for image analysis of particles

Image analysis of particles

YCORD(NO) = IYCORD(J ) 10 CONTINUE

NUM = NUM-NO IF (NUM.EQ.O) GO TO 50 DO 40 J = I,NUM

20 IF (NUMBER(J).NE.KKK) GO TO 40

DO 30 I = J,INN IXCORD(I) = IKCORD( I+I ) IYCORD( I ) = IYCORD( I+l ) NUMBER(1) = WOMBER(I+l)

30 CONTINUE

GO TO 20 40 CONTINUE 50 KOUNT = KOUNT+I

C C * * * * * C DETERMINE THE LENGTH OF THE LONG AXIS OF THE PARTICLE.

C***** C

DIST2 " 0.0 NOO = NO-I DO 70 L = IDNOO

IND = L+I DO 60 K m IND,NO

D I S T I m ( (XCORD( K ) -XCORD(L ) ) * * 2 ) + ( (YCORD(K)-YCORD( L ) ) * * 2 ) I F ( D I S T I . L E . D I S T 2 ) CO TO 60 DIST2 = DISTI PXI = XCORD(K) PX2 = XCORD(L) PYI = YCORD(K) PY2 = YCORD(L)

60 CONTINUE 70 CONTINUE

ALONG = SQRT(DIST2) C C***** C CALCULATE THE ANGLE OF INCLINATION Og THE LONG AXIS WITH C RESPECT TO THE X - A X I S . C***** C

IF (PYI.EQ.PY2) CO TO 110

IF ( P Y I . G T . P Y 2 ) GO TO 80 XLOW m PXI YLOW . PYI XHI - PX2 YHI = PY2 COTO 90

80 XLOW = PX2 YLOW = PY2

XHI = PXI YHI = PYI

90 I F (XLOW.EQ.XHI ) GO TO 100 PPP = (YHI-YLOW)/(XHI-XLOW) ATHETA = ATAN(PPP)*RAD I F ( A T H E T A . L T . 0 . 0 ) ATHETA - ATHETA+180.O GO TO 130

I00 ATHETA = 90.0 CO TO 130

110 I F ( P X I . G T . P X 2 ) GO TO 120 XLOW = PX1 YLOW = PY1 XH[ = PX2

57

Page 22: IMAGE: a FORTRAN V program for image analysis of particles

58 J. ST~K.Pt and S. S ~ G ~

YHI = PY2 GO TO 130

120 XLOW = PX2 YLOW - PY2 XHI = PXI YHI = PY1 ATHETA = 0.0

C C*'**** C CORRECT THE LENGTH OF THE LONG AXIS FOR ONE HALF A PIXEL ON C EACH END.

C***** C

130 TANGLE = ATHETA/RAD IF (ATHETA.GE.45.0.AND.ATHETA.LE.135.0) GO TO 140 ALONG = ALONG + ( i . 0/ABS (COS ( TANGLE ) ) ) GO TO 150

140 ALONG = ALONG+(I.0/ABS(SIN(TANGLE))) C C***** C FIND THE LENGTH OF THE SHORT AXIS USING THE EQUATION FOR C THE AREA OF AN ELLISPE. C***** C

150 ASHORT - 2*(ISPOT(KKK)/(PI*(ALONG/2) ) ) XX - FLOAT(IXC(KKK)) YY = FLOAT(IYC(KKK)) XX = XX/ISPOT(KKK) YY - YY/ISPOT(KKK)

C C***** C DRAW AREA ELLIPSES. C***** C

XCC " ( P X I ~ P X 2 ) / 2 . 0 YCC = ( P Y I + P Y 2 ) / 2 . 0 CALL ELLIPSE (ALONG,ASHORT,ATHETA,XCC,YCC, 12.0)

C C***** C CALL SUBROUTINES RECTANG AND BESTFIT TO CALCULATE OTHER C REGULAR GEOMETRIC SHAPES.

C***** C

CALL BESTFIT (NO, ISPOT(KKK),XX,YY,KOUNT,BLONG,BSHORT,BTHETA) CALL RECTANG (XLOW, YLOW, XHI ,YHI, NO,XCC ,YCC, KOUNT, ATHETA,ALONG, 31.0

* ,RSHORT) C C***** C DRAW GRAIN. C***** C

CALL DRAW (NO,2.35)

C C***** C WRITE ALL THE INFORMATION FOR EACH PARTICLE TO TAPE 14. C CONVERT APPROPRIATE PAR.JaMETERS INTO MILLIMETERS AND C WRITE IT TO TAPES II AND 12 TO BE *SAVED*. C***** C

IF (KOUNT.NE.I) GO TO 190 WRITE ( 1 4 , 1 6 0 ) WRITE (II,170)

Page 23: IMAGE: a FORTRAN V program for image analysis of particles

lma~ analysis of pa r~ l~

WRITE (12,180) 160 FORMAT ( ' ' , 'ALL THESE PARAMETERS ARE IN PIXELS ! ! ! ' , / / , ' ' ,

* 'KOUNT',3X,'SIZE',SX,'XX',6X,'YY',SX,'ALONG',2X,'ASHORT',2X,

* 'ATHETA',2Xt'PERIM',2X,'RSHORT',2X,'BLONG',2X,'BSHORT',2X,

* 'BTHETA',//) 170 FORMAT ( ' ' , ' A L L THESE PARAMETERS ARE IN MILLIMETERS ! ! 1 ' , / / , ' ' ,

* 'NUMBER',2X,'SIZE',SX,'XX',6X,'YY',SX,'ALONG',2X,'ASHORT',4X,

* 'ATHETA',4X,'ASPECT',2X,'PERIM',//) 180 FORMAT (' ','ALL THESE PARAMETERS ARE IN MILLIMETERS !!!',//,' ',

* ' N U M B E R ' , 2 X , ' R S H O R T ' , 2 X , ' R S P E C T ' , 2 X , ' B L O N G ' , 2 X , ' B S H O R T ' , 5 X , * ' B T H E T A ' , 3 X , ' B S P E C T ' , / / )

190 WRITE ( 1 4 , 2 0 0 ) KOUNT,ISPOT(KKK),XX,YY,ALONG,ASHORT,ATHETA,NO, * RSHORT,BLONG,BSHORT,BTHETA

200 FORMAT ( ' ' , I 4 , 3 X , I 4 , 2 X , 5 ( F 6 . 2 , 2 X ) , I 6 , 2 X , 4 ( F 6 . 2 , 2 X ) ) SPOT = ISPOT(KKK)*O.04 XX = 160.0-XX*0.2

YY = YY*0.2

ALONG = ALONG*O.2

ASHORT = ASHORT*0.2 ASPECT = ALONG/ASHORT

PERIM = FLOAT(NO)*0.2 RSHORT = RSHORT*0.2

RSPECT - ALONG/RSHORT

BLONG = BLONG*0.2

BSHORT = BSHORT*0.2

BSPECT = BLONG/BSHORT WRITE ( I I , 2 1 0 ) KOUNT,SPOT,YY,XX,ALONG,ASHORT,ATHETA,ASPECT,PERIM

210 FORMAT ( ' ' , I 4 , 3 X , 8 ( F 6 . 2 , 2 X ) ) WRITE ( 1 2 , 2 2 0 ) KOUNT,RSHORT,RSPECT,BLONG,BSHORT,BTHETA,BSPECT

220 FORMAT ( ' ' , I 4 , 3 X , 4 ( F 6 . 2 , 2 X ) , F I 0 . 5 , F 6 . 2 ) 230 IF (ISPOT(KKK).LE.SO.AND.ISPOT(KKK).GT.0) IDUST = IDUST+I

ISPOT(KKK) = 0 IXC(KZK) = 0

IYC(KKK) - 0 RETURN END

59