Name

Image::Find::Loops - Find loops in an image.

Synopsis

See method new.

Description

Find loops 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 loops in an image.

new($)

Find loops 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                       11111111111        11111111111
    1111                      1         1        1         1
   11  11    1111             1   111   1        1         1              1
   11  11    11 11            1   1 1   1        1         1
   11  11    11 11            1   1 1   1        1         1
    1111     11111            1   1 1   1        1         1
     11      1111             1   1 1   1111111111         1                  1
               1111           1   1 1   1111111111         1            1
              11111           1   1 1   1        1         1
      111111111111111111      1   1 1   1        1         1
      11    1111111111        1   111   1        1         1                1
      1      11111111         1         1        1         1
     11111111111              1         1        1         1
              111             11111111111        11111111111

END

ok nws($d->print(1)) eq nws(<<END);
     0         1
     012345678901

   0
   1      56
   2     3478
   3    12  90
   4    2    1
   5    10  32
   6     9854
   7      76
   8

Image: X = 79, Y = 15, Loop = 1
END

ok nws($d->print(2)) eq nws(<<END);
         1         2
     678901234567890123

   3        1234
   4        09 5
   5        78 67
   6        63298
   7        5410
   8          0123
   9         89  4
  10 123412367   5678
  11 0     45      09
  12 9        654321
  13 8765432107
  14         98

Image: X = 79, Y = 15, Loop = 2
END

ok nws($d->print(3)) eq nws(<<END);
     3         4         5
     012345678901234567890123456789

   1 12345678901        23456789012
   2 8         2        1         3
   3 7         3        0         4
   4 6         4        9         5
   5 5         5        8         6
   6 4         6        7         7
   7 3         7890123456         8
   8 2         0987654321         9
   9 1         1        0         0
  10 0         2        9         1
  11 9         3        8         2
  12 8         4        7         3
  13 7         5        6         4
  14 65432109876        54321098765

Image: X = 79, Y = 15, Loop = 3

END

ok nws($d->print(4)) eq nws(<<END);
      3         4
     9012345678901

   0
   1
   2
   3      432
   4      5 1
   5      6 0
   6      7 9
   7      8 8
   8      9 7
   9      0 6
  10      1 5
  11      234
  12
  13
  14

Image: X = 79, Y = 15, Loop = 4
END

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

Image::Find::Loops::new

numberOfLoops($)

Number of loops in the image. The partitions and loops are numbered from 1.

   Parameter  Description  
1  $i         Image        

loop($$)

Return an array of arrays [x, y] of sequentially touching pixels describing the largest loop in the specified partition where the loops in an image are numbered from 1.

   Parameter   Description  
1  $i          Image        
2  $partition  Partition    

Example:

is_deeply $d->loop(1),

[[3,3], [4,3], [4,2], [5,2], [5,1], [6,1], [6,2], [7,2], [7,3], [8,3], [8,4],

[8,5], [7,5], [7,6], [6,6], [6,7], [5,7], [5,6], [4,6], [4,5], [3,5], [3,4]];

print($$)

Print a loop in the image, sequentially numbering adjacent pixels from 0..9.

   Parameter   Description  
1  $i          Image        
2  $partition  Partition    

Example:

ok nws($d->print(2)) eq nws(<<END);
         1         2
     678901234567890123

   3        1234
   4        09 5
   5        78 67
   6        63298
   7        5410
   8          0123
   9         89  4
  10 123412367   5678
  11 0     45      09
  12 9        654321
  13 8765432107
  14         98

Image: X = 79, Y = 15, Loop = 2
END

Attributes

Attributes of an image

bounds :lvalue

The bounds of each partition: [$x1, $y1, $x2, $y2].

count :lvalue

Number of points in the image.

image :lvalue

Image data points.

partitions :lvalue

Number of partitions in the image.

partitionLoop :lvalue

Loop for each partition.

x :lvalue

Image dimension in x.

y :lvalue

Image dimension in y.

Private Methods

fillPartition($$)

Remove any interior voids in a partition.

   Parameter   Description  
1  $i          Image        
2  $partition  Partition    

clone($)

Clone an image.

   Parameter  Description  
1  $i         Image        

Example:

is_deeply $d, $d->clone;

partitionImage($$)

Partition the images into disjoint sets of connected points.

   Parameter  Description                                                       
1  $i         Image                                                             
2  $small     Minimum size of a partition - smaller partitions will be ignored  

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  
4  $small     Delete partitions of fewer pixels         

removeInteriorOfPartition($$$)

Remove the interior of a partition to leave the exterior loop.

   Parameter   Description   
1  $I          Image         
2  $i          Cloned image  
3  $partition  Partition     

findLongestLoop($$$)

Find the longest loop in a partition.

   Parameter   Description   
1  $I          Image         
2  $i          Cloned image  
3  $partition  Partition     

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.  

Index

1 bounds

2 clone

3 count

4 fillPartition

5 findLongestLoop

6 image

7 loop

8 mapPartition

9 new

10 numberOfLoops

11 partitionImage

12 partitionLoop

13 partitions

14 print

15 removeInteriorOfPartition

16 searchArea

17 x

18 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.