Image中每个像素的连通分量的高度矩阵

时间:2016-08-22 22:03:45

标签: matlab image-processing matrix

我在matlab中有一个B = 700x800的二进制图像。我想要做的是我需要一个与B大小相同的矩阵A,而不是只存储像素,我希望它包含对应于连接组件的高度像素属于二进制Image。

我该怎么做?

Referencs

关于矩阵A的形成 Extraction and Recognition of Artificial Text in Multimedia Documents

1 个答案:

答案 0 :(得分:1)

  1. 使用区域道具和边界框属性和pixelIdList
  2. 对于每个连接的组件,根据边界框为所有像素提供高度值
  3. 代码:

    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)