Name
Image::Find::Loops - Find loops in an image.
Synopsis
Use new to create and analyze a new image, then print to visualize the loops detected, or loop to get the coordinates of points in each loop in sequential order.
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) eq nws(<<END);
     0         1         2         3         4         5         6         7
     0123456789012345678901234567890123456789012345678901234567890123456789012345678
   0
   1      56                       12345678901        23456789012
   2     3478                      8         2        1         3
   3    12  90    1234             7   432   3        0         4
   4    2    1    09 5             6   5 1   4        9         5
   5    10  32    78 67            5   6 0   5        8         6
   6     9854     63298            4   7 9   6        7         7
   7      76      5410             3   8 8   7890123456         8
   8                0123           2   9 7   0987654321         9
   9               89  4           1   0 6   1        0         0
  10       123412367   5678        0   1 5   2        9         1
  11       0     45      09        9   234   3        8         2
  12       9        654321         8         4        7         3
  13       8765432107              7         5        6         4
  14               98              65432109876        54321098765
Image: X = 79, Y = 15, Loops = 4
END
ok nws($d->printLoop(2)) eq nws(<<END);
         1         2
     678901234567890123
   3        1111
   4        22 1
   5        22 22
   6        22412
   7        1334
   8          3411
   9         11  1
  10 111111111   1111
  11 1     22      22
  12 1        111111
  13 1111111122
  14         21
Image: X = 79, Y = 15, Loop = 2
END
ok nws($d->printLoop(3)) eq nws(<<END);
     3         4         5
     012345678901234567890123456789
   1 11111111111        11111111111
   2 1         1        1         1
   3 1         1        1         1
   4 1         1        1         1
   5 1         1        1         1
   6 1         1        1         1
   7 1         1222222221         1
   8 1         1222222221         1
   9 1         1        1         1
  10 1         1        1         1
  11 1         1        1         1
  12 1         1        1         1
  13 1         1        1         1
  14 11111111111        11111111111
Image: X = 79, Y = 15, Loop = 3
END
ok nws($d->printLoop(4)) eq nws(<<END);
      3         4
     9012345678901
   0
   1
   2
   3      111
   4      1 1
   5      1 1
   6      1 1
   7      1 1
   8      1 1
   9      1 1
  10      1 1
  11      111
  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
Example:
is_deeply [$d->count, $d->x, $d->y, $d->numberOfLoops],
[239,       79,    15,    4];
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 [grep{$_->[2] > 2} @{$d->loop(2)}],
[[15, 8, 3],
[15, 7, 3],
[15, 6, 4],
[14, 7, 3],
[16, 7, 4],
printLoop($$)
Print a loop in the image numbering pixels with the estimated thickness of the loop.
   Parameter   Description
1  $i          Image
2  $partition  Partition
Example:
ok nws($d->printLoop(2)) eq nws(<<END);
         1         2
     678901234567890123
   3        1111
   4        22 1
   5        22 22
   6        22412
   7        1334
   8          3411
   9         11  1
  10 111111111   1111
  11 1     22      22
  12 1        111111
  13 1111111122
  14         21
Image: X = 79, Y = 15, Loop = 2
END
ok nws($d->printLoop(3)) eq nws(<<END);
     3         4         5
     012345678901234567890123456789
   1 11111111111        11111111111
   2 1         1        1         1
   3 1         1        1         1
   4 1         1        1         1
   5 1         1        1         1
   6 1         1        1         1
   7 1         1222222221         1
   8 1         1222222221         1
   9 1         1        1         1
  10 1         1        1         1
  11 1         1        1         1
  12 1         1        1         1
  13 1         1        1         1
  14 11111111111        11111111111
Image: X = 79, Y = 15, Loop = 3
END
ok nws($d->printLoop(4)) eq nws(<<END);
      3         4
     9012345678901
   0
   1
   2
   3      111
   4      1 1
   5      1 1
   6      1 1
   7      1 1
   8      1 1
   9      1 1
  10      1 1
  11      111
  12
  13
  14
Image: X = 79, Y = 15, Loop = 4
END
print($)
Print the loops in an image sequentially numbering adjacent pixels in each loop from 0..9.
   Parameter  Description
1  $i         Image
Example:
ok nws($d->print) eq nws(<<END);
     0         1         2         3         4         5         6         7
     0123456789012345678901234567890123456789012345678901234567890123456789012345678
   0
   1      56                       12345678901        23456789012
   2     3478                      8         2        1         3
   3    12  90    1234             7   432   3        0         4
   4    2    1    09 5             6   5 1   4        9         5
   5    10  32    78 67            5   6 0   5        8         6
   6     9854     63298            4   7 9   6        7         7
   7      76      5410             3   8 8   7890123456         8
   8                0123           2   9 7   0987654321         9
   9               89  4           1   0 6   1        0         0
  10       123412367   5678        0   1 5   2        9         1
  11       0     45      09        9   234   3        8         2
  12       9        654321         8         4        7         3
  13       8765432107              7         5        6         4
  14               98              65432109876        54321098765
Image: X = 79, Y = 15, Loops = 4
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;
clonePartition($$)
Clone a partition of an image.
   Parameter   Description
1  $i          Image
2  $partition  Partition
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  $partition  Partition
findLongestLoop($$)
Find the longest loop in a partition.
   Parameter   Description
1  $I          Image
2  $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.
widthOfLoop($$)
Find the (estimated) width of the loop at each point.
   Parameter   Description
1  $I          Image
2  $partition  Partition
Index
1 bounds
2 clone
4 count
7 image
8 loop
10 new
14 partitions
15 print
16 printLoop
18 searchArea
19 widthOfLoop
20 x
21 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
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.