How can I perform a comparison function (of surrounding pixels) on a DEM using a starting pixel?
2 views (last 30 days)
Show older comments
I would like to write a function that would take as input, a starting pixel in a Digital Elevation Model raster, that would identify all pixels connected with this pixel that have the same (or lower) elevation. I'm not sure if I should use a simple region-growing algorithm for this. Thanks!
0 Comments
Answers (3)
Wolfgang Schwanghart
on 19 Jul 2012
Hi,
you might be interested in using the function ixneighbors available on the FEX which might make life a little easier for your task.
Say, you are interested in the pixel with the linear index ix you can proceed as follows
[ic,icd] = ixneighbors(dem,ix);
I = dem(icd)<=dem(ic);
ixn = icd(I);
In addition, you might be interested in TopoToolbox that has various functions for terrain analysis in Matlab.
Regards, W.
Image Analyst
on 19 Jul 2012
If you have the Image Processing Toolbox you could do it in 4 lines without writing your own region growing code by using morphological reconstruction. Here's some untested code just off the top of my head. You could just threshold your image
binaryImage = yourImage <= pixelValue;
Then use imreconstruct to grab only that one region connected to your specified pixel.
% Create a marker image.
markerImage = false(size(yourImage)); % Initialize to all false.
markerImage(row, column) = true; % Set the pixel that you're interested in.
% Extract the connected pixels.
connectedBlob = imreconstruct(binaryImage, markerImage, 8);
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!