itk-image-pad-resample
Resample virtually any type of image 2D, 3D with 1 or multiple components.
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 = ;const ImgPadResampleLib = ;
const medimgreader = ;medimgreader;medimgreader;const in_img = medimgreader; const imgpad = ;imgpad;imgpad;imgpad; //optionalimgpad; //optional imgpad; //optionalimgpad; //default is nearestimgpad;var img_out = imgpad; const writer = ;writer;writer;writer;
Example
Input RGBA image:
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!:
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:
tfjs
Convert image to a tensorflow Tensorconst 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