# Non-zero of Image

This block returns the total number of non-zero pixels found in an image. It is useful for quick measurements such as foreground pixel count, occupancy checks, or verifying mask coverage.

## 📥 Inputs <a href="#inputs" id="inputs"></a>

`Image Any` Provide the image you want to analyze. The block accepts color or grayscale images.

## 📤 Outputs <a href="#outputs" id="outputs"></a>

`Count` Total number of non-zero pixels detected in the provided image.

## 🕹️ Controls <a href="#controls" id="controls"></a>

This block has no user-facing controls. It runs automatically when an image is provided.

## ✨ Features <a href="#features" id="features"></a>

* Fast single-value result useful for simple analytics and decision making.
* Accepts both color and grayscale images (color images are internally interpreted for pixel activity).
* Works well as a lightweight metric for masks, binary results, or foreground detection.

## ⚙️ Running mechanism <a href="#how-it-works" id="how-it-works"></a>

When the block is evaluated it examines the provided image and counts pixels that are non-zero (i.e., contain useful/foreground information). The result is returned as a single numeric value through the `Count` output.

## 📝 Usage <a href="#usage" id="usage"></a>

1. Connect an image-producing block to the `Image Any` input.
2. Read the numeric result from the `Count` output to drive logic, logging, or alarms.
3. Combine with other blocks for pre-processing, visualization, or decision-making.

## 💡 Tips and Tricks <a href="#tips-and-tricks" id="tips-and-tricks"></a>

* Prepare a clear binary mask before counting by using `Image Threshold` or `Image Adaptive Threshold` to reduce false positives from noise.
* Use `Image ROI` or `Image ROI Select` to limit the counting area to a region of interest (for localized measurements).
* Reduce noise with `Blur`, `Bilateral Filter` or `Denoising` before counting to avoid inflated results.
* Visualize what is being counted by sending the same image to `Show Image` or overlay results with `Draw Result On Image` / `Write Text On Image`.
* Log numeric results over time using `CSV Export` or `Data to JSON` for trend analysis or record keeping.
* Combine with `Logic Input` or comparison blocks to trigger actions when the count crosses a threshold.

## 🛠️ Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>

* Unexpectedly high counts: check for image noise or stray pixels. Apply `Image Threshold` and smoothing blocks to clean the input.
* Zero or very low counts: confirm the upstream image is valid using `Show Image` and ensure the area of interest contains the expected foreground.
* Counts vary unexpectedly between frames: restrict the area with `Image ROI` or stabilize the input using filters to reduce frame-to-frame variation.


---

# Agent Instructions: 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:

```
GET https://docs.augelab.com/function-blocks/image-transformations/analysis/non-zero-of-image.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
