reference
labkit.image.resizeToFit
Resize an image to fit within maximum row/column limits.
Syntax
imageOut = labkit.image.resizeToFit(imageIn)
imageOut = labkit.image.resizeToFit(imageIn, Name, Value)
[imageOut, scale] = labkit.image.resizeToFit(___)Description
Computes one uniform scale that satisfies both the maximum row and column limits, preserving aspect ratio. With the default AllowUpscale value, images that already fit are returned unchanged. Target dimensions are rounded to the nearest integer and limited to at least one pixel.
"nearest" samples endpoint-aligned nearest input pixels. "bilinear" performs endpoint-aligned linear interpolation independently in each channel. Output keeps the input class; integer linear results are rounded and limited to the class range.
Inputs
imageIn- Numeric or logical 2-D image or 3-D multichannel image. Empty input is returned unchanged with scale 1.
Name-Value Arguments
MaxHeight- Positive maximum output row count. The default is Inf.
MaxWidth- Positive maximum output column count. The default is Inf.
AllowUpscale- Logical scalar controlling enlargement when both limits permit it. The default is false.
Method- "bilinear" (default) or "nearest".
Outputs
imageOut- Resized image, or imageIn unchanged when scale is 1.
scale- Uniform requested scale before target dimensions are rounded.
Errors
MATLAB inputParser errors are raised for invalid limits, AllowUpscale, malformed name-value arguments, or unsupported option names.
labkit:image:InvalidResizeMethod- Method is not "bilinear" or "nearest". Unsupported image classes or dimensions may raise the originating MATLAB interpolation or cast error.
Example
imageIn = reshape(uint8(1:200), 10, 20);
[imageOut, scale] = labkit.image.resizeToFit(imageIn, ...
"MaxHeight", 5, "Method", "nearest");Related APIs
labkit.image.previewBudget— Downsample image data to fit a display pixel budget.labkit.image.adjustBrightnessContrast— Apply simple brightness and contrast adjustment.labkit.image.adjustHueSaturation— Apply HSV hue and saturation adjustment.labkit.image.assertSupportedPaths— Throw when any path has an unsupported image extension.labkit.image.displayName— Return a short image-file display name.labkit.image.ensureRgb— Return image data with exactly three color channels.labkit.image.fileDialogFilter— Return a file-chooser-compatible image filter.labkit.image.grayWorldWhiteBalance— Apply generic gray-world white balance.
Source
This page is generated from the MATLAB help text in +labkit/+image/resizeToFit.m.