Reputation: 4291
I have a B=700x800 binary image in matlab.What I want to do is that I need a matrix A of same size as B but instead of storing just pixels I want it to contain the height corresponding to connected component that pixel belongs to in binary Image.
How would I do that?
Referencs
Page 5 about the formation of matrix A Extraction and Recognition of Artificial Text in Multimedia Documents
Upvotes: 0
Views: 66
Reputation: 3279
The code:
row = 100;
col = 100;
% Create a sample binary image
a = zeros(row,col);
a(20:30,40:60) = 1;
a(1:10,80:90) = 1;
% Finds bounding box of each component
regions = regionprops(im2bw(a),'BoundingBox','PixelIdxList');
% Go over each region and assigne is height
heightImage = zeros(row,col);
for i=1:1:length(regions)
% Change the pixels of the component to have the hight of the its
% bounding box
regionPixels = regions(i).PixelIdxList;
regionHegiht = regions(i).BoundingBox(4);
heightImage(regionPixels) = regionHegiht;
end
imshow(heightImage)
Upvotes: 1