how to merge two near bounding boxes ?
2 views (last 30 days)
Show older comments
Hello everyone
I'm trying to do the segmentation of symbols in an arabic mathematical equation. Here is the code :
clc
clear all, close all;
%% Image segmentation and extraction%% Get file from folder
[filename,pathname]=uigetfile('*','Load an Image');
%% Read Image
imagen=imread(fullfile(pathname,filename));
%% Show image
figure(1)
imshow(imagen);
title('INPUT IMAGE WITH NOISE')
%% Convert to gray scale
if size(imagen,3)==3 % RGB image
image=rgb2gray(imagen);
end
%% Convert to binary image
threshold = graythresh(image);
image1 =~im2bw(image,threshold);
%% Show image binary image
figure(2)
imshow(~image1);
title('INPUT IMAGE WITHOUT NOISE')
%% Label connected components
[L Nb]=bwlabel(image1);
%% Measure properties of image regions
bboxes=regionprops(L,'BoundingBox');
hold on
%% Plot Bounding Box
for n=1:size(bboxes,1)
rectangle('Position',bboxes(n).BoundingBox,'EdgeColor','r','LineWidth',0.5)
end
hold off
pause (1)
%% Objects extraction
figure(3)
for n=1:Nb
[r,c] = find(L==n);
n1=image1(min(r):max(r),min(c):max(c));
imshow(~n1);
pause(0.5)
end
%% Merge overlapping boxes
boxes = cat(1, bboxes.BoundingBox);
xmin = boxes(:,1);
ymin = boxes(:,2);
xmax = xmin + boxes(:,3) - 1;
ymax = ymin + boxes(:,4) - 1;
overlapRatio = bboxOverlapRatio(boxes, boxes);
n = size(overlapRatio,1);
overlapRatio(1:n+1:n^2) = 0;
g = graph(overlapRatio);
componentIndices = conncomp(g);
xmin = accumarray(componentIndices', xmin, [], @min);
ymin = accumarray(componentIndices', ymin, [], @min);
xmax = accumarray(componentIndices', xmax, [], @max);
ymax = accumarray(componentIndices', ymax, [], @max);
% Compose the merged bounding boxes using the [x y width height] format.
textBBoxes = [xmin ymin xmax-xmin+1 ymax-ymin+1];
ITextRegion = insertShape(image, 'Rectangle', textBBoxes,'LineWidth',2);
figure
imshow(ITextRegion)
this code works and merge boxes if they are overlapping.
My problem is that arabic letters often contain points. For example :

so when segmenting this letter it will give tow different boxes (symbols), just like this :

I want to merge them in order to get just one box (symbol).
thank you in advance for your help.
0 Comments
Answers (0)
See Also
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!