Crop

Description

Name

class Tinman.Image.Crop

Derived from

Image

Assumes the image holds a non-rectangular shape that is padded with a uniform color and replaces all padding pixels with void.

Since the source image is read scanline after scanline, cropping is performed locally for each scanline: Beginning at the left and right image borders, all pixels having the same color as the color parameter are replaced with void until a consecutive run of pixels having different colors is found (see skip). The following figures illustrates this: Pixels that have the same color as the color parameter are shown as '.' characters, all others are indicated with X:

+-----------------------------------------------------------------------+
|.......................................................................|
|.......................................................................|
|............................XXX........................................|
|...........................XXXXX.......................................|
|.........................XXXXXXX.......................................|
|.......................XXXXXXXXX.......................................|
|.....................XXXXXXXXXXX.......................................|
|...................XXXXXXXXXXXXXX......................................|
|.................XXXXXXXXXXXXXXXX......................................|
|................XXXXXXXXXXXXXXXXX......................................|
|...............XXXXXXXXXXXXXXXXXXX.....................................|
|................XXXXXXXXXXXXXXXXXXX....................................|
|.................XXXXXXXXXXXXXXXXXXXXX.................................|
|...................XXXXXXXXXXXXXXXXXXXXXXX.....X.......................|
|...............XXXXXXXXXX..XXXXXXXXXXXXXXXXXXXXXXXXXXX.................|
|..........XXXXXXXXXXXX.......XXXXXXXXXXXXXXXXXXXXXXXXXXX...............|
|.............XXXXXXX..........XXXXXXXXXXXXXXXXXXXXXXXXXX...............|
|...............XXX.............XXXXXXXXXXXXXXXXXXXXXXXX................|
|................................XXXXXXXXXXXXXXXXXXXXX..................|
|................................XXXXXXXXXXXXXXXXX......................|
|...................................XXXXXXX.............................|
|.......................................................................|
|.......................................................................|
|.......................................................................|
|.......................................................................|
+-----------------------------------------------------------------------+

The cropped image will look like this (whitespace represents void pixels):

+-----------------------------------------------------------------------+
|                                                                       |
|                                                                       |
|                            XXX                                        |
|                           XXXXX                                       |
|                         XXXXXXX                                       |
|                       XXXXXXXXX                                       |
|                     XXXXXXXXXXX                                       |
|                   XXXXXXXXXXXXXX                                      |
|                 XXXXXXXXXXXXXXXX                                      |
|                XXXXXXXXXXXXXXXXX              cropped because         |
|               XXXXXXXXXXXXXXXXXXX             of skipped pixels       |
|                XXXXXXXXXXXXXXXXXXX            |                       |
|                 XXXXXXXXXXXXXXXXXXXXX         V                       |
|                   XXXXXXXXXXXXXXXXXXXXXXX                             |
|               XXXXXXXXXX..XXXXXXXXXXXXXXXXXXXXXXXXXXX                 |
|          XXXXXXXXXXXX.......XXXXXXXXXXXXXXXXXXXXXXXXXXX               |
|             XXXXXXX..........XXXXXXXXXXXXXXXXXXXXXXXXXX               |
|               XXX.............XXXXXXXXXXXXXXXXXXXXXXXX                |
|                         ^      XXXXXXXXXXXXXXXXXXXXX                  |
|                         |      XXXXXXXXXXXXXXXXX                      |
|                  not reachable    XXXXXXX                             |
|                  from left or                                         |
|                  right border                                         |
|                                                                       |
|                                                                       |
+-----------------------------------------------------------------------+

Cropping will not change the image size or modify the georeference.

Fields / Required

image

Type

Image

Constraint

# != null

The image to crop.

Fields / Optional

color

Type

Tinman.Color

Default

{Color.Name: Black}

The padding pixel color.


width

Type

number

Constraint

# >= 0

Default

1

The maximum length (in pixels) of a run surrounded by void pixels that will be interpreted as void, too.

Fields / External

info

Type

Image.Info

Contains information about the image data source, including image format and embedded georeferencing information.