Cropping is simple, all you have to do is apply the appropriate mask. The trick is to create such a mask.
Assuming A
is your image, try the following:
%# Create an ellipse shaped mask c = fix(size(A) / 2); %# Ellipse center point (y, x) r_sq = [76, 100] .^ 2; %# Ellipse radii squared (y-axis, x-axis) [X, Y] = meshgrid(1:size(A, 2), 1:size(A, 1)); ellipse_mask = (r_sq(2) * (X - c(2)) .^ 2 + ... r_sq(1) * (Y - c(1)) .^ 2 <= prod(r_sq)); %# Apply the mask to the image A_cropped = bsxfun(@times, A, uint8(ellipse_mask));
The cropped image will be saved in A_cropped
. Play with the coordinates of the center and the values ββof the radii until you get the desired result.
EDIT : I have expanded the solution for RGB images (if matrix A
is 3-D).
source share