MATLAB: Select the region whereby the distance to the image border is bigger than 27 mm

distance to image edgeimage processingImage Processing Toolboximage segmentationMATLAB

I want to segment the LV part in an MRI image. In the last step of the algorithm, I have to Select the region whereby the distance to the image border is bigger than 27 mm.
How can I calculate the distance of each region to the image border?

Best Answer

When you say "from the region" do you mean from any of the red points? Or do you mean from the centroid of the region?
Either way, just use pdist2() to find the distance between the boundary or the centroid and the image edge coordinates.
Can you do it? Here's a start.
distances = pdist2(xyCentroid, xyImageEdge);
distMoreThan27 = distances < 27 * pixelsPerMm; % Binary map
for row = 1 : size(distMoreThan27, 1)
if any(distMoreThan27(row, :))
fprintf('Region %d is more than 27 mm.', row);
end
end
If you can't figure it out, attach your binary image mask, and your spatial calibration factor in units of "pixels per mm" or "mm per pixel".
Related Question