The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

Name

Image::Find::Paths - Find paths in an image.

Synopsis

Use new to create and analyze a new image, then print to visualize the paths detected, or path to get the coordinates of points along each path in sequential order with an estimate of the thickness of the path at each point.

Description

Find paths in an image.

The following sections describe the methods in each functional area of this module. For an alphabetic listing of all methods by name see Index.

Methods

Find paths in an image

new($)

Find paths in an image represented as a string.

     Parameter  Description                                                 
  1  $string    String of blanks; non blanks; new lines defining the image  

Example:

  my $d = new(<<END);
       11                                                                      111
        11                                                                 1   111
         1111                            111                                   111
            1                           111111             1                   111
          111                            1111             111                  111
         11  1111111                      1                1
        11    11111                       1                                      1
        1      111                        1                 1                    1
       1111111111                         1             111111                   1
                111                       1                               1      1
  END
  
  is_deeply [$d->count, $d->x, $d->y, $d->numberOfPaths], [96, 80, 10, 6];
  
  ok nws($d->print) eq nws(<<END);
     0         1         2         3         4         5         6         7         8
     01234567890123456789012345678901234567890123456789012345678901234567890123456789
  
   0      E1                                                                      E
   1       11                                                                     23
   2        1111                                                                   3
   3           1                             322E             S                    3
   4         111                             2               E1                    2S
   5        11     221S                      1
   6       11     23                         1                                      E
   7       1      3                          1                 S                    1
   8       11111112                          1             E1111                    1
   9                                         S                                      S
  
  Image: X = 80, Y = 10, Paths = 6
  END
  
  is_deeply $d->path(5),
  
  [[79,4, 1], [78,4, 2], [78,3, 3], [78,2, 3], [78,1, 3], [77,1, 2], [77,0, 1]];
  

This is a static method and so should be invoked as:

  Image::Find::Paths::new

numberOfPaths($)

Number of paths in the image.

     Parameter  Description  
  1  $i         Image        

Example:

  is_deeply [$d->count, $d->x, $d->y, $d->numberOfPaths], [96, 80, 10, 6];
  

path($$)

Returns an array of arrays [x, y, t] where x, y are the coordinates of each point sequentially along the specified path and t is the estimated thickness of the path at that point. Paths are numbered from 1 to numberOfPaths.

     Parameter   Description  
  1  $i          Image        
  2  $partition  Partition    

Example:

  is_deeply $d->path(5),
  
  [[79,4, 1], [78,4, 2], [78,3, 3], [78,2, 3], [78,1, 3], [77,1, 2], [77,0, 1]];
  

print($)

Print the image: use S, E to show the start and end of each path, otherwise use the estimated thickness of the path at each point to mark the track of each path within each connected partition of the image.

     Parameter  Description  
  1  $i         Image        

Example:

  ok nws($d->print) eq nws(<<END);
     0         1         2         3         4         5         6         7         8
     01234567890123456789012345678901234567890123456789012345678901234567890123456789
  
   0      E1                                                                      E
   1       11                                                                     23
   2        1111                                                                   3
   3           1                             322E             S                    3
   4         111                             2               E1                    2S
   5        11     221S                      1
   6       11     23                         1                                      E
   7       1      3                          1                 S                    1
   8       11111112                          1             E1111                    1
   9                                         S                                      S
  
  Image: X = 80, Y = 10, Paths = 6
  END
  

Attributes

Attributes of an image

count :lvalue

Number of points in the image.

image :lvalue

Image data points.

partitions :lvalue

Number of partitions in the image.

partitionEnd :lvalue

End points for each path.

partitionStart :lvalue

Start points for each path.

partitionPath :lvalue

Path for each partition.

x :lvalue

Image dimension in x.

y :lvalue

Image dimension in y.

Private Methods

clone($)

Clone an image.

     Parameter  Description  
  1  $i         Image        

Example:

  is_deeply $d, $d->clone;
  

clonePartition($$)

Clone a partition of an image.

     Parameter   Description  
  1  $i          Image        
  2  $partition  Partition    

countPixels($)

Count the pixels in an image.

     Parameter  Description  
  1  $i         Image        

height($)

Clone an image adding height to each pixel.

     Parameter  Description  
  1  $i         Image        

partition($)

Partition the images into disjoint sets of connected points.

     Parameter  Description  
  1  $i         Image        

mapPartition($$$)

Locate the pixels in the image that are connected to a pixel with a specified value.

     Parameter  Description                               
  1  $i         Image                                     
  2  $x         X coordinate of first point in partition  
  3  $y         Y coordinate of first point in partition  

start($$)

Find the starting point for a path in a partition.

     Parameter   Description  
  1  $i          Image        
  2  $partition  Partition    

end($$)

Find the other end of a path in a partition.

     Parameter   Description  
  1  $i          Image        
  2  $partition  Partition    

traverseToOtherEnd($$$$)

Traverse to the other end of a partition.

     Parameter   Description         
  1  $I          Image               
  2  $partition  Partition           
  3  $X          Start x coordinate  
  4  $Y          Start y coordinate  

searchArea($$$$)

Return the pixels to search from around a given pixel.

     Parameter   Description                        
  1  $i          Image                              
  2  $partition  Partition                          
  3  $x          X coordinate of center of search   
  4  $y          Y coordinate of center of search.  

checkAtLevelOne($$$)

Confirm that the specified pixel is at level one.

     Parameter   Description  
  1  $i          Image        
  2  $partition  Partition    
  3  $pixel      Pixel        

searchAreaHighest($$$$$$)

Return the highest pixels to search from around a given pixel.

     Parameter   Description                        
  1  $i          Image                              
  2  $partition  Partition                          
  3  $seen       Pixels already visited             
  4  $depth      Depth of search                    
  5  $x          X coordinate of center of search   
  6  $y          Y coordinate of center of search.  

shortestPathBetweenEndPoints($$$)

Find the shortest path between the start and the end points of a partition.

     Parameter   Description         
  1  $I          Image               
  2  $i          Image height clone  
  3  $partition  Partition           

widthOfPath($$)

Find the (estimated) width of the path at each point.

     Parameter   Description  
  1  $I          Image        
  2  $partition  Partition    

widthOfPaths($)

Find the (estimated) width of each path at each point.

     Parameter  Description  
  1  $i         Image        

printHeader($)

Print a header for the image so we can locate pixels by their coordinates.

     Parameter  Description  
  1  $i         Image        

Index

1 checkAtLevelOne

2 clone

3 clonePartition

4 count

5 countPixels

6 end

7 height

8 image

9 mapPartition

10 new

11 numberOfPaths

12 partition

13 partitionEnd

14 partitionPath

15 partitions

16 partitionStart

17 path

18 print

19 printHeader

20 searchArea

21 searchAreaHighest

22 shortestPathBetweenEndPoints

23 start

24 traverseToOtherEnd

25 widthOfPath

26 widthOfPaths

27 x

28 y

Installation

This module is written in 100% Pure Perl and, thus, it is easy to read, use, modify and install.

Standard Module::Build process for building and installing modules:

  perl Build.PL
  ./Build
  ./Build test
  ./Build install

Author

philiprbrenan@gmail.com

http://www.appaapps.com

Copyright

Copyright (c) 2016-2018 Philip R Brenan.

This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.