img = imread('cameraman.tif');
[row, col, ~] = size(img);
imgSize = [row, col];
squareSize = [50, 50];
maximumPosValue = (imgSize - squareSize + 1);
initialRandomPos = [randi(maximumPosValue(1)), randi(maximumPosValue(2))];
cropRect = [initialRandomPos(2), initialRandomPos(1), squareSize(2)-1, squareSize(1)-1];
imgCropped = imcrop(img, cropRect);
out = imtile({img, imgCropped}, 'BackgroundColor', 'w');
figure
imshow(out)
title('Original image | Random cropped image');
0 Comments
Sign in to comment.