LabKit MATLAB Workbench

reference

API ReferenceBatch Image Crop

batch_crop.cropGeometry.cropImage

Rotate and crop an image at a fixed pixel size.

Syntax

result = batch_crop.cropGeometry.cropImage(imageData, opts)

Description

Adds optional padding, rotates the resulting canvas, and extracts a crop centered at a point expressed in the original image coordinate system. The crop always has the requested pixel dimensions. Areas outside the transformed canvas use the selected fill value. This function does not resize the crop, display graphics, or write files.

Inputs

imageData
Nonempty numeric or logical image. Accepted sizes are M-by-N and M-by-N-by-C. The output preserves its class and channel count.
opts
Scalar structure containing the crop options below.

Options

cropWidth
Required positive pixel count. Noninteger values are rounded.
cropHeight
Required positive pixel count. Noninteger values are rounded.
angleDeg
Counterclockwise canvas rotation in degrees. Default: 0.
centerXY
Crop center [x y] in original-image pixel coordinates, where x is the column and y is the row. Invalid or empty input selects the geometric image center. The center is limited so the requested crop remains representable on the prepared canvas. Default: [].
paddingPercent
Padding added around each source edge as a percentage of the corresponding source dimension. Negative values are treated as zero by the canvas preparation code. Default: 0.
fillValue
Scalar or channel-compatible value used outside the rotated image. Empty input selects the app's white value for imageData. Default: [].

Outputs

result
Scalar crop result structure. result.image is exactly cropHeight-by-cropWidth-by-C. result.centerX and centerY retain the effective center in original-image coordinates. rotationDeg, paddingPercent, sourceWidth, sourceHeight, cropWidth, cropHeight, nativeCropWidth, nativeCropHeight, outputWidth, and outputHeight describe the operation. scaleMode is "Pixels", ok is true, status is "cropped", and message is "OK".

Errors

labkit_BatchImageCrop_app:InvalidImage
imageData is empty, nonnumeric, nonlogical, or has more than three dimensions.
labkit_BatchImageCrop_app:InvalidCropSize
cropWidth or cropHeight is absent, nonfinite, nonscalar, or smaller than one.

Example

imageData = reshape(uint8(1:100), 10, 10);
opts = struct("cropWidth", 4, "cropHeight", 3, "centerXY", [5 6]);
result = batch_crop.cropGeometry.cropImage(imageData, opts);
assert(result.ok && isequal(size(result.image), [3 4]))

Source

This page is generated from the MATLAB help text in apps/image_measurement/batch_crop/+batch_crop/+cropGeometry/cropImage.m.