im2uint16 — Convert images to uint16 in MATLAB and RunMat.
im2uint16(I) converts image data to uint16 using MATLAB image-scaling rules. Floating data in [0, 1] maps to [0, 65535].
Syntax
J = im2uint16(I)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
I | Any | Yes | — | Image data to convert. |
Returns
| Name | Type | Description |
|---|---|---|
J | NumericArray | Converted image data in uint16 class. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:im2uint16:TooManyInputs | More than one input argument is supplied. | im2uint16: too many input arguments |
RunMat:im2uint16:InvalidInput | Input cannot be gathered or interpreted for image conversion. | im2uint16: invalid input |
RunMat:im2uint16:UnsupportedInputType | Input type is outside supported numeric/logical image classes. | im2uint16: unsupported input type |
RunMat:im2uint16:Internal | Internal conversion step fails while building output tensor. | im2uint16: internal conversion failure |
How im2uint16 works
- Floating-point inputs are clamped to [0,1], multiplied by 65535, and rounded.
- uint8 inputs are expanded into the uint16 image range.
Example
Convert To uint16
J = im2uint16(I);Expected output:
% J is uint16 image dataUsing im2uint16 with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how im2uint16 changes the result.
Run a small im2uint16 example, explain the result, then change one input and compare the output.
Related Image functions
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how im2uint16 is executed, line by line, in Rust.
- View the source for im2uint16 in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.