Reputation: 85
I have an image with arabic text , I wanna to crop and fit the photo to the text . for example something like this
how can I do this with matlab? I try to solve with regionprops function and BoundingBox property but it separate the none connected parts and considering them as separate objects but I want one object
Upvotes: 1
Views: 284
Reputation: 13091
If you already got the bounding boxes for each individual object, you can deduce the bounding box that gets them all. However, just getting the indices to the coners will be much simpler and efficient. Supposing that mask
is a logical matrix with your text:
xs = any (mask);
xi = find (xs, 1, "first");
xf = finf (xs, 1, "last");
Then do the same for the y axis:
ys = any (mask, 2);
yi = find (ys, 1, "first");
yf = finf (ys, 1, "last");
The bounding box for your text will be:
text = mask(yi:yf, xi:xf);
Upvotes: 2
Reputation: 114796
When you provide regionprops
with a labeling of type logical
it runs belabel
behind the scene, thus seperating it into its connected components. If you convert your BW
mask to uint8
or any other type regionprops
will treat it a single component providing you with the desired bounding box.
Upvotes: 1