how to connect the adjacent lower edges of each bounding box
1 回表示 (過去 30 日間)
古いコメントを表示
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
8 件のコメント
回答 (1 件)
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)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!