npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

itk-image-pad-resample

v1.1.6

Published

Resample or pad an ITK image to make it match a given size in the i,j,k dimensions

Downloads

9

Readme

itk-image-pad-resample

Resample virtually any type of image 2D, 3D with 1 or multiple components.

NPM JavaScript Style Guide

Install

Install with the flag '-g' and use it in the command line.

npm install itk-image-pad-resample -g

Usage in the command line

img-pad-resample --help
Help: Resample an image to a specific size.
Required:
--img <input path to image> or --dir <directory>
--size <sizeX,sizeY,sizeZ>

Optional:
--out <output path> default: out.nrrd
--out_ext <output extension> (when using --dir) default: .nrrd
--spacing <spacingX,spacingY,spacingZ> Input image spacing is used. Otherwise, is set to fit the output size.
--pad <padX,padY,padZ> pad output at the top
--iso_spacing If this is set, the spacing of the output image will be isometric, i.e., the same for all dimensions which means the max spacing value is selected and set for all dimensions.
--center_image If this is set, the output image is centered in the resampled space.
--linear Linear interpolation, default is nearest neighbor.
img-pad-resample --img /path/to/input.nii --size 250,250,250 --out temp.nrrd 

To process a whole directory with images

img-pad-resample --dir /path/to/directory --size 250,250 --out /path/to/output/dir --out_ext .jpg

Usage in your js logic

Use med-img-reader to read any type of image with one or multiple components in a variety of formats.

const MedImgReader = require('med-img-reader');
const ImgPadResampleLib = require('itk-image-pad-resample');
const medimgreader = new MedImgReader();
medimgreader.SetFilename('/path/to/input{.png,.jpg,.nrrd,.nii.gz,.dcm}');
medimgreader.ReadImage();
const in_img = medimgreader.GetOutput();

const imgpad = new ImgPadResampleLib();
imgpad.SetImage(in_img);
imgpad.SetOutputSize([300, 250]);
imgpad.SetFitSpacingToOutputSizeOn(); //optional
imgpad.SetIsoSpacingOn(); //optional 
imgpad.SetCenterImageOn(); //optional
imgpad.SetInterpolationTypeToLinear(); //default is nearest
imgpad.Update();
var img_out = imgpad.GetOutput();

const writer = new MedImgReader();
writer.SetInput(img_out);
writer.SetFilename('/path/to/ouput/{.png,.jpg,.nrrd,.nii.gz,.dcm}');
writer.WriteImage();

Example

Input RGBA image: alt text

img-pad-resample --img brain.png --size 500,250 --out out_brain.png 

Output RGBA image, the image here might look stretched because typical image viewers will not take spacing information in consideration!: alt text

Use flag '--iso_spacing' to have the same spacing in all dimensions

img-pad-resample --img brain.png --size 500,250 --iso_spacing --out out_brain_iso.png 

Output RGBA image with equal spacing: alt text

Convert image to a tensorflow Tensor tfjs


const tf = require('@tensorflow/tfjs-node');//Or tfjs in browser or tfjs-node-gpu if in linux

tf.tensor(
	Float32Array.from(img_out.data), 
	[1, ...[...img_out.size].reverse(), img_out.imageType.components]
));

License

MIT © juanprietob