How can I assign real coordinates (UTM) to the centroids of connected components?

I'm looking for help with assigning real coordinates (in UTM 50000/700000 style) to centroids of connected components identified from a binary grid, that will be used to correspond to 'z' values of area at each point.
The original data is read from an ascii and thus has real coordinates assigned to each cell. When applying 'bwconncomp' the resultant data records the pixel IDs rather than coordinates to the cells making up each connected component:
lake_cells = bwconncomp(lake_grid);
lake_areas = regionprops(lake_cells, 'Area', 'Centroid');
Does anyone know how I can assign the original coordinates from my XYZ data corresponding to the pixel ID of the centroid of each connected component?
Thanks,
Caroline

Answers (1)

You said that the data has real coordinates assigned to each cell. But do the cells all represent the same rectangular area? If not then the centroid calculated by regionprops is not meaningful and you will have to calculate a center of mass.
If the cells are equal area, then take the x coordinate of the corner of the grid and add the centroid x times the difference in UTM x coordinates between the corners, and likewise for y. (Make the appropriate off-by-something adjustment according to what centroid it would return for the bottom corner itself.)

Categories

Asked:

on 16 Feb 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!