PixelExtractor Class

Extracts the pixel values from an image.

Inheritance
nimbusml.internal.core.feature_extraction.image._pixelextractor.PixelExtractor
PixelExtractor
nimbusml.base_transform.BaseTransform
PixelExtractor
sklearn.base.TransformerMixin
PixelExtractor

Constructor

PixelExtractor(use_alpha=False, use_red=True, use_green=True, use_blue=True, order='ARGB', interleave=False, convert=True, offset=None, scale=None, columns=None, **params)

Parameters

columns

a dictionary of key-value pairs, where key is the output column name and value is the input column name.

  • Multiple key-value pairs are allowed.

  • Input column type: Picture.

  • Output column type:

    Vector Type.

  • If the output column names are same as the input column names, then

simply specify columns as a list of strings.

The << operator can be used to set this value (see Column Operator)

For example

  • PixelExtractor(columns={'out1':'input1', 'out2':'input2'})

  • PixelExtractor() << {'out1':'input1', 'out2':'input2'}

For more details see Columns.

use_alpha

Specifies whether to use alpha channel. The default value is False.

use_red

Specifies whether to use red channel. The default value is True.

use_green

Specifies whether to use green channel. The default value is True.

use_blue

Specifies whether to use blue channel. The default value is True.

order

Order of colors.

interleave

Whether to separate each channel or interleave in ARGB order. This might be important, for example, if you are training a convolutional neural network, since this would affect the shape of the kernel, stride etc.

convert

Whether to convert to floating point. The default value is False.

offset

Specifies the offset (pre-scale). This requires convert = True. The default value is None.

scale

Specifies the scale factor. This requires convert = True. The default value is None.

params

Additional arguments sent to compute engine.

Examples


   ###############################################################################
   # Loader
   # Resizer
   # PixelExtractor
   # DnnFeaturizer
   # FastLinearBinaryClassifier
   import numpy as np
   import pandas
   from nimbusml import Pipeline
   from nimbusml.datasets.image import get_RevolutionAnalyticslogo, get_Microsoftlogo
   from nimbusml.feature_extraction.image import Loader, Resizer, PixelExtractor
   from nimbusml.linear_model import FastLinearBinaryClassifier

   data = pandas.DataFrame(data=dict(
       Path=[get_RevolutionAnalyticslogo(), get_Microsoftlogo()],
       Label=[True, False]))

   X = data[['Path']]
   y = data[['Label']]

   # define the training pipeline 
   pipeline = Pipeline([
       Loader(columns={'ImgPath': 'Path'}),
       Resizer(image_width=32, image_height=32,
               columns={'ImgResize': 'ImgPath'}),
       PixelExtractor(columns={'ImgPixels': 'ImgResize'}),
       FastLinearBinaryClassifier(feature='ImgPixels')
   ])

   # train
   pipeline.fit(X, y)

   # predict
   scores = pipeline.predict(X)
   print("Predicted Labels:", scores.PredictedLabel.values)
   # Predicted Labels : [True False]
   print("Accuracy:", np.mean(y.Label.values == scores.PredictedLabel.values))
   # Accuracy : 1

Remarks

PixelExtractor extracts the pixel values from an image. The input variables are images of the same size, typically the output of a Resizer transform. The output are pixel data in vector form that are typically used as features for a learner.

Methods

get_params

Get the parameters for this operator.

get_params

Get the parameters for this operator.

get_params(deep=False)

Parameters

deep
default value: False