how to connect the adjacent lower edges of each bounding box

1 回表示 (過去 30 日間)
praveen rai
praveen rai 2019 年 8 月 14 日
編集済み: praveen rai 2019 年 8 月 17 日
I have drawn a bounding box of rectangle shape on each character and save the all 4 point of all bounding box
Now I want to connect the lower edges of bounding box with each other
How to do it??
sample code for making bounding box and saving all 4 points of bounding box
I = imread('textlineImage.png');
I=im2bw(I);
I=imcomplement(I);
st=regionprops(I,'BoundingBox','Area');
allBB = zeros(length(st), 4);
for k = 1 : length(st)
thisBB = st(k).BoundingBox;
rectangle('Position', [thisBB(1),thisBB(2),thisBB(3),thisBB(4)],...
'EdgeColor', 'r', 'LineWidth', 1)
allBB(k, :) = thisBB;
points are save in varibale allBB
Image is
234.jpg
  8 件のコメント
Rik
Rik 2019 年 8 月 17 日
You have the coordinates right? Then what exactly is your issue?
praveen rai
praveen rai 2019 年 8 月 17 日
ya I have 4 point values of rectangle box in variable allBB but which two points I have to take and how to plot for every line so that I can get spline that is the issue
I am unable to wirte these thing in loop

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

回答 (1 件)

Image Analyst
Image Analyst 2019 年 8 月 17 日
編集済み: Image Analyst 2019 年 8 月 17 日
Use kmeans on the y values to identify boxes in one of the 5 lines that your image has.
[classIndexes, classCentroid] = kmeans(y, 5);
After that, you know which line each y is in then sort by x, then use spline. Something like (untested)
y = allBB(2:4:end);
[classIndexes, classCentroid] = kmeans(y, 5);
newXSamplePoints = 1 : size(yourImage, 2)
for k = 1 : 5
thisClass = classIndexes(k);
thesex = sort(x(thisClass), 'ascend');
% Fit the x to splines at every column in the image.
newY = spline(x, y, newXSamplePoints);
end
hold on;
plot(newXSamplePoints, newY, 'm-', 'LineWidth', 2)
  1 件のコメント
praveen rai
praveen rai 2019 年 8 月 17 日
編集済み: praveen rai 2019 年 8 月 17 日
its showing the following error
Error using kmeans (line 247)
X must have more rows than the number of clusters.
Error in rawcode (line 25)
[classIndexes, classCentroid] = kmeans(y, 5);
allBB has value 208*4 double and y has 1*208 double

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by