我在matlab中有一个B = 700x800的二进制图像。我想要做的是我需要一个与B大小相同的矩阵A,而不是只存储像素,我希望它包含对应于连接组件的高度像素属于二进制Image。
我该怎么做?
Referencs
关于矩阵A的形成 Extraction and Recognition of Artificial Text in Multimedia Documents
答案 0 :(得分:1)
代码:
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)