フィルターのクリア

How obtain coordinates of pixels within bwboundaries for each object?

6 ビュー (過去 30 日間)
asdf
asdf 2019 年 4 月 17 日
コメント済み: KALYAN ACHARJYA 2019 年 4 月 17 日
Suppose I have an image
and then I use the code below
I=imread("image.bmp");
imshow(I); hold on; [B,L,N] = bwboundaries(I);
for k=1:length(B),
boundary = B{k};
plot(boundary(:,2), boundary(:,1),'.r')
end
The boundaries then look like
However, I don't just want the x,y coordinates of each pixel ON the boundaries. I also want the x,y coordinates of each pixel INSIDE the boundaries also. That is, I want to store the row/column numbers for each object in separate matrices. So I want a matrix `A1` that should store the row/column numbers for the white pixels in the big object, and a matrix `A2` that should store the row/column numbers for the white pixels in the circular object
Is there a way to do this in Matlab?

回答 (1 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 4 月 17 日
編集済み: KALYAN ACHARJYA 2019 年 4 月 17 日
Code for find the pixels of two withe segmented objects
(Larger is object1 and circular object2)
%Image raed, ensure that image_bw is the binary image
image_bw=im2bw(rgb2gray(imread('image5.png')));
%Extration largest 1 blob only
object1=bwareafilt(image_bw,1);
% Find the rows and colums of object1
[rows_obj1,rows_obj1]=find(object1);
% Find second object
object2=image_bw & imcomplement(object1);
[rows_obj2,cols_obj2]=find(object2);
% Now use the rows_obj1 & rows_obj1 as you want
% Also rows_obj2 & cols_obj2
matrix_A1=[rows_obj1 rows_obj1];
matrix_A2=[rows_obj2 rows_obj2];
77.png
  2 件のコメント
asdf
asdf 2019 年 4 月 17 日
what if I have more than 2 objects? how should I modify this code?
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 4 月 17 日
As you asked for individual matrices for each segmented part(blobs), any image having more number of segmented blobs, you must separate indivually and apply the same.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeComputer Vision with Simulink についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by