# [✓] Extract the boundary points of an image using Wolfram Mathematica?

Posted 10 months ago
1282 Views
|
4 Replies
|
5 Total Likes
|

Hi, Currently, I am dealing with problems related to images. My intention is to convert an image to binary image and extract the boundary outline of the image to get the coordinates of the boundary image. Through Wolfram Mathematica, we can use the built-in function "binarize" to convert the image to binary image. Further steps to extract the boundary points through Wolfram Mathematica built-in function is not applicable. Is there any built-in function exist to extract the boundary outline points? For my concern, there is a "corner detection" but I could not find the built-in function for binary image outline extraction? Is there any way to extract the binary outline using Wolfram Mathematica? Here is an example of what I want to extract

## Extracted Boundary image

I want to get the boundary points and image as above. Can anyone help me?

4 Replies
Sort By:
Posted 10 months ago
 With img being the top image you can try things like: Binarize[img, 0.95] DeleteSmallComponents[%] ColorNegate[DeleteSmallComponents[ColorNegate[%]]] MorphologicalPerimeter[%] ComponentMeasurements[%, "Contours"] 
Posted 10 months ago
 Thanks so much for helping me with this.
 Hi Soffiah,regarding the original image you posted one cannot do more than Sander did. But I guess this is not what is wanted in general: In general - and most likely in your case - one starts using a DICOM image from a CT scanner and wants to get the coordinates of the respective pixels in terms of the CTs coordinate system. So I am going to show a simple example on this:My original DICOM image (see attachment) I am using below looks like this:The code: ClearAll["Global*"] (* import data and DICOM header: *) {{dataRaw}, dcmHdr} = Import[FileNameJoin[{NotebookDirectory[], "CT_img.dcm"}], {{"Data", "MetaInformation"}}]; rs = "RescaleSlope" /. dcmHdr; ri = "RescaleIntercept" /. dcmHdr; (* rescaling data (HU i.e."Hounsfield" values) according to DICOM-header: *) dataHU = dataRaw rs + ri; (* get image position and pixel spacing *) {x0Pos, y0Pos, zPos} = "ImagePosition" /. dcmHdr; pixSpacg = "PixelSpacing" /. dcmHdr; dataHUimg0 = Image[dataHU]; (* cut all values below 800 HU (e.g. for bones): *) dataHUimg1 = Closing[Binarize[dataHUimg0, 800], 2]; (* and calculate borders: *) bbImg = Thinning@Binarize@GradientFilter[dataHUimg1, 1]; (* get pixels: *) ptsImg = PixelValuePositions[Binarize@bbImg, 1] - 1; (* calculate true position [mm]: *) ptsMetric = (pixSpacg # + {x0Pos, y0Pos}) & /@ ptsImg; Graphics[{Blue, PointSize[.005], Point[ptsMetric]}, Frame -> True, AspectRatio -> Automatic, GridLines -> Automatic, FrameLabel -> {"mm", "mm"}] `The result is:Maybe you find that interesting/helpful, regards -- Henrik Attachments: