【问题标题】:Matlab - Image Processing - Extracting ContourMatlab - 图像处理 - 提取轮廓
【发布时间】:2017-12-11 08:15:28
【问题描述】:

我是 MATLAB 新手,也是图像处理新手。

我要找一张图片的轮廓,所以

leaf = imread('images\leaf.jpg')
SE = [1 1 1
      1 1 1
      1 1 1]
figure
imshow(leaf)
title("leaf_origin")

erosed_leaf = imerode(leaf,SE);
Contour = double(leaf) - double(erosed_leaf)
Contour=~Contour
figure
imshow(Contour)

这在运行 imshow 时给我一个错误

错误使用 images.internal.imageDisplayValidateParams>validateCData(第 119 行) 如果输入是逻辑的(二进制),它必须是二维的。

images.internal.imageDisplayValidateParams 中的错误(第 27 行) common_args.CData = validateCData(common_args.CData,image_type);

images.internal.imageDisplayParseInputs 中的错误(第 78 行) common_args = images.internal.imageDisplayValidateParams(common_args);

imshow 中的错误(第 241 行) images.internal.imageDisplayParseInputs({'Parent','Border','Reduce'},preparsed_varargin{:});

如果我删除contour 前面的~,它可以工作,但输出不正确。任何人都可以给我有关错误的任何提示吗?

【问题讨论】:

  • 在这一行之前,Contour=~Contour 变量 Contour 是一个 3 维双精度数组,我假设它代表颜色。执行Contour=~Contour 后,变量 Contour 变为 3 维逻辑数组(即填充 1 和 0)并且函数 imshow 不知道如何处理此输入,因此您得到错误。你想用Contour=~Contour 达到什么目的?恢复颜色?
  • @ArtyomEmelyanenko 是的,恢复颜色。谢谢您的帮助。将逻辑数组改为双数组后,就可以了。

标签: matlab image-processing


【解决方案1】:
erosed_leaf = imerode(leaf,SE);
contour = double(leaf) - double(erosed_leaf);
contour = double(~contour);

figure();
imshow(contour);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-17
    • 2021-08-16
    • 2020-11-15
    • 2012-11-15
    • 2020-03-29
    • 1970-01-01
    • 2014-11-02
    • 2019-07-18
    相关资源
    最近更新 更多