Matlab 获取属于某个形状的像素
我有这样的图像: 在这张图片中,我有11个形状(看起来像椭圆)。我想找到每个形状中每个像素的RGB(包括白色边缘/边界,因为它是形状的一部分) 如果有帮助,我有每个形状的中心坐标Matlab 获取属于某个形状的像素,matlab,image-processing,Matlab,Image Processing,我有这样的图像: 在这张图片中,我有11个形状(看起来像椭圆)。我想找到每个形状中每个像素的RGB(包括白色边缘/边界,因为它是形状的一部分) 如果有帮助,我有每个形状的中心坐标 非常感谢 这是我在回顾问题时想到的一个骇人的解决方案: 用白色填充每个形状,如其他问题中所述 由于您仍然拥有形状的中心,现在请使用图像中不存在的颜色(如粉色)再次填充每个形状 现在,每个感兴趣的像素(属于形状:边缘和内部)都是粉红色的,没有其他像素具有这种颜色 现在,您只需获得粉红色像素列表: foundPixels
非常感谢 这是我在回顾问题时想到的一个骇人的解决方案:
foundPixels=find(img==pink);%粉红色保留我使用的粉红色的值。
pixels=original(foundPixels);
)来获得所需的像素这是我在回顾问题时想到的一个骇人的解决方案:
foundPixels=find(img==pink);%粉红色保留我使用的粉红色的值。
pixels=original(foundPixels);
)来获得所需的像素以下是使您的工作更轻松的命令
%% Example%%
img = imread('coins.png');
BW4 = im2bw(img );
BW5 = imfill(BW4,'holes');
imshow(BW4), figure, imshow(BW5);
%% Example%%
L = bwlabel(BW5);
figure,imshow(L,[]);
%% 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.
有一个愉快的编码…以下是使您的工作轻松的命令
%% Example%%
img = imread('coins.png');
BW4 = im2bw(img );
BW5 = imfill(BW4,'holes');
imshow(BW4), figure, imshow(BW5);
%% Example%%
L = bwlabel(BW5);
figure,imshow(L,[]);
%% 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.