Aspect ratio of image components in Matlab
I am trying to split an image into components. This is my image,
This is the code -
image=imread('compo1.jpg');
image=imresize(image,[394 464]);
image = im2bw(image);
image=imcomplement(image);
[imx imy]=size(image);
new1=zeros(imx,imy);
compo = bwlabel(image,8) ;
mx=max(max(compo));
for i=1:mx
[r,c] = find(compo==i);
new1=zeros(imx,imy);
rc = [r c];
[sx sy]=size(rc);
for j=1:sx
x1=rc(j,1);
y1=rc(j,2);
new1(x1,y1)=1;
end
imshow(new1);
s = regionprops(new1, 'BoundingBox' );
A =(s.BoundingBox(4) / s.BoundingBox(3))
end
I use bwlabel
, but here my image has one connected component, so it doesn't work. I want to highlight each line as separate segments. My main goal is to find the aspect ratio of each line segment. How can I do this without using it bwlabel
?
+3
source to share
1 answer
You can use Hough Transform to detect lines, however the output will be in parametric form. Thus, you can use convolution techniques when a kernel designed for a specific orientation is collapsed with an image to get a line in that specific direction. You can refer to this link for a more detailed description.
0
source to share