Show Coordinates and/or Color of the found Boundaries
2 views (last 30 days)
Show older comments
Hello,
i´ve some problems solving my Issues with my program. First of all, the program should find the edges of some blocks. For that i used "bwboundaries". Now my blocks are marked. Now i have to, somehow, get the coordinates and the color (RGB-Code or exact color)of each block, but i´ve no idea how that should work. I attach you a picture of my current status and my code in matlab. Thanks in advance!
Code:
I = imread('test.jpg');
G = rgb2gray(I);
subplot(2, 1, 2);
imshow(I);
title('Originalbild');
set(gcf, 'Position', get(0,'Screensize'));
C = edge(G,'canny');
subplot(2, 2, 2);
imshow(C);
title('CannyEdge');
subplot(2, 2, 1);
imshow(G);
hold on;
title('Kanten markiert');
Raender = bwboundaries(C);
for k =1:length(Raender);
R = Raender{k};
plot(R(:,2),R(:,1),'g','LineWidth',3);
end
hold off
0 Comments
Answers (1)
Vidya Viswanathan
on 23 Dec 2015
The function "bwboundaries" traces the exterior boundaries of objects, as well as boundaries of holes inside these objects. It returns a P x 1 cell array, where P represents the number of objects or holes. Each cell in the cell array contains a Q x 2 matrix where Q represents the number of boundary pixel for the corresponding region. Each row in the matrix contains the row and column coordinates of the boundary pixel. I believe this addresses your first question.
In regard to your query on obtaining the color of the boundary pixel, you can use the original image matrix I and the coordinates of the boundary pixels. If 'r' represents the row coordinate and 'c' represents the column coordinate, the pixel intensity at location (r,c) can be found using I(r,c,:) (if I is not a 2D matrix). In case I is a grayscale or binary image, the pixel intensity is directly computed using I(r,c).
0 Comments
See Also
Categories
Find more on Computer Vision with Simulink in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!