Edison
Edison

Reputation: 4291

Matrix of the Heights of the the connected component of each pixel in Image

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

Answers (1)

Amitay Nachmani
Amitay Nachmani

Reputation: 3279

  1. Use region props and with the bounding box proprieties and pixelIdList
  2. For each connected component give all the pixels the height value according to the bounding box

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

Related Questions