MATLAB: How to crop 4 different images from a single image

cropfingerprintimageimage fields

I have a form with 4 image fields, stacked together horizontally, I want to crop these 4 images automatically, and want to save these 4 images individually with 4 different file names. How could I perform it using Matlab. Can you help me with some code for it?

Best Answer

[rows, columns, numberOfColorChannels] = size(theImage);
col4 = round(columns/4, columns/2, 3*columns/4);
if numberOfColorChannels == 1
% Gray scale image.
image1 = theImage(:, 1:col4(1));
image2 = theImage(:, col4(1)+1:col4(2));
image3 = theImage(:, col4(2)+1:col4(3));
image4 = theImage(:, col4(3)+1:end);
else
% Color image.
image1 = theImage(:, 1:col4(1), :);
image2 = theImage(:, col4(1)+1:col4(2), :);
image3 = theImage(:, col4(2)+1:col4(3), :);
image4 = theImage(:, col4(3)+1:end, :);
end
Then use imwrite to save each quadrant.