【问题标题】:Extract elliptical region and crop it with with manually in Matlab提取椭圆区域并在 Matlab 中手动裁剪
【发布时间】:2014-09-07 06:19:54
【问题描述】:

我有很多人脸图像,我想手动从图像中提取一个椭圆区域并裁剪并自动保存(如 imcrop 但不是矩形)。 你能帮我解决这个问题吗?

感谢您的帮助

【问题讨论】:

标签: matlab image-processing crop extraction matlab-cvst


【解决方案1】:

您可以使用imellipse 函数。

【讨论】:

    【解决方案2】:
    %This is what you would do after creating the mask to get the coordinates.
    
    structBoundaries = bwboundaries(binaryImage);
    xy=structBoundaries{1}; % Get n by 2 array of x,y coordinates.
    x = xy(:, 2); % Columns.
    y = xy(:, 1); % Rows.
    

    但是更好的方法是使用下面的代码。本质上,它要求用户选择图像,然后用户手动裁剪图像,然后将其保存到原始图像所在的位置。

    [FileName,PathName] = uigetfile({'*.jpg;*.tif;*.png;*.gif','All Image Files'},'Please Select an Image');
    image = imread([PathName FileName]); 
    imshow(image) %needed to use imellipse
    user_defined_ellipse = imellipse(gca, []); % creates user defined ellipse object.
    wait(user_defined_ellipse);% You need to click twice to continue. 
    MASK = double(user_defined_ellipse.createMask());
    new_image_name = [PathName 'Cropped_Image_' FileName];
    new_image_name = new_image_name(1:strfind(new_image_name,'.')-1); %removing the .jpg, .tiff, etc 
    new_image_name = [new_image_name '.png']; % making the image .png so it can be transparent
    imwrite(image, new_image_name,'png','Alpha',MASK);
    msg = msgbox(['The image was written to ' new_image_name],'New Image Path');
    waitfor(msg);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-20
      • 2013-04-07
      • 2014-05-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-16
      • 1970-01-01
      相关资源
      最近更新 更多