问题描述
我有这张图片:
I have this image:
在这张图片中,我有11个形状(看起来像椭圆形)。我想找到每个形状中每个像素的RGB(包括白色边缘/边界,因为它是形状的一部分)。
In this image I have 11 shapes (look like ellipses). I want to find the RGB of each pixel in each shape (including the white edge/boundary, as it's a part of the shape).
如果它有帮助,我有每个形状的中心坐标。
If it helps, I have the center coordinate of each shape.
非常感谢!
推荐答案
这里是使你的工作变得简单的命令...
here are the commands that makes your work easy...
-
正如Superbest所说用命令填充图像
As "Superbest" said fill the image with command
%% Example%%
img = imread('coins.png');
BW4 = im2bw(img );
BW5 = imfill(BW4,'holes');
imshow(BW4), figure, imshow(BW5);
现在使用命令bwlabeln()来查找簇或形状的数量。
Now use command bwlabeln(), to find out the number of clusters or shapes.
%% Example%%
L = bwlabel(BW5);
figure,imshow(L,[]);
L将为您提供相同数量的形状所有像素的数字属于相同的形状。
L包含BW中连接组件的标签。 BW可以有任何尺寸; L与BW的大小相同。 L的元素是大于或等于0的整数值。标记为0的像素是背景。标记为1的像素构成一个对象,标记为2的像素构成第二个对象,依此类推。
L will give you number of shapes with same number to all the pixels belongs to same shape.L containing labels for the connected components in BW. BW can have any dimension; L is the same size as BW. The elements of L are integer values greater than or equal to 0. The pixels labeled 0 are the background. The pixels labeled 1 make up one object, the pixels labeled 2 make up a second object, and so on.
-
假设您有两个形状或区域,那么可以按如下方式找到原始颜色或灰度值。
Suppose you have two shapes or regions then to find the original color or gray scale values od as follows.
%% 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.
编码很开心......
Have a happy coding...
这篇关于获取属于形状的像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!