![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
@codait/max-vis
Advanced tools
max-vis
is a JavaScript library and command-line utility to help render the predictions returned by some of the deep learning models of the Model Asset eXchange (MAX).
Given the JSON result (prediction) from one of the MAX image models and the source image, with max-vis
you can render a new version of the image with predictions (i.e., bounding box, pose lines, etc) annotated on it.
browser
<script src="https://cdn.jsdelivr.net/npm/@codait/max-vis"></script>
Node.js
npm install @codait/max-vis
command-line
npm install -g @codait/max-vis
See working examples for browser, Node.js, and command-line environments in the /examples
directory.
browser
// the prediction (JSON object) returned by a MAX image model
const prediction = ...
// the source image used to get the prediction
const image = document.getElementById('myimage')
// returns a Promise that resolves to a copy of the source image annotated with the prediction
maxvis.annotate(prediction, image)
.then(annotatedImageBlob => {
// the argument passed is a Blob of a PNG image
let img = document.createElement('img')
img.src = URL.createObjectURL(annotatedImageBlob)
document.body.appendChild(img)
})
Note: When loaded in a browser, the global variable
maxvis
will be available to access the API.
Node.js
const maxvis = require('@codait/max-vis')
// the prediction (JSON object) returned by a MAX image model
const prediction = ...
// the source image used to get the prediction
const image = 'images/myImage.jpg'
// returns a Promise that resolves to a copy of the source image annotated with the prediction
maxvis.annotate(prediction, image)
.then(annotatedImageBuffer => {
// the argument passed is a Buffer of a PNG image
fs.writeFile('myAnnotatedImage.png', annotatedImageBuffer, (err) => {
if (err) {
console.error(err)
}
})
})
command-line
Pass prediction directly from a file
$ maxvis images/myImage.jpg -p maxImageModelPrediction.json
or pipe prediction from curl
$ curl -X POST "http://max-image-model-endpoint/model/predict" \
-F "image=@images/myImage.jpg" \
| maxvis images/myImage.jpg
Note: When installed as a command-line utility, the global command
maxvis
will be available.
Processes the prediction against the image and renders the prediction (in a Canvas
overlay) on top of the image. Not applicable when running in Node.js.
prediction
- (Required) the prediction output from a MAX image model
image
- (Required) an HTMLImageElement
or the id
of an HTMLImageElement
options
- (Optional) a JSON object of options to customize rendering. See Options for more info.
Processes the prediction against the image and creates a new version of the image that includes the rendered prediction.
prediction
- (Required) the prediction output from a MAX image model
image
- (Required) an HTMLImageElement
or HTMLCanvasElement
or the id
of an HTMLImageElement
or HTMLCanvasElement
.
options
- (Optional) a JSON object of options to customize rendering. See Options for more info.
Returns a Promise that resolves to a Blob
(in browsers) or Buffer
(in Node.js) of a PNG image containing the input image annotated with the prediction.
Processes the prediction against the image, extracts the components from the image.
prediction
- (Required) the prediction output from a MAX image model
image
- (Required) an HTMLImageElement
or HTMLCanvasElement
or the id
of an HTMLImageElement
or HTMLCanvasElement
.
options
- (Optional) a JSON object of options to customize rendering. See Options for more info.
Returns a Promise that resolves to an array of objects representing each item of the prediction. Each object in the array contains:
image
: a Blob
(in browsers) or Buffer
(in Node.js) of a PNG image containing the cropped out area of the input image identified in prediction.label
: a label for the imageReturns the max-vis
version number
Available options to pass to the API. All are optional and by default, max-vis
will try to determine the appropriate values from the prediction object.
Option | Type | Description |
---|---|---|
type | String | The name of type of rendering the prediction conforms to. Acceptable types are boxes (for bounding boxes), lines (for pose lines), or segments (for image segmentation). |
height | Number | The height (in pixels) of the image represented by the prediction |
width | Number | The width (in pixels) of the image represented by the prediction |
colors | 2D array or Object | An array of RGB values to use for rendering (e.g., [[255,0,200], [125,125,125], ...] ). Alternatively, for bounding boxes an object of label names mapped to preferred RGB values (e.g., {person: [255,0,200], horse: [125,125,125], ...} ) can be passed. |
segments | Array | An array of segmentation IDs to process (e.g., [0, 15]). If not provided, all segments will be processed. This is only applicable for predictions of type segments . |
exclude | Boolean | Set to true if segments option indicates segmentation that should be excluded instead of included in processing. Default is false . This is only applicable for predictions of type segments . |
lineWidth | Number | The thickness of the lines in the rendering. Default is 2. This is only applicable for predictions of type boxes or lines . |
Available parameters to pass to the CLI
Parameter | Description |
---|---|
--type | Same as type API option |
--extract | Extract and save each component of the prediction from the image instead of saving a single image will all components rendered |
--prediction | The path to a JSON file containing the prediction returned by a MAX image model |
The /examples
directory contains working examples for the browser, Node.js, and command-line environments.
annotate bounding boxes
extract bounding boxes
annotate segmentation maps
extract segmentation maps
annotate pose lines
FAQs
Image annotation library for MAX image models
The npm package @codait/max-vis receives a total of 3 weekly downloads. As such, @codait/max-vis popularity was classified as not popular.
We found that @codait/max-vis demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.