> For the complete documentation index, see [llms.txt](https://serving.konduit.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://serving.konduit.ai/examples/java/server/pipeline-steps/image-to-ndarray-step.md).

# Image To NDArray Step

Image To NDArray Step is used as a pre-processing step in Pipeline Step to manipulate or convert the image into an *n-*&#x44; array based on the model requirement input layer or the next pipeline step. We can include `ImageToNDArrayStep()` in pipeline into inference configuration.

```java
InferenceConfiguration inferenceConfiguration = new InferenceConfiguration();

inferenceConfiguration.pipeline(SequencePipeline.builder()
                .add(new ImageToNDArrayStep() //add ImageToNDArrayStep() into pipeline to set image to NDArray for input
                        .config(new ImageToNDArrayConfig() //image configuration
                                .width(28)
                                .height(28)
                                .includeMinibatchDim(true)
                                .channelLayout(NDChannelLayout.GRAYSCALE)
                                .format(NDFormat.CHANNELS_LAST)
                        )
                        .keys("image")
                        .outputNames("input_layer"))
                ).build()
        );
```

From `ImageToNDArrayConfig()` in the above, the input image will have 28 by 28 shape size and convert to a 3-D array. Set mini batch dimension to true, and the channel has a depth of 1 for grayscale, put at last of a list such \[1, 28, 28, 1].

{% hint style="info" %}
The shape array such \[minibatch\_dim, width, height, channels] if format is *CHANNELS\_LAST* .
{% endhint %}

```java
inferenceConfiguration.pipeline(SequencePipeline.builder()
        .add(new ImageToNDArrayStep() //add ImageToNDArrayStep() into pipeline to set image to NDArray for input
                .config(new ImageToNDArrayConfig() //image configuration
                        .width(28)
                        .height(28)
                        .includeMinibatchDim(true)
                        .channelLayout(NDChannelLayout.GRAYSCALE)
                        .format(NDFormat.CHANNELS_FIRST)
                        .normalization(ImageNormalization.builder().type(ImageNormalization.Type.SCALE).build())
                )
                .keys("image")
                .outputNames("input_layer")
        ).build()
);
```

We'll be able to add data normalization and change channel element position to first which will give the input of \[1, 1, 28, 28] to the model. Failure to give an image with characteristics mentioned in configuration will affect the deployment of model in server and return an error. You can see the similar configuration in [Keras Step](/examples/java/server/pipeline-steps/keras-step.md) and [Tensorflow Step](/examples/java/server/pipeline-steps/tensorflow-step.md). &#x20;


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://serving.konduit.ai/examples/java/server/pipeline-steps/image-to-ndarray-step.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
