2012-04-07 29 views
1

像素我有这样的图像: enter image description here获取属于形状

在该图像I具有11个的形状(像椭圆)。我想要找到每个形状中每个像素的RGB(包括白色边缘/边界,因为它是形状的一部分)。

如果有帮助,我有每个形状的中心坐标。

非常感谢!

回答

2

这里是让你的工作更轻松的命令......

  1. 为 “Superbest说:” 带命令

    %% Example%% 
    img = imread('coins.png'); 
    BW4 = im2bw(img); 
    BW5 = imfill(BW4,'holes'); 
    imshow(BW4), figure, imshow(BW5); 
    
  2. 现在用命令bwlabeln填充图像() ,找出聚类或形状的数量。

    %% Example%% 
    L = bwlabel(BW5); 
    figure,imshow(L,[]); 
    

我会给你相同数量的形状的数量给所有的像素属于相同的形状。 L包含BW中已连接组件的标签。体重可以有任何维度; L与BW的大小相同。 L的元素是大于或等于0的整数值。标记为0的像素是背景。标记为1的像素构成一个对象,标记为2的像素构成第二个对象,依此类推。

  1. 假设您有两个形状或区域,然后找到原始颜色或灰度值od,如下所示。

    %% Example%% 
    cods = find(L==1); 
    Shape1(1:size(img,1),1:size(img,2))=0; 
    Shape1(cods) = img(cods); 
    %% Now shape1 is same size as img, but will have gray scale values at region1 locations only,you will get RGB valuse in shape1 image.. repeate it for as many shapes as you have in your image. 
    

拥有一个美满的编码...

+0

+1使用bwlabel的'()'。 – 2012-04-09 12:17:51

2

这是发生在我身上,因为我正在审查问题的解决哈克:

  1. 用白色填充每个形状为您的其他问题,Matlab fill shapes by white被描述。
  2. 由于您仍然有形状的中心,现在再次使用图像中不存在的颜色(如粉色)填充每个形状。
  3. 现在,每个感兴趣的像素(属于形状:边缘和内部的像素)都被着色为粉红色,并且没有其他像素具有此颜色。
  4. 现在,你可以简单地得到粉色像素的列表:

    foundPixels = find(img == pink); % pink holds the value for the pink color I used.

  5. 现在你可以使用原始图像(pixels = original(foundPixels);)对这些指数来获得你想要的像素。