7.3.11. Connected Component Analysis
(lsh/libimage/cca.lsh)


elementary routines for performing a connected component (CC) analysis on images. The basic procedure consists in:

There are a few other methods for performing various cleanup on the runs and on the CCs. There is also a method for reconstructing the image from the cleaned CCs.

Another trick: There is a matrix named ubcut in the CCAnalyzer object. Every pixel set in this matrix will force the RUN and CC code to ignore connexity on certain pixels. For instance, you can force arbitrary cuts by setting the pixels of a 4-connex line in this matrix. This has to be done before the call to run-analysis .

-- Leon Bottou 9/96



7.3.11.0. CCAnalyzer
(lsh/libimage/cca.lsh)


Class for connected component analysis.

7.3.11.1. (new CCAnalyzer grayimage)
[CLASS] (lsh/libimage/cca.lsh)


Class CCanalyzer holds all the information necessary for the connected component analysis of an image grayimage .

7.3.11.2. (==> ccanalizer run-analysis threshold)
[MSG] (lsh/libimage/cca.lsh)


Computes a run length representation of the binary image obtained by thresholdind the gray image ubmatrix2d at threshold thres . The run information is stored into slot runs of the CCAnalizer object.

Each line of matrix runs is a 4-vector containing the following information:

This function breaks runs on each non zero pixel of the image located in slot ubcut of ccanalyzer . The default value is all zeroes.

This function returns t on success.



7.3.11.3. (==> ccanalyzer cc-analysis)
[MSG] (lsh/libimage/cca.lsh)


Perform the connected component analysis of the image represented by the runs matrix contained in the ccanalyzer object. This algorithm usually considers 8-connexity. This is altered when the cut image ubcuts contains a non zero value indicating a forced cut.

The results are stored in the cc descriptor matrix ccdesc of the object. Each line of this matrix represent a connected component (CC).

This function returns t on success. You may postprocess the returned CC with cc-measure-gray , cc-remove-specs , and other functions in this file.



7.3.11.4. (==> ccanalyzer remove-long-runs maxlen)
[MSG] (lsh/libimage/cca.lsh)


This function removes the runs whose length is longer than maxlen . Long runs are sometimes good indicator for underlines. Note that nothing is changed in the image. You must use reconstruct-from-runs or reconstruct-from-cc for that.

7.3.11.5. (==> ccanalyzer reconstruct-from-runs)
[MSG] (lsh/libimage/cca.lsh)


Reconstruct matrix ubimg from the run representation. This code saves the gray level information already present in ubimg . It just sets all pixels not included in a run to zero.

7.3.11.6. (==> ccanalyzer cc-measure-gray)
[MSG] (lsh/libimage/cca.lsh)


Compute the average gray level of each CC and store it at index (CC-WPIX) of the CC descriptor matrix ccdesc .

7.3.11.7. (==> ccanalyzer remove-small-cc minpix mingray minweight)
[MSG] (lsh/libimage/cca.lsh)


Remove small connected components

Note that nothing is changed in the image or the run matrix. You must use reconstruct-from-cc for that.



7.3.11.8. (==> ccanalyzer reconstruct-from-cc)
[MSG] (lsh/libimage/cca.lsh)


Reconstruct matrix ubimg from the connected components in ccdesc . This code saves the gray level information already present in ubimg . It just sets all pixels not included in a run to zero.

7.3.11.9. (==> ccanalyzer overlay-cc ccid ccimg originx originy)
[MSG] (lsh/libimage/cca.lsh)


Overlays connected component ccid into ubyte matrix ccimg . Matrix ccimg is assumed to have its top left corner at position originx originy in the intial image. Connected components that do not fit matrix ccimg are silently clipped. Returns t when something was drawn.

7.3.11.10. (==> ccanalyzer draw-cc x y)
[MSG] (lsh/libimage/cca.lsh)


Draws image at location x y by painting each connected component with a random color. Unfortunately, random colors are sometimes too close. [INTERPRETED ONLY]

7.3.11.11. (==> ccanalyzer pick-cc x y)
[MSG] (lsh/libimage/cca.lsh)


returns the index of the connected component that contains the point x , y , or -1 if no component contains the point.

7.3.11.12. (==> ccanalyzer image-height)
[MSG] (lsh/libimage/cca.lsh)


returns height of image on which CCA is performed

7.3.11.13. (==> ccanalyzer image-width)
[MSG] (lsh/libimage/cca.lsh)


returns width of image on which CCA is performed

7.3.11.14. (==> ccanalyzer run-histo histo hosto offset)
[MSG] (lsh/libimage/cca.lsh)


compute histogram of runs. histo is an N by P matrix, and hosto an N vector. this method will accumulate the histogram of run lengths for each scan line between offset and offset +N-1. on output, elements i, j of histo will be incremented by the number of runs on line i- offset that are of length j. element i of hosto will incremented by the number of runs on scanline i- offset that are larger or equal to P.

7.3.11.15. (==> ccanalyzer bbox-histo histo)
[MSG] (lsh/libimage/cca.lsh)


computes 2D histogram of bounding box heights and width and increment 2D matrix histo by it. Element i, j of histo will be incremented by the number of CC whose bounding box is of height i and of width j.

7.3.11.16. (==> ccanalyzer ccbottoms thres)
[MSG] (lsh/libimage/cca.lsh)


return a matrix with x and y of horixontal center of bottom of each CC. CCs whose number of black pixels are smaller than thres are ignored.

7.3.11.17. (==> CCAnalyzer get-cc-fltim cc-id cc-fltim cc-com cc-off)
[MSG] (lsh/libimage/cca.lsh)


  ((-int-) cc-id) : index of the cc
  ((-idx2- (-flt-)) cc-fltim) : image in float
  ((-idx1- (-flt-)) cc-com) : center of mass,  in float [X,Y]
  ((-idx1- (-int-)) cc-off) : offset [X,Y]
ADDED: Patrick Haffner, July 97
Given the index of a CC, returns:
1) the corresponding gray level float image, dilated (WITH OFFSET)
2) the center of mass of the bitmap (WITHOUT OFFSET)
3) the offset used to align the float image to the upper right corner.
WARNING: fltim expands all the edges of the bounding box
by 1 pixel, UNLESS this cannot be done because we hit the
global image border.