【问题标题】:Segmentation in an image with a single object in MATLAB在 MATLAB 中对具有单个对象的图像进行分割
【发布时间】:2015-01-29 19:04:57
【问题描述】:

图片如下:

我的目标是将这只鸟放在另一个图像中。我用 MATLAB 尝试了一些东西,首先rgb2gray 然后imhist 得到鸟的强度,然后我做了一个面具,但我总是得到一个包含树和云的面具。

【问题讨论】:

  • Photoshop 可能是一个很好的解决方案。如果你想要免费的东西,或者 GIMP。

标签: matlab image-processing image-segmentation


【解决方案1】:

这里有一些您可以用于此任务的代码:

clear;
close all;
im = imread('~/Downloads/siraly_www.kepfeltoltes.hu_.jpg');
im = rgb2gray(im);

%// Manually crop the image
im = double(im(620:1619, 2150:3279));
%// Find edges
hedge = vision.EdgeDetector('Method', 'Sobel');
edges = step(hedge, im);
%// Dilate to close edges around object
edges = imdilate(edges, [0 1 0; 1 1 1; 0 1 0]);
%// Find boundary of object
bound = bwboundaries(edges);
bound = bound{1}; % Largest boundary is around object
%// Display image and object boundary
figure; imshow(im, []);
hold on;
plot(bound(:,2), bound(:,1), '.');
hold off;
%// Select all object pixels by filling the boundary
bwobject = false(size(im));
bwobject(sub2ind(size(im), bound(:,1), bound(:,2))) = true;
bwobject = imfill(bwobject, 'holes');
imobject = zeros(size(im));
imobject(bwobject) = im(bwobject);
figure; imshow(imobject, []);

这里使用的方法是:

  1. 手动裁剪图像。
  2. 使用EdgeDetector object 进行边缘检测。
  3. 仅使用imdilatebwboundariesimfill 检索对象像素的形态学操作。

以下是代码中计算和绘制的对象边界:

这是从图像中裁剪出来的对象:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-09
    • 2013-10-23
    • 2014-12-26
    • 1970-01-01
    • 2018-02-21
    • 2011-07-21
    • 2020-03-11
    • 1970-01-01
    相关资源
    最近更新 更多