pengfeidip
4/13/2019 - 5:50 AM

[crop the image]crop the image and transform RGB to Gray #matlab

[crop the image]crop the image and transform RGB to Gray #matlab

%cropping image using an rectangle by a user
function [rect_region, rect_coord]= crop_image(refImg)
    % crop the image by user
    %return:
    %rect_region : region selected by user
    %rect_coord : coordinate of region with [xmin, ymin, width, height]

    %specify an rectangle region by a user
    rect_coord  = getrect ;
    
    %cropping the image with the specified region.
    rect_region = imcrop(refImg, rect_coord );
    if ndims(rect_region) == 3
        rect_region = rgb2gray(rect_region);
    end
    
end